[Resolved]Please help on custom pricing
Posted: Wed Dec 26, 2012 5:19 am
Try to implement pricing activity for deal order as the price is based on some simple rules depending on the order info applying to all customers. I thought I can simply create an offer and an order item adjustment for the discount. But it seems not working. It throws following exception:
I guess the way to create offer and adjustment may be incorrect. Here are the code snippet:
PriceDealOrderActivity
DealOrderPricingService
What's wrong with the code? How to create a price adjustment? Or is there are better approach such as Dynamic Pricing?
Thank you!
-Charlie
Code: Select all
avax.persistence.EntityNotFoundException: Unable to find org.broadleafcommerce.core.offer.domain.OrderItemAdjustmentImpl with id 351
I guess the way to create offer and adjustment may be incorrect. Here are the code snippet:
PriceDealOrderActivity
Code: Select all
public class PriceDealOrderActivity extends PriceOrderIfNecessaryActivity {
@Autowired
@Resource(name="dealOrderPricingService")
private DealOrderPricingService dealOrderService;
public ProcessContext execute(ProcessContext context) throws Exception {
CartOperationRequest request = ((CartOperationContext) context).getSeedData();
Order order = request.getOrder();
dealOrderPricingService.createAdjustmentAndUpdateOrderPrice(order, request.isPriceOrder());
request.setOrder(order);
return context;
}
}
DealOrderPricingService
Code: Select all
@Service("dealOrderService")
public class DealOrderPricingServiceImpl implements DealOrderService {
@Resource(name="blOfferDao")
private OfferDao offerDao;
@Resource(name = "blOrderService")
protected OrderService orderService;
@Autowired
@Resource(name="dealService")
private DealService dealService;
@Override
@Transactional("blTransactionManager")
public void createAdjustmentAndUpdateOrderPrice(Order order, boolean isPricingOrder) throws Exception {
List<OrderItem> orderItems = order.getOrderItems();
if (orderItems != null) {
for (OrderItem orderItem : orderItems) {
Long discount = dealService.getDiscount(orderItem);
if (discount != 0) {
List<OrderItemAdjustment> adjustments = orderItem.getOrderItemAdjustments();
if (adjustments == null) {
adjustments = new ArrayList<OrderItemAdjustment>();
}
if (adjustments.size() == 0) {
Offer offer = new OfferImpl();
offer.setName(orderItem.getDeal().getName());
offer.setValue(orderItem.getPrice().multiply(discount/100.0).getAmount());
offer.setType(OfferType.ORDER_ITEM);
offer.setDeliveryType(OfferDeliveryType.AUTOMATIC);
OrderItemAdjustment itemAdjustment = offerDao.createOrderItemAdjustment();
itemAdjustment.init(orderItem, offer, "Deal");
itemAdjustment.setRetailPriceValue(orderItem.getRetailPrice());
itemAdjustment.setSalesPriceValue(orderItem.getSalePrice());
itemAdjustment.setValue(orderItem.getPrice().multiply(discount/100.0));
adjustments.add(itemAdjustment);
orderItem.setOrderItemAdjustments(adjustments);
}
orderItem.updatePrices();
orderItem.assignFinalPrice();
}
}
}
order = orderService.save(order, isPricingOrder);
}
What's wrong with the code? How to create a price adjustment? Or is there are better approach such as Dynamic Pricing?
Thank you!
-Charlie