1

I'm trying to remove all the Stock from query products in a cronjob:

List<ProductModel> products = flexibleSearchService.search(GET_SPECIAL_PRODUCTS_QUERY);

for (ProductModel product : products.getResult()) {
     modelService.removeAll(product.getStockLevels());
}

If I debug here I can see that all the products have stock, however, after performing the removeAll method from model Service, the Stock is not removed.

How can I fix this?

Nexussim Lements
  • 535
  • 1
  • 15
  • 47
  • maybe you just need to refresh product model after removing stock level models – Andrii Andriichuk Aug 10 '21 at 11:45
  • if this is performed from groovy console "commit" mode has to be selected – Andrii Andriichuk Aug 10 '21 at 11:46
  • as per above snippet, you are having search result in products variable but you are referring dufryProducts.getResult() – Raushan Kumar Aug 10 '21 at 13:46
  • Have you tried to do `modelService.save(product)` after removing the stock? – David Espino Sep 24 '21 at 00:17
  • Products will be available in different catalog versions. Try giving the proper catalog version in the query for deleting. Also, as mentioned by @RaushanKumar, flexible search returns SearchResult and getResult() method returns List. In the above code, the return type of flexible query is wrong. – Himanshu Jain Sep 16 '22 at 14:32

0 Answers0