Search in sources :

Example 11 with ProductOptionValue

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;
}
Also used : ProductOptionValue(org.broadleafcommerce.core.catalog.domain.ProductOptionValue) Sku(org.broadleafcommerce.core.catalog.domain.Sku)

Example 12 with ProductOptionValue

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

Aggregations

ProductOptionValue (org.broadleafcommerce.core.catalog.domain.ProductOptionValue)12 ArrayList (java.util.ArrayList)7 Sku (org.broadleafcommerce.core.catalog.domain.Sku)6 Property (org.broadleafcommerce.openadmin.dto.Property)4 Entity (org.broadleafcommerce.openadmin.dto.Entity)3 HashMap (java.util.HashMap)2 List (java.util.List)2 ProductOption (org.broadleafcommerce.core.catalog.domain.ProductOption)2 SkuProductOptionValueXref (org.broadleafcommerce.core.catalog.domain.SkuProductOptionValueXref)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 Serializable (java.io.Serializable)1 StringWriter (java.io.StringWriter)1 Writer (java.io.Writer)1 ServiceException (org.broadleafcommerce.common.exception.ServiceException)1 ExtensionResultHolder (org.broadleafcommerce.common.extension.ExtensionResultHolder)1 ExtensionResultStatusType (org.broadleafcommerce.common.extension.ExtensionResultStatusType)1 Product (org.broadleafcommerce.core.catalog.domain.Product)1 ProductOptionValueImpl (org.broadleafcommerce.core.catalog.domain.ProductOptionValueImpl)1 SkuBundleItem (org.broadleafcommerce.core.catalog.domain.SkuBundleItem)1 SkuImpl (org.broadleafcommerce.core.catalog.domain.SkuImpl)1