use of org.broadleafcommerce.core.catalog.domain.Sku in project BroadleafCommerce by BroadleafCommerce.
the class SkuCustomPersistenceHandler method fetch.
@SuppressWarnings("unchecked")
@Override
public DynamicResultSet fetch(PersistencePackage persistencePackage, CriteriaTransferObject cto, DynamicEntityDao dynamicEntityDao, RecordHelper helper) throws ServiceException {
String ceilingEntityFullyQualifiedClassname = persistencePackage.getCeilingEntityFullyQualifiedClassname();
try {
PersistencePerspective persistencePerspective = persistencePackage.getPersistencePerspective();
// get the default properties from Sku and its subclasses
Map<String, FieldMetadata> originalProps = helper.getSimpleMergedProperties(Sku.class.getName(), persistencePerspective);
// Pull back the Skus based on the criteria from the client
List<FilterMapping> filterMappings = helper.getFilterMappings(persistencePerspective, cto, ceilingEntityFullyQualifiedClassname, originalProps);
// allow subclasses to provide additional criteria before executing the query
applyProductOptionValueCriteria(filterMappings, cto, persistencePackage, null);
applySkuBundleItemValueCriteria(filterMappings, cto, persistencePackage);
applyAdditionalFetchCriteria(filterMappings, cto, persistencePackage);
List<Serializable> records = helper.getPersistentRecords(persistencePackage.getCeilingEntityFullyQualifiedClassname(), filterMappings, cto.getFirstResult(), cto.getMaxResults());
// Convert Skus into the client-side Entity representation
Entity[] payload = helper.getRecords(originalProps, records);
int totalRecords = helper.getTotalRecords(persistencePackage.getCeilingEntityFullyQualifiedClassname(), filterMappings);
// Now fill out the relevant properties for the product options for the Skus that were returned
updateProductOptionFieldsForFetch(records, payload);
return new DynamicResultSet(payload, totalRecords);
} catch (Exception e) {
throw new ServiceException("Unable to perform fetch for entity: " + ceilingEntityFullyQualifiedClassname, e);
}
}
use of org.broadleafcommerce.core.catalog.domain.Sku in project BroadleafCommerce by BroadleafCommerce.
the class SkuCustomPersistenceHandler method update.
@Override
public Entity update(PersistencePackage persistencePackage, DynamicEntityDao dynamicEntityDao, RecordHelper helper) throws ServiceException {
Entity entity = persistencePackage.getEntity();
try {
// Fill out the Sku instance from the form
PersistencePerspective persistencePerspective = persistencePackage.getPersistencePerspective();
Map<String, FieldMetadata> adminProperties = helper.getSimpleMergedProperties(Sku.class.getName(), persistencePerspective);
filterOutProductMetadata(adminProperties);
Object primaryKey = helper.getPrimaryKey(entity, adminProperties);
Sku adminInstance = (Sku) dynamicEntityDao.retrieve(Class.forName(entity.getType()[0]), primaryKey);
adminInstance = (Sku) helper.createPopulatedInstance(adminInstance, entity, adminProperties, false);
// Verify that there isn't already a Sku for this particular product option value combo
Entity errorEntity = validateUniqueProductOptionValueCombination(adminInstance.getProduct(), getProductOptionProperties(entity), adminInstance);
if (errorEntity != null) {
entity.setPropertyValidationErrors(errorEntity.getPropertyValidationErrors());
return entity;
}
// Only modify product options if this ISN'T an update for inventory properties
if (!persistencePackage.containsCriteria(INVENTORY_ONLY_CRITERIA)) {
associateProductOptionValuesToSku(entity, adminInstance, dynamicEntityDao);
}
adminInstance = dynamicEntityDao.merge(adminInstance);
extensionManager.getProxy().skuUpdated(adminInstance);
// Fill out the DTO and add in the product option value properties to it
Entity result = helper.getRecord(adminProperties, adminInstance, null, null);
for (Property property : getProductOptionProperties(entity)) {
result.addProperty(property);
}
return result;
} catch (Exception e) {
throw new ServiceException("Unable to perform update for entity: " + Sku.class.getName(), e);
}
}
use of org.broadleafcommerce.core.catalog.domain.Sku 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.Sku in project BroadleafCommerce by BroadleafCommerce.
the class SkuCustomPersistenceHandler method add.
@Override
public Entity add(PersistencePackage persistencePackage, DynamicEntityDao dynamicEntityDao, RecordHelper helper) throws ServiceException {
Entity entity = persistencePackage.getEntity();
try {
// Fill out the Sku instance from the form
PersistencePerspective persistencePerspective = persistencePackage.getPersistencePerspective();
Sku adminInstance = (Sku) Class.forName(entity.getType()[0]).newInstance();
Map<String, FieldMetadata> adminProperties = helper.getSimpleMergedProperties(Sku.class.getName(), persistencePerspective);
filterOutProductMetadata(adminProperties);
adminInstance = (Sku) helper.createPopulatedInstance(adminInstance, entity, adminProperties, false);
// Verify that there isn't already a Sku for this particular product option value combo
Entity errorEntity = validateUniqueProductOptionValueCombination(adminInstance.getProduct(), getProductOptionProperties(entity), null);
if (errorEntity != null) {
entity.setPropertyValidationErrors(errorEntity.getPropertyValidationErrors());
return entity;
}
// persist the newly-created Sku
adminInstance = dynamicEntityDao.persist(adminInstance);
// associate the product option values
associateProductOptionValuesToSku(entity, adminInstance, dynamicEntityDao);
// After associating the product option values, save off the Sku
adminInstance = dynamicEntityDao.merge(adminInstance);
// Fill out the DTO and add in the product option value properties to it
Entity result = helper.getRecord(adminProperties, adminInstance, null, null);
for (Property property : getProductOptionProperties(entity)) {
result.addProperty(property);
}
return result;
} catch (Exception e) {
throw new ServiceException("Unable to perform fetch for entity: " + Sku.class.getName(), e);
}
}
use of org.broadleafcommerce.core.catalog.domain.Sku 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());
}
}
Aggregations