use of org.broadleafcommerce.core.catalog.domain.ProductOptionValue in project BroadleafCommerce by BroadleafCommerce.
the class DefaultAdminCatalogExtensionHandler method persistSkuPermutation.
/**
* Simply iterates through the permutations based on the product options and persists them
* as new {@link org.broadleafcommerce.core.catalog.domain.Sku} instances in the {@link org.broadleafcommerce.core.catalog.domain.Product}
*
* @param product
* @param permutationsToGenerate
* @param erh
* @return
*/
@Override
public ExtensionResultStatusType persistSkuPermutation(Product product, List<List<ProductOptionValue>> permutationsToGenerate, ExtensionResultHolder<Integer> erh) {
int numPermutationsCreated = 0;
// For each permutation, I need them to map to a specific Sku
for (List<ProductOptionValue> permutation : permutationsToGenerate) {
if (permutation.isEmpty())
continue;
Sku permutatedSku = catalogService.createSku();
permutatedSku.setProduct(product);
permutatedSku.setProductOptionValues(permutation);
permutatedSku = catalogService.saveSku(permutatedSku);
product.getAdditionalSkus().add(permutatedSku);
numPermutationsCreated++;
}
if (numPermutationsCreated != 0) {
catalogService.saveProduct(product);
}
erh.setResult(numPermutationsCreated);
return ExtensionResultStatusType.HANDLED;
}
use of org.broadleafcommerce.core.catalog.domain.ProductOptionValue 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);
}
Aggregations