Search in sources :

Example 1 with SkuPriceWrapper

use of org.broadleafcommerce.core.catalog.domain.pricing.SkuPriceWrapper in project BroadleafCommerce by BroadleafCommerce.

the class OrderItemServiceImpl method createDynamicPriceDiscreteOrderItem.

@Override
public DiscreteOrderItem createDynamicPriceDiscreteOrderItem(final DiscreteOrderItemRequest itemRequest, @SuppressWarnings("rawtypes") HashMap skuPricingConsiderations) {
    final DiscreteOrderItem item = (DiscreteOrderItem) orderItemDao.create(OrderItemType.EXTERNALLY_PRICED);
    populateDiscreteOrderItem(item, itemRequest);
    SkuPriceWrapper wrapper = new SkuPriceWrapper(itemRequest.getSku());
    DynamicSkuPrices prices = dynamicSkuPricingService.getSkuPrices(wrapper, skuPricingConsiderations);
    item.setBundleOrderItem(itemRequest.getBundleOrderItem());
    item.setBaseRetailPrice(prices.getRetailPrice());
    item.setBaseSalePrice(prices.getSalePrice());
    item.setSalePrice(prices.getSalePrice());
    item.setRetailPrice(prices.getRetailPrice());
    if (itemRequest.getSalePriceOverride() != null) {
        item.setSalePriceOverride(Boolean.TRUE);
        item.setSalePrice(itemRequest.getSalePriceOverride());
        item.setBaseSalePrice(itemRequest.getSalePriceOverride());
    }
    if (itemRequest.getRetailPriceOverride() != null) {
        item.setRetailPriceOverride(Boolean.TRUE);
        item.setRetailPrice(itemRequest.getRetailPriceOverride());
        item.setBaseRetailPrice(itemRequest.getRetailPriceOverride());
    }
    item.setDiscreteOrderItemFeePrices(itemRequest.getDiscreteOrderItemFeePrices());
    for (DiscreteOrderItemFeePrice fee : itemRequest.getDiscreteOrderItemFeePrices()) {
        item.setSalePrice(item.getSalePrice().add(fee.getAmount()));
        item.setRetailPrice(item.getRetailPrice().add(fee.getAmount()));
    }
    item.setPersonalMessage(itemRequest.getPersonalMessage());
    applyAdditionalOrderItemProperties(item);
    return item;
}
Also used : DiscreteOrderItem(org.broadleafcommerce.core.order.domain.DiscreteOrderItem) SkuPriceWrapper(org.broadleafcommerce.core.catalog.domain.pricing.SkuPriceWrapper) DynamicSkuPrices(org.broadleafcommerce.core.catalog.service.dynamic.DynamicSkuPrices) DiscreteOrderItemFeePrice(org.broadleafcommerce.core.order.domain.DiscreteOrderItemFeePrice)

Example 2 with SkuPriceWrapper

use of org.broadleafcommerce.core.catalog.domain.pricing.SkuPriceWrapper in project BroadleafCommerce by BroadleafCommerce.

the class SkuPricingConsiderationContext method getDynamicSkuPrices.

public static DynamicSkuPrices getDynamicSkuPrices(Sku sku) {
    DynamicSkuPrices prices = null;
    if (SkuPricingConsiderationContext.hasDynamicPricing()) {
        if (!getThreadCache().containsKey(sku.getId())) {
            // We have dynamic pricing, so we will pull the retail price from there
            if (!SkuPricingConsiderationContext.isPricingConsiderationActive()) {
                SkuPriceWrapper wrapper = new SkuPriceWrapper(sku);
                SkuPricingConsiderationContext.startPricingConsideration();
                try {
                    prices = SkuPricingConsiderationContext.getSkuPricingService().getSkuPrices(wrapper, SkuPricingConsiderationContext.getSkuPricingConsiderationContext());
                } finally {
                    SkuPricingConsiderationContext.endPricingConsideration();
                }
            } else {
                try {
                    prices = new DynamicSkuPrices();
                    Field retail = getSingleField(sku.getClass(), "retailPrice");
                    Object retailVal = retail.get(sku);
                    Money retailPrice = retailVal == null ? null : new Money((BigDecimal) retailVal);
                    Field sale = getSingleField(sku.getClass(), "salePrice");
                    Object saleVal = sale.get(sku);
                    Money salePrice = saleVal == null ? null : new Money((BigDecimal) saleVal);
                    prices.setRetailPrice(retailPrice);
                    prices.setSalePrice(salePrice);
                } catch (IllegalAccessException e) {
                    throw ExceptionHelper.refineException(e);
                }
            }
            getThreadCache().put(sku.getId(), prices);
        } else {
            prices = getThreadCache().get(sku.getId());
        }
    }
    return prices;
}
Also used : Field(java.lang.reflect.Field) Money(org.broadleafcommerce.common.money.Money) SkuPriceWrapper(org.broadleafcommerce.core.catalog.domain.pricing.SkuPriceWrapper) BigDecimal(java.math.BigDecimal)

Aggregations

SkuPriceWrapper (org.broadleafcommerce.core.catalog.domain.pricing.SkuPriceWrapper)2 Field (java.lang.reflect.Field)1 BigDecimal (java.math.BigDecimal)1 Money (org.broadleafcommerce.common.money.Money)1 DynamicSkuPrices (org.broadleafcommerce.core.catalog.service.dynamic.DynamicSkuPrices)1 DiscreteOrderItem (org.broadleafcommerce.core.order.domain.DiscreteOrderItem)1 DiscreteOrderItemFeePrice (org.broadleafcommerce.core.order.domain.DiscreteOrderItemFeePrice)1