Class SkuGenerationService<P extends Variant>
java.lang.Object
com.broadleafcommerce.catalog.service.product.SkuGenerationService<P>
@ConfigurationProperties("broadleaf.catalog.sku.generation")
public class SkuGenerationService<P extends Variant>
extends Object
Responsible for generating Skus for a
OptionTemplateGroup
. To customize the SKU codes
that are genereated, see generateUniqueSkuCode(String)
.- Author:
- Phillip Verheyden (phillipuniverse)
-
Constructor Summary
ConstructorsConstructorDescriptionSkuGenerationService
(VariantService<P> variantSvc, ProductService<Product> productSvc, ProductOptionValueCombinationService combinationSvc, com.broadleafcommerce.common.extension.TypeFactory typeFactory, org.springframework.transaction.support.TransactionTemplate template) -
Method Summary
Modifier and TypeMethodDescriptionprotected <T extends ProductOptionValueCombination>
PbuildVariant
(String skuPrefix, Collection<T> valuesCombination, Product product) <T extends ProductOptionValueCombination,
C extends Collection<T>>
List<P>createAndSaveVariants
(Collection<C> combinationsToCreate, Product product, String skuCodePrefix, com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Creates and persistsVariants
for the given option combinations.generateSkus
(String skuCodePrefix, String productId, com.broadleafcommerce.data.tracking.core.context.ContextInfo context) Generate a set ofVariants
from a pre-configuredOptionTemplateGroup
.protected String
generateUniqueSkuCode
(String skuPrefix) Extension point to customize the format of SKU codes that are generatedprotected <T extends ProductOptionValueCombination>
StringgenerateVariantName
(Product product, Collection<T> valuesCombination) Extension point to customize the variant names that are generatedprotected ProductOptionValueCombinationService
protected OptionTemplateService<OptionTemplate>
int
protected ProductService<Product>
protected org.springframework.transaction.support.TransactionTemplate
protected com.broadleafcommerce.common.extension.TypeFactory
protected VariantService<P>
void
setOptionTemplateService
(OptionTemplateService<OptionTemplate> optionTemplateService) void
setPostfixCharacters
(int postfixCharacters)
-
Constructor Details
-
SkuGenerationService
public SkuGenerationService(VariantService<P> variantSvc, ProductService<Product> productSvc, ProductOptionValueCombinationService combinationSvc, com.broadleafcommerce.common.extension.TypeFactory typeFactory, org.springframework.transaction.support.TransactionTemplate template)
-
-
Method Details
-
generateSkus
public List<P> generateSkus(@Nullable String skuCodePrefix, @NonNull String productId, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo context) Generate a set ofVariants
from a pre-configuredOptionTemplateGroup
. Variants are only generated if theOptionTemplates
that appear in the givenOptionTemplateGroup
areDefaultProductOptionType.VARIANT_DISTINGUISHING
.All of the
Variants
created as a result of this operation are saved in the backing data store -
createAndSaveVariants
public <T extends ProductOptionValueCombination,C extends Collection<T>> List<P> createAndSaveVariants(Collection<C> combinationsToCreate, Product product, @Nullable String skuCodePrefix, @Nullable com.broadleafcommerce.data.tracking.core.context.ContextInfo contextInfo) Creates and persistsVariants
for the given option combinations.- Type Parameters:
T
- The type ofProductOptionValueCombination
C
- The type ofCollection
containingProductOptionValueCombinations
.- Parameters:
combinationsToCreate
- Combination of option values to create variants for.product
- The parent productskuCodePrefix
- A prefix for the SKUs for the generated variants.contextInfo
- Additional sandbox and multitenant info.- Returns:
- The created
Variants
.
-
buildVariant
protected <T extends ProductOptionValueCombination> P buildVariant(@Nullable String skuPrefix, Collection<T> valuesCombination, Product product) -
generateUniqueSkuCode
Extension point to customize the format of SKU codes that are generated- Parameters:
skuPrefix
- the preconfigured prefix for a SKU- Returns:
- a unique SKU code
-
generateVariantName
protected <T extends ProductOptionValueCombination> String generateVariantName(Product product, Collection<T> valuesCombination) Extension point to customize the variant names that are generated- Parameters:
product
- the owning productvaluesCombination
- the product option value combination used to generate this variant- Returns:
- a name for the variant
-
getVariantSvc
-
getProductSvc
-
getOptionTemplateService
-
setOptionTemplateService
@Autowired public void setOptionTemplateService(OptionTemplateService<OptionTemplate> optionTemplateService) -
getCombinationSvc
-
getTypeFactory
protected com.broadleafcommerce.common.extension.TypeFactory getTypeFactory() -
getTemplate
protected org.springframework.transaction.support.TransactionTemplate getTemplate() -
setPostfixCharacters
public void setPostfixCharacters(int postfixCharacters) -
getPostfixCharacters
public int getPostfixCharacters()
-