use of org.broadleafcommerce.core.catalog.domain.Product in project BroadleafCommerce by BroadleafCommerce.
the class SolrSearchServiceImpl method getProducts.
/**
* Given a list of product IDs from solr, this method will look up the IDs via the productDao and build out
* actual Product instances. It will return a Products that is sorted by the order of the IDs in the passed
* in list.
*
* @param response
* @return the actual Product instances as a result of the search
*/
protected List<Product> getProducts(List<SolrDocument> responseDocuments) {
final List<Long> productIds = new ArrayList<>();
for (SolrDocument doc : responseDocuments) {
productIds.add((Long) doc.getFieldValue(shs.getIndexableIdFieldName()));
}
List<Product> products = productDao.readProductsByIds(productIds);
extensionManager.getProxy().batchFetchCatalogData(products);
// We have to sort the products list by the order of the productIds list to maintain sortability in the UI
if (products != null) {
Collections.sort(products, new Comparator<Product>() {
@Override
public int compare(Product o1, Product o2) {
Long o1id = shs.getIndexableId(o1);
Long o2id = shs.getIndexableId(o2);
return new Integer(productIds.indexOf(o1id)).compareTo(productIds.indexOf(o2id));
}
});
}
extensionManager.getProxy().modifySearchResults(responseDocuments, products);
return products;
}
use of org.broadleafcommerce.core.catalog.domain.Product in project BroadleafCommerce by BroadleafCommerce.
the class I18nSolrIndexServiceExtensionHandler method startBatchEvent.
@Override
public ExtensionResultStatusType startBatchEvent(List<? extends Indexable> indexables) {
List<String> skuIds = new ArrayList<String>(indexables.size());
List<String> productIds = new ArrayList<String>();
List<String> skuAttributeIds = new ArrayList<String>();
List<String> productAttributeIds = new ArrayList<String>();
for (Indexable indexable : indexables) {
Sku sku = null;
if (Product.class.isAssignableFrom(indexable.getClass())) {
Product product = (Product) indexable;
productIds.add(product.getId().toString());
for (Map.Entry<String, ProductAttribute> attributeEntry : product.getProductAttributes().entrySet()) {
ProductAttribute attribute = attributeEntry.getValue();
productAttributeIds.add(attribute.getId().toString());
}
sku = product.getDefaultSku();
}
if (sku != null) {
skuIds.add(sku.getId().toString());
for (Map.Entry<String, SkuAttribute> attributeEntry : sku.getSkuAttributes().entrySet()) {
SkuAttribute attribute = attributeEntry.getValue();
skuAttributeIds.add(attribute.getId().toString());
}
}
}
addEntitiesToTranslationCache(skuIds, TranslatedEntity.SKU);
addEntitiesToTranslationCache(productIds, TranslatedEntity.PRODUCT);
addEntitiesToTranslationCache(skuAttributeIds, TranslatedEntity.SKU_ATTRIBUTE);
addEntitiesToTranslationCache(productAttributeIds, TranslatedEntity.PRODUCT_ATTRIBUTE);
return ExtensionResultStatusType.HANDLED_CONTINUE;
}
Aggregations