use of org.broadleafcommerce.core.catalog.domain.ProductOptionValue in project BroadleafCommerce by BroadleafCommerce.
the class ProductOptionsProcessor method addAllProductOptionsToModel.
protected void addAllProductOptionsToModel(Map<String, Object> newModelVars, Product product) {
List<ProductOption> productOptions = product.getProductOptions();
List<ProductOptionDTO> dtos = new ArrayList<>();
for (ProductOption option : productOptions) {
ProductOptionDTO dto = new ProductOptionDTO();
dto.setId(option.getId());
dto.setType(option.getType().getType());
Map<Long, String> values = new HashMap<>();
for (ProductOptionValue value : option.getAllowedValues()) {
values.put(value.getId(), value.getAttributeValue());
}
dto.setValues(values);
dtos.add(dto);
}
writeJSONToModel(newModelVars, "allProductOptions", dtos);
}
use of org.broadleafcommerce.core.catalog.domain.ProductOptionValue in project BroadleafCommerce by BroadleafCommerce.
the class i18nUpdateCartServiceExtensionHandler method translateOrderItem.
protected void translateOrderItem(OrderItem orderItem, Sku sku) {
if (sku != null) {
orderItem.setName(sku.getName());
if (sku.getProductOptionValues() != null) {
for (ProductOptionValue optionValue : sku.getProductOptionValues()) {
String key = optionValue.getProductOption().getAttributeName();
OrderItemAttribute attr = orderItem.getOrderItemAttributes().get(key);
if (attr != null) {
attr.setValue(optionValue.getAttributeValue());
} else {
OrderItemAttribute attribute = new OrderItemAttributeImpl();
attribute.setName(key);
attribute.setValue(optionValue.getAttributeValue());
attribute.setOrderItem(orderItem);
orderItem.getOrderItemAttributes().put(key, attribute);
}
}
}
}
}
use of org.broadleafcommerce.core.catalog.domain.ProductOptionValue in project BroadleafCommerce by BroadleafCommerce.
the class AdminCatalogServiceImpl method generatePermutations.
/**
* Generates all the possible permutations for the combinations of given ProductOptions
* @param currentTypeIndex
* @param currentPermutation
* @param options
* @return a list containing all of the possible combinations of ProductOptionValues based on grouping by the ProductOptionValue
*/
public List<List<ProductOptionValue>> generatePermutations(int currentTypeIndex, List<ProductOptionValue> currentPermutation, List<ProductOption> options) {
List<List<ProductOptionValue>> result = new ArrayList<List<ProductOptionValue>>();
if (currentTypeIndex == options.size()) {
result.add(currentPermutation);
return result;
}
ProductOption currentOption = options.get(currentTypeIndex);
List<ProductOptionValue> allowedValues = currentOption.getAllowedValues();
if (!currentOption.getUseInSkuGeneration()) {
// This flag means do not generate skus and so do not create permutations for this ProductOption,
// end it here and return the current list of permutations.
result.addAll(generatePermutations(currentTypeIndex + 1, currentPermutation, options));
return result;
}
// Check to make sure there is at least 1 Allowed Value, else prevent generation
if (currentOption.getAllowedValues().isEmpty()) {
return null;
}
for (ProductOptionValue option : allowedValues) {
List<ProductOptionValue> permutation = new ArrayList<ProductOptionValue>();
permutation.addAll(currentPermutation);
permutation.add(option);
result.addAll(generatePermutations(currentTypeIndex + 1, permutation, options));
}
if (allowedValues.size() == 0) {
// There are still product options left in our array to compute permutations, even though this ProductOption does not have any values associated.
result.addAll(generatePermutations(currentTypeIndex + 1, currentPermutation, options));
}
return result;
}
use of org.broadleafcommerce.core.catalog.domain.ProductOptionValue in project BroadleafCommerce by BroadleafCommerce.
the class SkuCustomPersistenceHandler method updateProductOptionFieldsForFetch.
/**
* Sets the {@link ProductOptionValue}s of the given {@link Sku}s in a list format for display in a ListGrid context.
*
* @param records
* @param payload
* @return
*/
public void updateProductOptionFieldsForFetch(List<Serializable> records, Entity[] payload) {
for (int i = 0; i < records.size(); i++) {
Sku sku = (Sku) records.get(i);
Entity entity = payload[i];
List<ProductOptionValue> optionValues = BLCCollectionUtils.collectList(sku.getProductOptionValueXrefs(), new TypedTransformer<ProductOptionValue>() {
@Override
public ProductOptionValue transform(Object input) {
return ((SkuProductOptionValueXref) input).getProductOptionValue();
}
});
for (ProductOptionValue value : optionValues) {
Property optionProperty = new Property();
optionProperty.setName(PRODUCT_OPTION_FIELD_PREFIX + value.getProductOption().getId());
optionProperty.setValue(value.getId().toString());
optionProperty.setDisplayValue(value.getAttributeValue());
entity.addProperty(optionProperty);
}
if (CollectionUtils.isNotEmpty(optionValues)) {
entity.addProperty(getConsolidatedOptionProperty(optionValues));
} else {
entity.addProperty(getBlankConsolidatedOptionProperty());
}
}
}
use of org.broadleafcommerce.core.catalog.domain.ProductOptionValue in project BroadleafCommerce by BroadleafCommerce.
the class AdminCatalogServiceImpl method generateSkusFromProduct.
@Override
public Integer generateSkusFromProduct(Long productId) {
Product product = catalogService.findProductById(productId);
if (CollectionUtils.isEmpty(product.getProductOptions())) {
return -1;
}
List<List<ProductOptionValue>> allPermutations = generatePermutations(0, new ArrayList<ProductOptionValue>(), product.getProductOptions());
// return -2 to indicate that one of the Product Options used in Sku generation has no Allowed Values
if (allPermutations == null) {
return -2;
}
LOG.info("Total number of permutations: " + allPermutations.size());
LOG.info(allPermutations);
// determine the permutations that I already have Skus for
List<List<ProductOptionValue>> previouslyGeneratedPermutations = new ArrayList<List<ProductOptionValue>>();
if (CollectionUtils.isNotEmpty(product.getAdditionalSkus())) {
for (Sku additionalSku : product.getAdditionalSkus()) {
if (CollectionUtils.isNotEmpty(additionalSku.getProductOptionValues())) {
previouslyGeneratedPermutations.add(additionalSku.getProductOptionValues());
}
}
}
List<List<ProductOptionValue>> permutationsToGenerate = new ArrayList<List<ProductOptionValue>>();
for (List<ProductOptionValue> permutation : allPermutations) {
boolean previouslyGenerated = false;
for (List<ProductOptionValue> generatedPermutation : previouslyGeneratedPermutations) {
if (isSamePermutation(permutation, generatedPermutation)) {
previouslyGenerated = true;
break;
}
}
if (!previouslyGenerated) {
permutationsToGenerate.add(permutation);
}
}
int numPermutationsCreated = 0;
if (extensionManager != null) {
ExtensionResultHolder<Integer> result = new ExtensionResultHolder<Integer>();
ExtensionResultStatusType resultStatusType = extensionManager.getProxy().persistSkuPermutation(product, permutationsToGenerate, result);
if (ExtensionResultStatusType.HANDLED == resultStatusType) {
numPermutationsCreated = result.getResult();
}
}
return numPermutationsCreated;
}
Aggregations