use of org.broadleafcommerce.core.catalog.domain.Product in project BroadleafCommerce by BroadleafCommerce.
the class ProductDataProvider method createProducts.
@DataProvider(name = "setupProducts")
public static Object[][] createProducts() {
Product p1 = getProduct(null);
Product p2 = getProduct(null);
Product p3 = getProduct(null);
Product p4 = getProduct(null);
Product p5 = getProduct(null);
Product p6 = getProduct(null);
Product p7 = getProduct(null);
Object[][] objs = new Object[7][1];
objs[0] = new Object[] { p1 };
objs[1] = new Object[] { p2 };
objs[2] = new Object[] { p3 };
objs[3] = new Object[] { p4 };
objs[4] = new Object[] { p5 };
objs[5] = new Object[] { p6 };
objs[6] = new Object[] { p7 };
return objs;
}
use of org.broadleafcommerce.core.catalog.domain.Product in project BroadleafCommerce by BroadleafCommerce.
the class ProductCustomPersistenceHandler method getAdminInstance.
protected Product getAdminInstance(PersistencePackage persistencePackage, DynamicEntityDao dynamicEntityDao, RecordHelper helper, Entity entity) throws ClassNotFoundException {
PersistencePerspective persistencePerspective = persistencePackage.getPersistencePerspective();
Map<String, FieldMetadata> adminProperties = helper.getSimpleMergedProperties(Product.class.getName(), persistencePerspective);
Object primaryKey = helper.getPrimaryKey(entity, adminProperties);
String type = entity.getType()[0];
Product adminInstance = (Product) dynamicEntityDao.retrieve(Class.forName(type), primaryKey);
return adminInstance;
}
use of org.broadleafcommerce.core.catalog.domain.Product in project BroadleafCommerce by BroadleafCommerce.
the class ProductCustomPersistenceHandler method add.
@Override
public Entity add(PersistencePackage persistencePackage, DynamicEntityDao dynamicEntityDao, RecordHelper helper) throws ServiceException {
Entity entity = persistencePackage.getEntity();
try {
PersistencePerspective persistencePerspective = persistencePackage.getPersistencePerspective();
Product adminInstance = (Product) Class.forName(entity.getType()[0]).newInstance();
Map<String, FieldMetadata> adminProperties = helper.getSimpleMergedProperties(Product.class.getName(), persistencePerspective);
if (adminInstance instanceof ProductBundle) {
removeBundleFieldRestrictions((ProductBundle) adminInstance, adminProperties, entity);
}
adminInstance = (Product) helper.createPopulatedInstance(adminInstance, entity, adminProperties, false);
adminInstance = dynamicEntityDao.merge(adminInstance);
// any Sku fields, and thus a Sku would not be created. Product still needs a default Sku so instantiate one
if (adminInstance.getDefaultSku() == null) {
Sku newSku = catalogService.createSku();
dynamicEntityDao.persist(newSku);
adminInstance.setDefaultSku(newSku);
adminInstance = dynamicEntityDao.merge(adminInstance);
}
// also set the default product for the Sku
adminInstance.getDefaultSku().setDefaultProduct(adminInstance);
dynamicEntityDao.merge(adminInstance.getDefaultSku());
// if this is a Pre-Add, skip the rest of the method
if (entity.isPreAdd()) {
return helper.getRecord(adminProperties, adminInstance, null, null);
}
boolean handled = false;
if (extensionManager != null) {
ExtensionResultStatusType result = extensionManager.getProxy().manageParentCategoryForAdd(persistencePackage, adminInstance);
handled = ExtensionResultStatusType.NOT_HANDLED != result;
}
if (!handled) {
setupXref(adminInstance);
}
return helper.getRecord(adminProperties, adminInstance, null, null);
} catch (Exception e) {
throw new ServiceException("Unable to add entity for " + entity.getType()[0], e);
}
}
use of org.broadleafcommerce.core.catalog.domain.Product in project BroadleafCommerce by BroadleafCommerce.
the class SkuCustomPersistenceHandler method inspect.
/**
* Build out the extra fields for the product options
*/
@Override
public DynamicResultSet inspect(PersistencePackage persistencePackage, DynamicEntityDao dynamicEntityDao, InspectHelper helper) throws ServiceException {
try {
PersistencePerspective persistencePerspective = persistencePackage.getPersistencePerspective();
Map<MergedPropertyType, Map<String, FieldMetadata>> allMergedProperties = new HashMap<>();
String productIdStr = null;
if (persistencePackage.getCustomCriteria() != null && persistencePackage.getCustomCriteria().length > 0) {
productIdStr = persistencePackage.getCustomCriteria()[0];
}
String cacheKey = skuMetadataCacheService.buildCacheKey(productIdStr);
Map<String, FieldMetadata> properties = null;
boolean useCache = skuMetadataCacheService.useCache();
if (useCache) {
properties = skuMetadataCacheService.getFromCache(cacheKey);
}
if (properties == null) {
// Grab the default properties for the Sku
properties = helper.getSimpleMergedProperties(SkuImpl.class.getName(), persistencePerspective);
boolean isFirstCriteriaNAN = persistencePackage.getCustomCriteria() == null || persistencePackage.getCustomCriteria().length == 0;
if (!isFirstCriteriaNAN && useToOneLookupSkuProductOptionValue) {
isFirstCriteriaNAN = !DIGIT.matchesAllOf(persistencePackage.getCustomCriteria()[0]);
}
if (isFirstCriteriaNAN) {
// look up all the ProductOptions and then create new fields for each of them
List<ProductOption> options = catalogService.readAllProductOptions();
int order = 0;
for (ProductOption option : options) {
// add this to the built Sku properties
FieldMetadata md = createIndividualOptionField(option, order);
if (md != null) {
properties.put("productOption" + option.getId(), md);
}
}
} else {
// If we have a product to filter the list of available product options, then use it
try {
Long productId = Long.parseLong(persistencePackage.getCustomCriteria()[0]);
Product product = catalogService.findProductById(productId);
for (ProductOption option : product.getProductOptions()) {
FieldMetadata md = createIndividualOptionField(option, 0);
if (md != null) {
properties.put("productOption" + option.getId(), md);
}
}
} catch (NumberFormatException e) {
// the criteria wasn't a product id, just don't do anything
}
}
// also build the consolidated field; if using the SkuBasicClientEntityModule then this field will be
// permanently hidden
properties.put(CONSOLIDATED_PRODUCT_OPTIONS_FIELD_NAME, createConsolidatedOptionField(SkuImpl.class));
if (useCache) {
skuMetadataCacheService.addToCache(cacheKey, properties);
}
}
allMergedProperties.put(MergedPropertyType.PRIMARY, properties);
// allow the adorned list to contribute properties as well in the case of Sku bundle items
adornedPersistenceModule.setPersistenceManager((PersistenceManager) helper);
adornedPersistenceModule.updateMergedProperties(persistencePackage, allMergedProperties);
Class<?>[] entityClasses = dynamicEntityDao.getAllPolymorphicEntitiesFromCeiling(SkuImpl.class);
for (Map.Entry<MergedPropertyType, Map<String, FieldMetadata>> entry : allMergedProperties.entrySet()) {
filterOutProductMetadata(entry.getValue());
}
ClassMetadata mergedMetadata = helper.buildClassMetadata(entityClasses, persistencePackage, allMergedProperties);
DynamicResultSet results = new DynamicResultSet(mergedMetadata, null, null);
return results;
} catch (Exception e) {
ServiceException ex = new ServiceException("Unable to retrieve inspection results for " + persistencePackage.getCeilingEntityFullyQualifiedClassname(), e);
throw ex;
}
}
use of org.broadleafcommerce.core.catalog.domain.Product in project BroadleafCommerce by BroadleafCommerce.
the class ProductParentCategoryFieldPersistenceProvider method populateValue.
@Override
public MetadataProviderResponse populateValue(PopulateValueRequest populateValueRequest, Serializable instance) {
if (!canHandlePersistence(populateValueRequest, instance)) {
return MetadataProviderResponse.NOT_HANDLED;
}
boolean handled = false;
if (extensionManager != null) {
ExtensionResultStatusType result = extensionManager.getProxy().manageParentCategory(populateValueRequest.getProperty(), (Product) instance);
handled = ExtensionResultStatusType.NOT_HANDLED != result;
}
if (!handled || BroadleafRequestContext.getBroadleafRequestContext().isProductionSandBox()) {
Long requestedValue = null;
if (StringUtils.isNotEmpty(populateValueRequest.getRequestedValue())) {
requestedValue = Long.parseLong(populateValueRequest.getRequestedValue());
}
boolean dirty = checkDirtyState((Product) instance, requestedValue);
if (dirty) {
populateValueRequest.getProperty().setIsDirty(true);
if (requestedValue != null) {
((Product) instance).setCategory((Category) populateValueRequest.getPersistenceManager().getDynamicEntityDao().find(CategoryImpl.class, requestedValue));
} else {
((Product) instance).setCategory(null);
}
}
}
return MetadataProviderResponse.HANDLED_BREAK;
}
Aggregations