use of org.broadleafcommerce.core.order.domain.OrderItemPriceDetail in project BroadleafCommerce by BroadleafCommerce.
the class CandidateItemOfferTest method setUp.
@Override
protected void setUp() throws Exception {
OfferDataItemProvider dataProvider = new OfferDataItemProvider();
CandidateItemOfferImpl candidate = new CandidateItemOfferImpl();
Category category1 = new CategoryImpl();
category1.setName("test1");
category1.setId(1L);
Product product1 = new ProductImpl();
Sku sku1 = new SkuImpl();
sku1.setName("test1");
sku1.setDiscountable(true);
sku1.setRetailPrice(new Money(19.99D));
product1.setDefaultSku(sku1);
CategoryProductXref xref1 = new CategoryProductXrefImpl();
xref1.setProduct(product1);
xref1.setCategory(category1);
category1.getAllProductXrefs().add(xref1);
Category category2 = new CategoryImpl();
category2.setName("test2");
category2.setId(2L);
Product product2 = new ProductImpl();
Sku sku2 = new SkuImpl();
sku2.setName("test2");
sku2.setDiscountable(true);
sku2.setRetailPrice(new Money(29.99D));
product2.setDefaultSku(sku2);
CategoryProductXref xref2 = new CategoryProductXrefImpl();
xref2.setProduct(product2);
xref2.setCategory(category2);
category2.getAllProductXrefs().add(xref2);
DiscreteOrderItemImpl orderItem1 = new DiscreteOrderItemImpl();
orderItem1.setCategory(category1);
orderItem1.setName("test1");
orderItem1.setOrderItemType(OrderItemType.DISCRETE);
orderItem1.setProduct(product1);
orderItem1.setQuantity(2);
orderItem1.setSku(sku1);
Order order = new OrderImpl();
orderItem1.setOrder(order);
promotableOrder = new PromotableOrderImpl(order, new PromotableItemFactoryImpl(), false);
offer = dataProvider.createItemBasedOfferWithItemCriteria("order.subTotal.getAmount()>20", OfferDiscountType.PERCENT_OFF, "([MVEL.eval(\"toUpperCase()\",\"test1\"), MVEL.eval(\"toUpperCase()\",\"test2\")] contains MVEL.eval(\"toUpperCase()\", discreteOrderItem.category.name))", "([MVEL.eval(\"toUpperCase()\",\"test1\"), MVEL.eval(\"toUpperCase()\",\"test2\")] contains MVEL.eval(\"toUpperCase()\", discreteOrderItem.category.name))").get(0);
candidateOffer = new PromotableCandidateItemOfferImpl(promotableOrder, offer);
promotableOrderItem = new PromotableOrderItemImpl(orderItem1, null, new PromotableItemFactoryImpl(), false);
OrderItemPriceDetail pdetail = new OrderItemPriceDetailImpl();
pdetail.setOrderItem(orderItem1);
pdetail.setQuantity(2);
priceDetail = new PromotableOrderItemPriceDetailImpl(promotableOrderItem, 2);
List<PromotableOrderItem> items = new ArrayList<PromotableOrderItem>();
items.add(promotableOrderItem);
promotableCandidate = new PromotableCandidateItemOfferImpl(promotableOrder, offer);
OfferTargetCriteriaXref xref = offer.getTargetItemCriteriaXref().iterator().next();
promotableCandidate.getCandidateTargetsMap().put(xref.getOfferItemCriteria(), items);
}
use of org.broadleafcommerce.core.order.domain.OrderItemPriceDetail in project BroadleafCommerce by BroadleafCommerce.
the class OrderOfferProcessorImpl method synchronizeItemPriceDetails.
protected void synchronizeItemPriceDetails(OrderItem orderItem, PromotableOrderItem promotableOrderItem) {
Map<String, PromotableOrderItemPriceDetail> promotableDetailsMap = buildPromotableDetailsMap(promotableOrderItem);
Map<Long, OrderItemPriceDetail> unmatchedDetailsMap = new HashMap<Long, OrderItemPriceDetail>();
for (OrderItemPriceDetail orderItemPriceDetail : orderItem.getOrderItemPriceDetails()) {
String detailKey = buildItemPriceDetailKey(orderItemPriceDetail);
PromotableOrderItemPriceDetail promotableDetail = promotableDetailsMap.remove(detailKey);
if (promotableDetail != null) {
processMatchingDetails(orderItemPriceDetail, promotableDetail);
} else {
unmatchedDetailsMap.put(orderItemPriceDetail.getId(), orderItemPriceDetail);
}
}
Iterator<OrderItemPriceDetail> unmatchedDetailsIterator = unmatchedDetailsMap.values().iterator();
for (PromotableOrderItemPriceDetail priceDetail : promotableDetailsMap.values()) {
if (unmatchedDetailsIterator.hasNext()) {
// Reuse an existing priceDetail
OrderItemPriceDetail existingDetail = unmatchedDetailsIterator.next();
// Reset use Sale flag to true
existingDetail.setUseSalePrice(true);
offerServiceUtilities.updatePriceDetail(existingDetail, priceDetail);
unmatchedDetailsIterator.remove();
} else {
// Create a new priceDetail
OrderItemPriceDetail newPriceDetail = orderItemDao.createOrderItemPriceDetail();
newPriceDetail.setOrderItem(orderItem);
offerServiceUtilities.updatePriceDetail(newPriceDetail, priceDetail);
orderItem.getOrderItemPriceDetails().add(newPriceDetail);
}
}
// Remove any unmatched details
Iterator<OrderItemPriceDetail> pdIterator = orderItem.getOrderItemPriceDetails().iterator();
offerServiceUtilities.removeUnmatchedPriceDetails(unmatchedDetailsMap, pdIterator);
}
use of org.broadleafcommerce.core.order.domain.OrderItemPriceDetail in project BroadleafCommerce by BroadleafCommerce.
the class PromotableOrderItemImpl method initializePriceDetails.
protected void initializePriceDetails() {
if (includeAdjustments) {
for (OrderItemPriceDetail detail : orderItem.getOrderItemPriceDetails()) {
PromotableOrderItemPriceDetail poid = itemFactory.createPromotableOrderItemPriceDetail(this, detail.getQuantity());
itemPriceDetails.add(poid);
for (OrderItemPriceDetailAdjustment adjustment : detail.getOrderItemPriceDetailAdjustments()) {
PromotableOrderItemPriceDetailAdjustment poidAdj = new PromotableOrderItemPriceDetailAdjustmentImpl(adjustment, poid);
poid.addCandidateItemPriceDetailAdjustment(poidAdj);
}
poid.chooseSaleOrRetailAdjustments();
List<OrderItemQualifier> oiqs = poid.getPromotableOrderItem().getOrderItem().getOrderItemQualifiers();
if (CollectionUtils.isNotEmpty(oiqs)) {
for (OrderItemQualifier oiq : oiqs) {
PromotionQualifier pq = new PromotionQualifier();
pq.setPromotion(oiq.getOffer());
pq.setQuantity(oiq.getQuantity().intValue());
pq.setFinalizedQuantity(oiq.getQuantity().intValue());
pq.setPrice(oiq.getOrderItem().getPriceBeforeAdjustments(oiq.getOffer().getApplyDiscountToSalePrice()));
poid.getPromotionQualifiers().add(pq);
}
}
}
} else {
PromotableOrderItemPriceDetail poid = itemFactory.createPromotableOrderItemPriceDetail(this, orderItem.getQuantity());
itemPriceDetails.add(poid);
}
}
use of org.broadleafcommerce.core.order.domain.OrderItemPriceDetail in project BroadleafCommerce by BroadleafCommerce.
the class OrderItemDaoImpl method initializeOrderItemPriceDetails.
@Override
public OrderItemPriceDetail initializeOrderItemPriceDetails(OrderItem item) {
OrderItemPriceDetail detail = createOrderItemPriceDetail();
detail.setOrderItem(item);
detail.setQuantity(item.getQuantity());
detail.setUseSalePrice(item.getIsOnSale());
item.getOrderItemPriceDetails().add(detail);
return detail;
}
use of org.broadleafcommerce.core.order.domain.OrderItemPriceDetail in project BroadleafCommerce by BroadleafCommerce.
the class OfferServiceImpl method getUniqueOffersFromOrder.
@Override
@SuppressWarnings("unchecked")
public Set<Offer> getUniqueOffersFromOrder(Order order) {
HashSet<Offer> result = new HashSet<Offer>();
Transformer adjustmentToOfferTransformer = new Transformer() {
@Override
public Object transform(Object input) {
return ((Adjustment) input).getOffer();
}
};
result.addAll(CollectionUtils.collect(order.getOrderAdjustments(), adjustmentToOfferTransformer));
if (order.getOrderItems() != null) {
for (OrderItem item : order.getOrderItems()) {
result.addAll(CollectionUtils.collect(item.getOrderItemAdjustments(), adjustmentToOfferTransformer));
// record usage for price details on the item as well
if (item.getOrderItemPriceDetails() != null) {
for (OrderItemPriceDetail detail : item.getOrderItemPriceDetails()) {
result.addAll(CollectionUtils.collect(detail.getOrderItemPriceDetailAdjustments(), adjustmentToOfferTransformer));
}
}
}
}
if (order.getFulfillmentGroups() != null) {
for (FulfillmentGroup fg : order.getFulfillmentGroups()) {
result.addAll(CollectionUtils.collect(fg.getFulfillmentGroupAdjustments(), adjustmentToOfferTransformer));
}
}
return result;
}
Aggregations