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;
}
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;
}
}
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;
}
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;
}
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;
}
Aggregations