use of org.broadleafcommerce.core.catalog.domain.Sku in project BroadleafCommerce by BroadleafCommerce.
the class ProductOptionsProcessor method addProductOptionPricingToModel.
protected void addProductOptionPricingToModel(Map<String, Object> newModelVars, Product product, BroadleafTemplateContext context, Map<String, String> tagAttributes) {
List<Sku> skus = product.getSkus();
List<ProductOptionPricingDTO> skuPricing = new ArrayList<>();
for (Sku sku : skus) {
List<Long> productOptionValueIds = new ArrayList<>();
List<ProductOptionValue> productOptionValues = sku.getProductOptionValues();
for (ProductOptionValue productOptionValue : productOptionValues) {
productOptionValueIds.add(productOptionValue.getId());
}
ProductOptionPricingDTO pricingDto = createPricingDto(sku, productOptionValueIds, tagAttributes, context);
skuPricing.add(pricingDto);
}
writeJSONToModel(newModelVars, "skuPricing", skuPricing);
}
use of org.broadleafcommerce.core.catalog.domain.Sku in project BroadleafCommerce by BroadleafCommerce.
the class UncacheableDataProcessor method addProductInventoryData.
protected void addProductInventoryData(Map<String, Object> attrMap, BroadleafTemplateContext context) {
List<Long> outOfStockProducts = new ArrayList<>();
List<Long> outOfStockSkus = new ArrayList<>();
Set<Product> allProducts = new HashSet<>();
Set<Sku> allSkus = new HashSet<>();
Set<Product> products = (Set<Product>) context.getVariable("blcAllDisplayedProducts");
Set<Sku> skus = (Set<Sku>) context.getVariable("blcAllDisplayedSkus");
if (!CollectionUtils.isEmpty(products)) {
allProducts.addAll(products);
}
if (!CollectionUtils.isEmpty(skus)) {
allSkus.addAll(skus);
}
extensionManager.getProxy().modifyProductListForInventoryCheck(context, allProducts, allSkus);
if (!allProducts.isEmpty()) {
for (Product product : allProducts) {
if (product.getDefaultSku() != null) {
Boolean qtyAvailable = inventoryService.isAvailable(product.getDefaultSku(), 1);
if (qtyAvailable != null && !qtyAvailable) {
outOfStockProducts.add(product.getId());
} else {
InventoryServiceExtensionHandler handler = inventoryServiceExtensionManager.getProxy();
ExtensionResultHolder<Boolean> holder = new ExtensionResultHolder<>();
handler.isProductBundleAvailable(product, 1, holder);
Boolean available = holder.getResult();
if (available != null && !available) {
outOfStockProducts.add(product.getId());
}
}
}
}
} else {
if (!allSkus.isEmpty()) {
Map<Sku, Integer> inventoryAvailable = inventoryService.retrieveQuantitiesAvailable(allSkus);
for (Map.Entry<Sku, Integer> entry : inventoryAvailable.entrySet()) {
if (entry.getValue() == null || entry.getValue() < 1) {
outOfStockSkus.add(entry.getKey().getId());
}
}
}
}
attrMap.put("outOfStockProducts", outOfStockProducts);
attrMap.put("outOfStockSkus", outOfStockSkus);
}
use of org.broadleafcommerce.core.catalog.domain.Sku in project BroadleafCommerce by BroadleafCommerce.
the class SeoDefaultPropertyServiceImpl method getImage.
@Override
public String getImage(Product product) {
Sku defaultSku = product.getDefaultSku();
Map<String, SkuMediaXref> mediaXrefs = defaultSku.getSkuMediaXref();
SkuMediaXref primaryMediaXref = mediaXrefs.get("primary");
if (primaryMediaXref != null) {
Media primaryMedia = primaryMediaXref.getMedia();
return urlResolver.getSiteBaseUrl() + primaryMedia.getUrl();
}
return null;
}
use of org.broadleafcommerce.core.catalog.domain.Sku in project BroadleafCommerce by BroadleafCommerce.
the class SolrSearchServiceImpl method getSkus.
/**
* Given a list of Sku IDs from solr, this method will look up the IDs via the skuDao and build out
* actual Sku instances. It will return a Sku list that is sorted by the order of the IDs in the passed
* in list.
*
* @param response
* @return the actual Sku instances as a result of the search
*/
protected List<Sku> getSkus(List<SolrDocument> responseDocuments) {
final List<Long> skuIds = new ArrayList<>();
for (SolrDocument doc : responseDocuments) {
skuIds.add((Long) doc.getFieldValue(shs.getIndexableIdFieldName()));
}
List<Sku> skus = skuDao.readSkusByIds(skuIds);
// We have to sort the skus list by the order of the skuIds list to maintain sortability in the UI
if (skus != null) {
Collections.sort(skus, new Comparator<Sku>() {
@Override
public int compare(Sku o1, Sku o2) {
return new Integer(skuIds.indexOf(o1.getId())).compareTo(skuIds.indexOf(o2.getId()));
}
});
}
return skus;
}
use of org.broadleafcommerce.core.catalog.domain.Sku 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