如何从hybris中删除Carentries?

如何从hybris中删除Carentries?,hybris,Hybris,我需要创建一个CronJob来删除特定类型的购物车条目。我已经找到了所有需要PK的条目,但是我仍然不能删除它们 我在网上发现,我不能使用FlexibleSearchQuery来实现这一点。此外,我在CarentryService中也没有找到任何方法。删除逻辑在哪里?您必须使用modelService从数据库中删除任何模型。在您的情况下,只需将CarentryModel的列表传递给getModelService()。移除所有(列表) 查看DefaultCartServiceupdateQuanti

我需要创建一个CronJob来删除特定类型的购物车条目。我已经找到了所有需要PK的条目,但是我仍然不能删除它们


我在网上发现,我不能使用FlexibleSearchQuery来实现这一点。此外,我在CarentryService中也没有找到任何方法。删除逻辑在哪里?

您必须使用
modelService
从数据库中删除任何模型。在您的情况下,只需将CarentryModel的列表传递给
getModelService()。移除所有(列表)

查看DefaultCartServiceupdateQuantities方法,对于用户试图从购物车中删除的购物车条目,基本上该方法是以0数量调用的

    final Collection<CartEntryModel> toRemove = new LinkedList<CartEntryModel>();
    final Collection<CartEntryModel> toSave = new LinkedList<CartEntryModel>();
    for (final Map.Entry<CartEntryModel, Long> e : getEntryQuantityMap(cart, quantities).entrySet())
    {
        final CartEntryModel cartEntry = e.getKey();
        final Long quantity = e.getValue();
        if (quantity == null || quantity.longValue() < 1)
        {
            toRemove.add(cartEntry);
        }
        else
        {
            cartEntry.setQuantity(quantity);
            toSave.add(cartEntry);
        }
    }
    getModelService().removeAll(toRemove);
final Collection toRemove=new LinkedList();
最终集合toSave=newlinkedlist();
对于(最终映射。条目e:getEntryQuantityMap(购物车,数量)。entrySet())
{
最终CarentryModel Carentry=e.getKey();
最终长数量=e.getValue();
if(quantity==null | | quantity.longValue()<1)
{
删除。添加(Carentry);
}
其他的
{
Carentry.设置数量(数量);
保存。添加(cartEntry);
}
}
getModelService().removeAll(toRemove);
您可以使用groovy脚本实现相同的表单。提及

Groovy脚本示例:

import de.hybris.platform.servicelayer.search.FlexibleSearchQuery;
import de.hybris.platform.servicelayer.model.ModelService;
import de.hybris.platform.core.model.user.CartEntryModel;
import de.hybris.platform.servicelayer.search.SearchResult;
import org.apache.commons.collections.CollectionUtils;



def removeCartEntries()

 {
  final SearchResult<CartEntryModel> searchResults = flexibleSearchService.search("query to get the list of cartentries")
  if (searchResults != null && CollectionUtils.isNotEmpty(searchResults.getResult())) {
      modelService.removeAll(searchResults.getResult());
   }
 }
removeCartEntries();

println "done";
import de.hybris.platform.servicelayer.search.FlexibleSearchQuery;
导入de.hybris.platform.servicelayer.model.ModelService;
导入de.hybris.platform.core.model.user.carentrymodel;
导入de.hybris.platform.servicelayer.search.SearchResult;
导入org.apache.commons.collections.CollectionUtils;
def RemoveCarentries()
{
final SearchResult searchResults=flexibleSearchService.search(“查询以获取Carentries列表”)
if(searchResults!=null&&CollectionUtils.isNotEmpty(searchResults.getResult()){
removeAll(searchResults.getResult());
}
}
移除动脉入口();
println“完成”;

您必须使用
modelService
从数据库中删除任何模型。在您的情况下,只需将CarentryModel的列表传递给
getModelService()。移除所有(列表)

查看DefaultCartServiceupdateQuantities方法,对于用户试图从购物车中删除的购物车条目,基本上该方法是以0数量调用的

    final Collection<CartEntryModel> toRemove = new LinkedList<CartEntryModel>();
    final Collection<CartEntryModel> toSave = new LinkedList<CartEntryModel>();
    for (final Map.Entry<CartEntryModel, Long> e : getEntryQuantityMap(cart, quantities).entrySet())
    {
        final CartEntryModel cartEntry = e.getKey();
        final Long quantity = e.getValue();
        if (quantity == null || quantity.longValue() < 1)
        {
            toRemove.add(cartEntry);
        }
        else
        {
            cartEntry.setQuantity(quantity);
            toSave.add(cartEntry);
        }
    }
    getModelService().removeAll(toRemove);
final Collection toRemove=new LinkedList();
最终集合toSave=newlinkedlist();
对于(最终映射。条目e:getEntryQuantityMap(购物车,数量)。entrySet())
{
最终CarentryModel Carentry=e.getKey();
最终长数量=e.getValue();
if(quantity==null | | quantity.longValue()<1)
{
删除。添加(Carentry);
}
其他的
{
Carentry.设置数量(数量);
保存。添加(cartEntry);
}
}
getModelService().removeAll(toRemove);
您可以使用groovy脚本实现相同的表单。提及

Groovy脚本示例:

import de.hybris.platform.servicelayer.search.FlexibleSearchQuery;
import de.hybris.platform.servicelayer.model.ModelService;
import de.hybris.platform.core.model.user.CartEntryModel;
import de.hybris.platform.servicelayer.search.SearchResult;
import org.apache.commons.collections.CollectionUtils;



def removeCartEntries()

 {
  final SearchResult<CartEntryModel> searchResults = flexibleSearchService.search("query to get the list of cartentries")
  if (searchResults != null && CollectionUtils.isNotEmpty(searchResults.getResult())) {
      modelService.removeAll(searchResults.getResult());
   }
 }
removeCartEntries();

println "done";
import de.hybris.platform.servicelayer.search.FlexibleSearchQuery;
导入de.hybris.platform.servicelayer.model.ModelService;
导入de.hybris.platform.core.model.user.carentrymodel;
导入de.hybris.platform.servicelayer.search.SearchResult;
导入org.apache.commons.collections.CollectionUtils;
def RemoveCarentries()
{
final SearchResult searchResults=flexibleSearchService.search(“查询以获取Carentries列表”)
if(searchResults!=null&&CollectionUtils.isNotEmpty(searchResults.getResult()){
removeAll(searchResults.getResult());
}
}
移除动脉入口();
println“完成”;

这没用?@TrishulSinghChoudhary其实没用。因为我不需要净化和删除购物车。我只需要从所有Cart中删除特定类型的CartEntries。这没用吗?@TrishulSinghChoudhary不太好。因为我不需要净化和删除购物车。我只需要从所有Cart中删除特定类型的CartEntries。