Groovy script to get all the base products along with it's product references with PIPe delimiter.
import de.hybris.platform.servicelayer.search.FlexibleSearchService;
import de.hybris.platform.servicelayer.search.FlexibleSearchQuery;
import de.hybris.platform.core.model.product.ProductModel;
import de.hybris.platform.catalog.model.ProductReferenceModel;
import java.util.*;
FlexibleSearchService flexibleSearchService = spring.getBean("flexibleSearchService");
List < ProductModel > baseProducts = new ArrayList < ProductModel > ();
FlexibleSearchQuery flexibleSearchQuery = new FlexibleSearchQuery("SELECT {P:pk} FROM {Product! as P}, {CatalogVersion as CV}, {Catalog as C} WHERE {P:catalogversion}={CV:PK} AND {CV:catalog}={C:PK} AND ({P.varianttype} is not null ) and {C:id}='globalProductCatalog' AND {CV:version}='Staged' order by {P.code} desc");
baseProducts.addAll(flexibleSearchService.search(flexibleSearchQuery).getResult());
int count = 0;
for (ProductModel obj: baseProducts)
{
if (!obj.getProductReferences().isEmpty()) {
List < ProductReferenceModel > productReferences = obj.getProductReferences();
for (ProductReferenceModel pr: productReferences) {
if ((pr).getTarget() != null) {
ProductModel pm = pr.getTarget();
if (pm != null) {
count++;
System.out.println("" + obj.getCode() + "\t|\t" + obj.getName() + "\t|\t" + pm.getCode() + "\t|\t" + pm.getName() + "");
}
}
}
}
}
println count;
return "success! totally found product references : " + count;
Comments
Post a Comment