Search in sources :

Example 1 with DynamicSkuPrices

use of org.broadleafcommerce.core.catalog.service.dynamic.DynamicSkuPrices in project BroadleafCommerce by BroadleafCommerce.

the class ProductOptionValueImpl method getPriceAdjustment.

@Override
public Money getPriceAdjustment() {
    Money returnPrice = null;
    if (SkuPricingConsiderationContext.hasDynamicPricing()) {
        DynamicSkuPrices dynamicPrices = SkuPricingConsiderationContext.getSkuPricingService().getPriceAdjustment(this, priceAdjustment == null ? null : new Money(priceAdjustment), SkuPricingConsiderationContext.getSkuPricingConsiderationContext());
        returnPrice = dynamicPrices.getPriceAdjustment();
    } else {
        if (priceAdjustment != null) {
            returnPrice = new Money(priceAdjustment, Money.defaultCurrency());
        }
    }
    return returnPrice;
}
Also used : Money(org.broadleafcommerce.common.money.Money) DynamicSkuPrices(org.broadleafcommerce.core.catalog.service.dynamic.DynamicSkuPrices)

Example 2 with DynamicSkuPrices

use of org.broadleafcommerce.core.catalog.service.dynamic.DynamicSkuPrices in project BroadleafCommerce by BroadleafCommerce.

the class SkuImpl method getPriceData.

@Override
public DynamicSkuPrices getPriceData() {
    if (SkuPricingConsiderationContext.hasDynamicPricing()) {
        DynamicSkuPrices dynamicPrices = SkuPricingConsiderationContext.getDynamicSkuPrices(this);
        return dynamicPrices;
    } else {
        DynamicSkuPrices dsp = new DynamicSkuPrices();
        BroadleafCurrency tmpCurrency;
        if (currency != null) {
            tmpCurrency = currency;
        } else {
            tmpCurrency = BroadleafRequestContext.getCurrency();
        }
        if (retailPrice != null) {
            dsp.setRetailPrice(new Money(retailPrice, tmpCurrency));
        }
        if (salePrice != null) {
            dsp.setSalePrice(new Money(salePrice, tmpCurrency));
        }
        return dsp;
    }
}
Also used : Money(org.broadleafcommerce.common.money.Money) BroadleafCurrency(org.broadleafcommerce.common.currency.domain.BroadleafCurrency) DynamicSkuPrices(org.broadleafcommerce.core.catalog.service.dynamic.DynamicSkuPrices) ClonePolicyCollectionOverride(org.broadleafcommerce.common.extensibility.jpa.clone.ClonePolicyCollectionOverride)

Example 3 with DynamicSkuPrices

use of org.broadleafcommerce.core.catalog.service.dynamic.DynamicSkuPrices 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 4 with DynamicSkuPrices

use of org.broadleafcommerce.core.catalog.service.dynamic.DynamicSkuPrices in project BroadleafCommerce by BroadleafCommerce.

the class DiscreteOrderItemImpl method updateSalePrice.

protected boolean updateSalePrice() {
    if (isSalePriceOverride()) {
        return false;
    }
    Money skuSalePrice = null;
    DynamicSkuPrices priceData = getSku().getPriceData();
    if (priceData != null) {
        skuSalePrice = priceData.getPriceForQuantity(quantity);
    }
    if (skuSalePrice == null) {
        skuSalePrice = getSku().getSalePrice();
    }
    // Override retail/sale prices from skuBundle.
    if (skuBundleItem != null) {
        if (skuBundleItem.getSalePrice() != null) {
            skuSalePrice = skuBundleItem.getSalePrice();
        }
    }
    boolean updated = false;
    // use the sku prices - the retail and sale prices could be null
    if (skuSalePrice != null && !skuSalePrice.getAmount().equals(salePrice)) {
        baseSalePrice = skuSalePrice.getAmount();
        salePrice = skuSalePrice.getAmount();
        updated = true;
    }
    // If there is no more sale price (because it got removed) then detect that case as well
    if (skuSalePrice == null && salePrice != null) {
        baseSalePrice = null;
        salePrice = null;
        updated = true;
    }
    // Adjust prices by adding in fees if they are attached.
    if (getDiscreteOrderItemFeePrices() != null) {
        for (DiscreteOrderItemFeePrice fee : getDiscreteOrderItemFeePrices()) {
            Money returnPrice = convertToMoney(salePrice);
            if (returnPrice != null) {
                salePrice = returnPrice.add(fee.getAmount()).getAmount();
            }
        }
    }
    return updated;
}
Also used : Money(org.broadleafcommerce.common.money.Money) DynamicSkuPrices(org.broadleafcommerce.core.catalog.service.dynamic.DynamicSkuPrices)

Example 5 with DynamicSkuPrices

use of org.broadleafcommerce.core.catalog.service.dynamic.DynamicSkuPrices in project BroadleafCommerce by BroadleafCommerce.

the class SkuImpl method getSalePrice.

@Override
public Money getSalePrice() {
    Money returnPrice = null;
    Money optionValueAdjustments = null;
    if (SkuPricingConsiderationContext.hasDynamicPricing()) {
        // We have dynamic pricing, so we will pull the sale price from there
        DynamicSkuPrices dynamicPrices = SkuPricingConsiderationContext.getDynamicSkuPrices(this);
        returnPrice = dynamicPrices.getSalePrice();
        optionValueAdjustments = dynamicPrices.getPriceAdjustment();
        if (SkuPricingConsiderationContext.isPricingConsiderationActive()) {
            return returnPrice;
        }
    } else if (salePrice != null) {
        // We have an explicitly set sale price directly on this entity. We will not apply any adjustments
        returnPrice = new Money(salePrice, getCurrency());
    }
    if (returnPrice == null && hasDefaultSku()) {
        returnPrice = lookupDefaultSku().getSalePrice();
        optionValueAdjustments = getProductOptionValueAdjustments();
    }
    if (returnPrice == null) {
        return null;
    }
    if (optionValueAdjustments != null) {
        returnPrice = returnPrice.add(optionValueAdjustments);
    }
    return returnPrice;
}
Also used : Money(org.broadleafcommerce.common.money.Money) DynamicSkuPrices(org.broadleafcommerce.core.catalog.service.dynamic.DynamicSkuPrices) ClonePolicyCollectionOverride(org.broadleafcommerce.common.extensibility.jpa.clone.ClonePolicyCollectionOverride)

Aggregations

DynamicSkuPrices (org.broadleafcommerce.core.catalog.service.dynamic.DynamicSkuPrices)6 Money (org.broadleafcommerce.common.money.Money)5 ClonePolicyCollectionOverride (org.broadleafcommerce.common.extensibility.jpa.clone.ClonePolicyCollectionOverride)2 BroadleafCurrency (org.broadleafcommerce.common.currency.domain.BroadleafCurrency)1 SkuPriceWrapper (org.broadleafcommerce.core.catalog.domain.pricing.SkuPriceWrapper)1 DiscreteOrderItem (org.broadleafcommerce.core.order.domain.DiscreteOrderItem)1 DiscreteOrderItemFeePrice (org.broadleafcommerce.core.order.domain.DiscreteOrderItemFeePrice)1