Search in sources :

Example 76 with Product

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;
}
Also used : SolrDocument(org.apache.solr.common.SolrDocument) ArrayList(java.util.ArrayList) Product(org.broadleafcommerce.core.catalog.domain.Product)

Example 77 with Product

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;
}
Also used : SkuAttribute(org.broadleafcommerce.core.catalog.domain.SkuAttribute) ArrayList(java.util.ArrayList) Product(org.broadleafcommerce.core.catalog.domain.Product) Indexable(org.broadleafcommerce.core.catalog.domain.Indexable) ProductAttribute(org.broadleafcommerce.core.catalog.domain.ProductAttribute) Sku(org.broadleafcommerce.core.catalog.domain.Sku) Map(java.util.Map)

Aggregations

Product (org.broadleafcommerce.core.catalog.domain.Product)77 Sku (org.broadleafcommerce.core.catalog.domain.Sku)34 ArrayList (java.util.ArrayList)23 Category (org.broadleafcommerce.core.catalog.domain.Category)18 ProductImpl (org.broadleafcommerce.core.catalog.domain.ProductImpl)17 SkuImpl (org.broadleafcommerce.core.catalog.domain.SkuImpl)12 Order (org.broadleafcommerce.core.order.domain.Order)12 Transactional (org.springframework.transaction.annotation.Transactional)11 Test (org.testng.annotations.Test)11 DiscreteOrderItem (org.broadleafcommerce.core.order.domain.DiscreteOrderItem)10 ExtensionResultStatusType (org.broadleafcommerce.common.extension.ExtensionResultStatusType)9 Money (org.broadleafcommerce.common.money.Money)9 ProductBundle (org.broadleafcommerce.core.catalog.domain.ProductBundle)9 CategoryProductXref (org.broadleafcommerce.core.catalog.domain.CategoryProductXref)8 ExtensionResultHolder (org.broadleafcommerce.common.extension.ExtensionResultHolder)7 CategoryImpl (org.broadleafcommerce.core.catalog.domain.CategoryImpl)7 CategoryProductXrefImpl (org.broadleafcommerce.core.catalog.domain.CategoryProductXrefImpl)7 CriteriaBuilder (javax.persistence.criteria.CriteriaBuilder)6 RelatedProduct (org.broadleafcommerce.core.catalog.domain.RelatedProduct)6 OrderItemRequestDTO (org.broadleafcommerce.core.order.service.call.OrderItemRequestDTO)6