Search in sources :

Example 6 with ProductBundle

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);
    }
}
Also used : Entity(org.broadleafcommerce.openadmin.dto.Entity) FieldMetadata(org.broadleafcommerce.openadmin.dto.FieldMetadata) BasicFieldMetadata(org.broadleafcommerce.openadmin.dto.BasicFieldMetadata) PersistencePerspective(org.broadleafcommerce.openadmin.dto.PersistencePerspective) ServiceException(org.broadleafcommerce.common.exception.ServiceException) ProductBundle(org.broadleafcommerce.core.catalog.domain.ProductBundle) Product(org.broadleafcommerce.core.catalog.domain.Product) ExtensionResultStatusType(org.broadleafcommerce.common.extension.ExtensionResultStatusType) Sku(org.broadleafcommerce.core.catalog.domain.Sku) ServiceException(org.broadleafcommerce.common.exception.ServiceException)

Example 7 with ProductBundle

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();
}
Also used : ProductBundle(org.broadleafcommerce.core.catalog.domain.ProductBundle) Date(java.util.Date)

Example 8 with ProductBundle

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;
}
Also used : ProductBundle(org.broadleafcommerce.core.catalog.domain.ProductBundle) ProductBundleComparator(org.broadleafcommerce.core.catalog.domain.ProductBundleComparator)

Example 9 with ProductBundle

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);
}
Also used : ProductBundle(org.broadleafcommerce.core.catalog.domain.ProductBundle) PropertyValidationResult(org.broadleafcommerce.openadmin.server.service.persistence.validation.PropertyValidationResult) Sku(org.broadleafcommerce.core.catalog.domain.Sku)

Example 10 with ProductBundle

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;
}
Also used : DiscreteOrderItemRequest(org.broadleafcommerce.core.order.service.call.DiscreteOrderItemRequest) AbstractOrderItemRequest(org.broadleafcommerce.core.order.service.call.AbstractOrderItemRequest) GiftWrapOrderItemRequest(org.broadleafcommerce.core.order.service.call.GiftWrapOrderItemRequest) OrderItemRequest(org.broadleafcommerce.core.order.service.call.OrderItemRequest) ProductBundleOrderItemRequest(org.broadleafcommerce.core.order.service.call.ProductBundleOrderItemRequest) ConfigurableOrderItemRequest(org.broadleafcommerce.core.order.service.call.ConfigurableOrderItemRequest) BundleOrderItemRequest(org.broadleafcommerce.core.order.service.call.BundleOrderItemRequest) Category(org.broadleafcommerce.core.catalog.domain.Category) DiscreteOrderItemRequest(org.broadleafcommerce.core.order.service.call.DiscreteOrderItemRequest) NonDiscreteOrderItemRequestDTO(org.broadleafcommerce.core.order.service.call.NonDiscreteOrderItemRequestDTO) DiscreteOrderItem(org.broadleafcommerce.core.order.domain.DiscreteOrderItem) OrderItem(org.broadleafcommerce.core.order.domain.OrderItem) GiftWrapOrderItem(org.broadleafcommerce.core.order.domain.GiftWrapOrderItem) BundleOrderItem(org.broadleafcommerce.core.order.domain.BundleOrderItem) ProductBundle(org.broadleafcommerce.core.catalog.domain.ProductBundle) ProductBundleOrderItemRequest(org.broadleafcommerce.core.order.service.call.ProductBundleOrderItemRequest) Product(org.broadleafcommerce.core.catalog.domain.Product) Sku(org.broadleafcommerce.core.catalog.domain.Sku) ConfigurableOrderItemRequest(org.broadleafcommerce.core.order.service.call.ConfigurableOrderItemRequest)

Aggregations

ProductBundle (org.broadleafcommerce.core.catalog.domain.ProductBundle)14 Product (org.broadleafcommerce.core.catalog.domain.Product)9 Sku (org.broadleafcommerce.core.catalog.domain.Sku)9 BundleOrderItem (org.broadleafcommerce.core.order.domain.BundleOrderItem)6 DiscreteOrderItem (org.broadleafcommerce.core.order.domain.DiscreteOrderItem)6 Category (org.broadleafcommerce.core.catalog.domain.Category)4 SkuBundleItem (org.broadleafcommerce.core.catalog.domain.SkuBundleItem)4 Order (org.broadleafcommerce.core.order.domain.Order)4 OrderItem (org.broadleafcommerce.core.order.domain.OrderItem)3 ServiceException (org.broadleafcommerce.common.exception.ServiceException)2 ExtensionResultStatusType (org.broadleafcommerce.common.extension.ExtensionResultStatusType)2 Money (org.broadleafcommerce.common.money.Money)2 CategoryProductXref (org.broadleafcommerce.core.catalog.domain.CategoryProductXref)2 DiscreteOrderItemRequest (org.broadleafcommerce.core.order.service.call.DiscreteOrderItemRequest)2 OrderItemRequestDTO (org.broadleafcommerce.core.order.service.call.OrderItemRequestDTO)2 BasicFieldMetadata (org.broadleafcommerce.openadmin.dto.BasicFieldMetadata)2 Entity (org.broadleafcommerce.openadmin.dto.Entity)2 FieldMetadata (org.broadleafcommerce.openadmin.dto.FieldMetadata)2 PersistencePerspective (org.broadleafcommerce.openadmin.dto.PersistencePerspective)2 Transactional (org.springframework.transaction.annotation.Transactional)2