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