use of org.broadleafcommerce.core.catalog.domain.ProductBundle 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.ProductBundle in project BroadleafCommerce by BroadleafCommerce.
the class ProductDaoImpl method readAutomaticProductBundles.
@Override
public List<ProductBundle> readAutomaticProductBundles() {
Date currentDate = DateUtil.getCurrentDateAfterFactoringInDateResolution(cachedDate, currentDateResolution);
TypedQuery<ProductBundle> query = em.createNamedQuery("BC_READ_AUTOMATIC_PRODUCT_BUNDLES", ProductBundle.class);
query.setParameter("currentDate", currentDate);
query.setParameter("autoBundle", Boolean.TRUE);
query.setHint(QueryHints.HINT_CACHEABLE, true);
query.setHint(QueryHints.HINT_CACHE_REGION, "query.Catalog");
return query.getResultList();
}
use of org.broadleafcommerce.core.catalog.domain.ProductBundle in project BroadleafCommerce by BroadleafCommerce.
the class CatalogServiceImpl method findAutomaticProductBundles.
@Override
public List<ProductBundle> findAutomaticProductBundles() {
List<ProductBundle> bundles = productDao.readAutomaticProductBundles();
Collections.sort(bundles, new ProductBundleComparator());
return bundles;
}
use of org.broadleafcommerce.core.catalog.domain.ProductBundle in project BroadleafCommerce by BroadleafCommerce.
the class ProductBundleSkuBundleItemValidator method validate.
@Override
public PropertyValidationResult validate(Entity entity, Serializable instance, Map<String, FieldMetadata> entityFieldMetadata, Map<String, String> validationConfiguration, BasicFieldMetadata propertyMetadata, String propertyName, String value) {
String skuId = entity.findProperty("sku") == null ? null : entity.findProperty("sku").getValue();
String bundleId = entity.findProperty("bundle") == null ? null : entity.findProperty("bundle").getValue();
if (skuId != null && bundleId != null) {
ProductBundle productBundle = (ProductBundle) catalogService.findProductById(Long.valueOf(bundleId));
Long defaultSkuOrigId = sandBoxHelper.getOriginalId(Sku.class, productBundle.getDefaultSku().getId()).getOriginalId();
if (Long.valueOf(skuId).equals(defaultSkuOrigId)) {
return new PropertyValidationResult(false, ERROR_MESSAGE);
}
}
return new PropertyValidationResult(true);
}
use of org.broadleafcommerce.core.catalog.domain.ProductBundle in project BroadleafCommerce by BroadleafCommerce.
the class OrderItemServiceImpl method buildOrderItemFromDTO.
@Override
public OrderItem buildOrderItemFromDTO(Order order, OrderItemRequestDTO orderItemRequestDTO) {
Sku sku = null;
if (orderItemRequestDTO.getSkuId() != null) {
sku = catalogService.findSkuById(orderItemRequestDTO.getSkuId());
}
Product product = null;
if (orderItemRequestDTO.getProductId() != null) {
product = catalogService.findProductById(orderItemRequestDTO.getProductId());
}
Category category = null;
if (orderItemRequestDTO.getCategoryId() != null) {
category = catalogService.findCategoryById(orderItemRequestDTO.getCategoryId());
}
if (category == null && product != null) {
category = product.getDefaultCategory();
}
OrderItem item;
if (orderItemRequestDTO instanceof NonDiscreteOrderItemRequestDTO) {
NonDiscreteOrderItemRequestDTO ndr = (NonDiscreteOrderItemRequestDTO) orderItemRequestDTO;
OrderItemRequest itemRequest = new OrderItemRequest();
itemRequest.setQuantity(ndr.getQuantity());
itemRequest.setRetailPriceOverride(ndr.getOverrideRetailPrice());
itemRequest.setSalePriceOverride(ndr.getOverrideSalePrice());
itemRequest.setItemAttributes(orderItemRequestDTO.getItemAttributes());
itemRequest.setAdditionalAttributes(orderItemRequestDTO.getAdditionalAttributes());
itemRequest.setItemName(ndr.getItemName());
itemRequest.setOrder(order);
item = createOrderItem(itemRequest);
} else if (product == null || !(product instanceof ProductBundle)) {
DiscreteOrderItemRequest itemRequest = new DiscreteOrderItemRequest();
itemRequest.setCategory(category);
itemRequest.setProduct(product);
itemRequest.setSku(sku);
itemRequest.setQuantity(orderItemRequestDTO.getQuantity());
itemRequest.setItemAttributes(orderItemRequestDTO.getItemAttributes());
itemRequest.setAdditionalAttributes(orderItemRequestDTO.getAdditionalAttributes());
itemRequest.setOrder(order);
itemRequest.setSalePriceOverride(orderItemRequestDTO.getOverrideSalePrice());
itemRequest.setRetailPriceOverride(orderItemRequestDTO.getOverrideRetailPrice());
item = createDiscreteOrderItem(itemRequest);
} else {
ProductBundleOrderItemRequest bundleItemRequest = new ProductBundleOrderItemRequest();
bundleItemRequest.setCategory(category);
bundleItemRequest.setProductBundle((ProductBundle) product);
bundleItemRequest.setSku(sku);
bundleItemRequest.setQuantity(orderItemRequestDTO.getQuantity());
bundleItemRequest.setItemAttributes(orderItemRequestDTO.getItemAttributes());
bundleItemRequest.setName(product.getName());
bundleItemRequest.setOrder(order);
bundleItemRequest.setSalePriceOverride(orderItemRequestDTO.getOverrideSalePrice());
bundleItemRequest.setRetailPriceOverride(orderItemRequestDTO.getOverrideRetailPrice());
item = createBundleOrderItem(bundleItemRequest, false);
}
if (orderItemRequestDTO.getParentOrderItemId() != null) {
OrderItem parent = readOrderItemById(orderItemRequestDTO.getParentOrderItemId());
item.setParentOrderItem(parent);
}
if (orderItemRequestDTO.getHasConfigurationError()) {
item.setHasValidationError(true);
}
if (orderItemRequestDTO instanceof ConfigurableOrderItemRequest) {
ConfigurableOrderItemRequest configRequest = (ConfigurableOrderItemRequest) orderItemRequestDTO;
if (configRequest.getHasConfigurationError()) {
item.setHasValidationError(true);
}
if (!configRequest.getDiscountsAllowed()) {
item.setDiscountingAllowed(false);
}
}
applyAdditionalOrderItemProperties(item);
return item;
}
Aggregations