Search in sources :

Example 1 with OrderItemPriceDetail

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);
}
Also used : Category(org.broadleafcommerce.core.catalog.domain.Category) PromotableOrderImpl(org.broadleafcommerce.core.offer.service.discount.domain.PromotableOrderImpl) CategoryProductXref(org.broadleafcommerce.core.catalog.domain.CategoryProductXref) DiscreteOrderItemImpl(org.broadleafcommerce.core.order.domain.DiscreteOrderItemImpl) OrderItemPriceDetailImpl(org.broadleafcommerce.core.order.domain.OrderItemPriceDetailImpl) PromotableOrderItemPriceDetailImpl(org.broadleafcommerce.core.offer.service.discount.domain.PromotableOrderItemPriceDetailImpl) ArrayList(java.util.ArrayList) Product(org.broadleafcommerce.core.catalog.domain.Product) PromotableCandidateItemOfferImpl(org.broadleafcommerce.core.offer.service.discount.domain.PromotableCandidateItemOfferImpl) PromotableOrderItem(org.broadleafcommerce.core.offer.service.discount.domain.PromotableOrderItem) Money(org.broadleafcommerce.common.money.Money) PromotableItemFactoryImpl(org.broadleafcommerce.core.offer.service.discount.domain.PromotableItemFactoryImpl) CategoryProductXrefImpl(org.broadleafcommerce.core.catalog.domain.CategoryProductXrefImpl) PromotableOrder(org.broadleafcommerce.core.offer.service.discount.domain.PromotableOrder) Order(org.broadleafcommerce.core.order.domain.Order) PromotableOrderItemImpl(org.broadleafcommerce.core.offer.service.discount.domain.PromotableOrderItemImpl) CategoryImpl(org.broadleafcommerce.core.catalog.domain.CategoryImpl) SkuImpl(org.broadleafcommerce.core.catalog.domain.SkuImpl) ProductImpl(org.broadleafcommerce.core.catalog.domain.ProductImpl) PromotableOrderImpl(org.broadleafcommerce.core.offer.service.discount.domain.PromotableOrderImpl) OrderImpl(org.broadleafcommerce.core.order.domain.OrderImpl) PromotableCandidateItemOfferImpl(org.broadleafcommerce.core.offer.service.discount.domain.PromotableCandidateItemOfferImpl) OfferDataItemProvider(org.broadleafcommerce.core.offer.service.OfferDataItemProvider) OrderItemPriceDetail(org.broadleafcommerce.core.order.domain.OrderItemPriceDetail) PromotableOrderItemPriceDetail(org.broadleafcommerce.core.offer.service.discount.domain.PromotableOrderItemPriceDetail) Sku(org.broadleafcommerce.core.catalog.domain.Sku) PromotableOrderItemPriceDetailImpl(org.broadleafcommerce.core.offer.service.discount.domain.PromotableOrderItemPriceDetailImpl)

Example 2 with OrderItemPriceDetail

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);
}
Also used : HashMap(java.util.HashMap) OrderItemPriceDetail(org.broadleafcommerce.core.order.domain.OrderItemPriceDetail) PromotableOrderItemPriceDetail(org.broadleafcommerce.core.offer.service.discount.domain.PromotableOrderItemPriceDetail) PromotableOrderItemPriceDetail(org.broadleafcommerce.core.offer.service.discount.domain.PromotableOrderItemPriceDetail)

Example 3 with OrderItemPriceDetail

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);
    }
}
Also used : PromotionQualifier(org.broadleafcommerce.core.offer.service.discount.PromotionQualifier) OrderItemPriceDetail(org.broadleafcommerce.core.order.domain.OrderItemPriceDetail) OrderItemQualifier(org.broadleafcommerce.core.order.domain.OrderItemQualifier) OrderItemPriceDetailAdjustment(org.broadleafcommerce.core.offer.domain.OrderItemPriceDetailAdjustment)

Example 4 with OrderItemPriceDetail

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;
}
Also used : OrderItemPriceDetail(org.broadleafcommerce.core.order.domain.OrderItemPriceDetail)

Example 5 with OrderItemPriceDetail

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;
}
Also used : Transformer(org.apache.commons.collections.Transformer) OrderItemPriceDetailAdjustment(org.broadleafcommerce.core.offer.domain.OrderItemPriceDetailAdjustment) Adjustment(org.broadleafcommerce.core.offer.domain.Adjustment) PromotableCandidateItemOffer(org.broadleafcommerce.core.offer.service.discount.domain.PromotableCandidateItemOffer) PromotableCandidateFulfillmentGroupOffer(org.broadleafcommerce.core.offer.service.discount.domain.PromotableCandidateFulfillmentGroupOffer) PromotableCandidateOrderOffer(org.broadleafcommerce.core.offer.service.discount.domain.PromotableCandidateOrderOffer) CustomerOffer(org.broadleafcommerce.core.offer.domain.CustomerOffer) Offer(org.broadleafcommerce.core.offer.domain.Offer) OrderItem(org.broadleafcommerce.core.order.domain.OrderItem) FulfillmentGroup(org.broadleafcommerce.core.order.domain.FulfillmentGroup) OrderItemPriceDetail(org.broadleafcommerce.core.order.domain.OrderItemPriceDetail) HashSet(java.util.HashSet)

Aggregations

OrderItemPriceDetail (org.broadleafcommerce.core.order.domain.OrderItemPriceDetail)9 PromotableOrder (org.broadleafcommerce.core.offer.service.discount.domain.PromotableOrder)4 FulfillmentGroup (org.broadleafcommerce.core.order.domain.FulfillmentGroup)4 Order (org.broadleafcommerce.core.order.domain.Order)4 ArrayList (java.util.ArrayList)3 Money (org.broadleafcommerce.common.money.Money)3 Category (org.broadleafcommerce.core.catalog.domain.Category)3 CategoryImpl (org.broadleafcommerce.core.catalog.domain.CategoryImpl)3 CategoryProductXref (org.broadleafcommerce.core.catalog.domain.CategoryProductXref)3 CategoryProductXrefImpl (org.broadleafcommerce.core.catalog.domain.CategoryProductXrefImpl)3 Product (org.broadleafcommerce.core.catalog.domain.Product)3 ProductImpl (org.broadleafcommerce.core.catalog.domain.ProductImpl)3 Sku (org.broadleafcommerce.core.catalog.domain.Sku)3 SkuImpl (org.broadleafcommerce.core.catalog.domain.SkuImpl)3 OrderItemPriceDetailAdjustment (org.broadleafcommerce.core.offer.domain.OrderItemPriceDetailAdjustment)3 PromotableOrderImpl (org.broadleafcommerce.core.offer.service.discount.domain.PromotableOrderImpl)3 DiscreteOrderItemImpl (org.broadleafcommerce.core.order.domain.DiscreteOrderItemImpl)3 FulfillmentGroupItem (org.broadleafcommerce.core.order.domain.FulfillmentGroupItem)3 OrderImpl (org.broadleafcommerce.core.order.domain.OrderImpl)3 OrderItem (org.broadleafcommerce.core.order.domain.OrderItem)3