use of org.broadleafcommerce.core.catalog.domain.Product in project BroadleafCommerce by BroadleafCommerce.
the class ProductCustomPersistenceHandler method update.
@Override
public Entity update(PersistencePackage persistencePackage, DynamicEntityDao dynamicEntityDao, RecordHelper helper) throws ServiceException {
Entity entity = persistencePackage.getEntity();
try {
PersistencePerspective persistencePerspective = persistencePackage.getPersistencePerspective();
Map<String, FieldMetadata> adminProperties = helper.getSimpleMergedProperties(Product.class.getName(), persistencePerspective);
BasicFieldMetadata defaultCategory = ((BasicFieldMetadata) adminProperties.get("defaultCategory"));
defaultCategory.setFriendlyName("ProductImpl_Parent_Category");
if (entity.findProperty("defaultCategory") != null && !StringUtils.isEmpty(entity.findProperty("defaultCategory").getValue())) {
// Change the inherited type so that this property is disconnected from the entity and validation is temporarily skipped.
// This is useful when the defaultCategory was previously completely empty for whatever reason. Without this, such
// a case would fail the validation, even though the property was specified in the submission.
defaultCategory.setInheritedFromType(String.class.getName());
}
Object primaryKey = helper.getPrimaryKey(entity, adminProperties);
Product adminInstance = (Product) dynamicEntityDao.retrieve(Class.forName(entity.getType()[0]), primaryKey);
if (adminInstance instanceof ProductBundle) {
removeBundleFieldRestrictions((ProductBundle) adminInstance, adminProperties, entity);
}
CategoryProductXref oldDefault = getCurrentDefaultXref(adminInstance);
// so override required flag for that field during deployment
if (BroadleafRequestContext.getBroadleafRequestContext().isProductionSandBox()) {
((BasicFieldMetadata) adminProperties.get("defaultCategory")).setRequiredOverride(false);
}
adminInstance = (Product) helper.createPopulatedInstance(adminInstance, entity, adminProperties, false);
adminInstance = dynamicEntityDao.merge(adminInstance);
boolean handled = false;
if (extensionManager != null) {
ExtensionResultStatusType result = extensionManager.getProxy().manageParentCategoryForUpdate(persistencePackage, adminInstance);
handled = ExtensionResultStatusType.NOT_HANDLED != result;
extensionManager.getProxy().manageFields(persistencePackage, adminInstance);
}
if (!handled) {
setupXref(adminInstance);
removeOldDefault(adminInstance, oldDefault, entity);
}
return helper.getRecord(adminProperties, adminInstance, null, null);
} catch (Exception e) {
throw new ServiceException("Unable to update entity for " + entity.getType()[0], e);
}
}
use of org.broadleafcommerce.core.catalog.domain.Product in project BroadleafCommerce by BroadleafCommerce.
the class ProductCustomPersistenceHandler method remove.
@Override
public void remove(PersistencePackage persistencePackage, DynamicEntityDao dynamicEntityDao, RecordHelper helper) throws ServiceException {
Entity entity = persistencePackage.getEntity();
try {
Product adminInstance = getAdminInstance(persistencePackage, dynamicEntityDao, helper, entity);
removeProduct(persistencePackage, adminInstance, helper);
} catch (ClassNotFoundException e) {
throw new ServiceException("Unable to remove entity for " + entity.getType()[0], e);
}
}
use of org.broadleafcommerce.core.catalog.domain.Product in project BroadleafCommerce by BroadleafCommerce.
the class ProductUrlFieldPersistenceProvider method populateValue.
@Override
public MetadataProviderResponse populateValue(PopulateValueRequest request, Serializable instance) {
String propName = request.getProperty().getName();
String val = request.getRequestedValue();
if ("url".equals(propName) && ProductImpl.class.isAssignableFrom(instance.getClass())) {
Product product = (Product) instance;
ExtensionResultHolder<String> holder = new ExtensionResultHolder<>();
ExtensionResultStatusType result = extensionManager.getProxy().modifyUrl(val, product, holder);
if (ExtensionResultStatusType.HANDLED == result) {
product.setUrl(holder.getResult());
return MetadataProviderResponse.HANDLED;
}
}
return super.populateValue(request, instance);
}
use of org.broadleafcommerce.core.catalog.domain.Product in project BroadleafCommerce by BroadleafCommerce.
the class SkuPricingPersistenceProvider method getCurrency.
@Override
protected Currency getCurrency(ExtractValueRequest extractValueRequest, Property property) {
BroadleafCurrency bc = null;
if (extractValueRequest.getEntity() instanceof Product && isDefaultSkuProperty(extractValueRequest, property)) {
Product p = (Product) extractValueRequest.getEntity();
bc = p.getDefaultSku().getCurrency();
} else if (extractValueRequest.getEntity() instanceof Sku) {
Sku s = (Sku) extractValueRequest.getEntity();
bc = s.getCurrency();
}
if (bc == null) {
BroadleafRequestContext brc = BroadleafRequestContext.getBroadleafRequestContext();
return brc.getJavaCurrency();
} else {
return Currency.getInstance(bc.getCurrencyCode());
}
}
use of org.broadleafcommerce.core.catalog.domain.Product 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