Search in sources :

Example 76 with OrderItem

use of org.broadleafcommerce.core.order.domain.OrderItem in project BroadleafCommerce by BroadleafCommerce.

the class OfferServiceUtilitiesImpl method applyAdjustmentsForItemPriceDetails.

@Override
public void applyAdjustmentsForItemPriceDetails(PromotableCandidateItemOffer itemOffer, List<PromotableOrderItemPriceDetail> itemPriceDetails) {
    for (PromotableOrderItemPriceDetail itemPriceDetail : itemPriceDetails) {
        for (PromotionDiscount discount : itemPriceDetail.getPromotionDiscounts()) {
            if (discount.getPromotion().equals(itemOffer.getOffer())) {
                if (itemOffer.getOffer().isTotalitarianOffer() || !itemOffer.getOffer().isCombinableWithOtherOffers()) {
                    // the value of the item
                    if (adjustmentIsNotGoodEnoughToBeApplied(itemOffer, itemPriceDetail)) {
                        break;
                    }
                }
                OrderItem orderItem = itemPriceDetail.getPromotableOrderItem().getOrderItem();
                Boolean offerCanApplyToChildOrderItems = itemOffer.getOffer().getApplyToChildItems();
                if (isAddOnOrderItem(orderItem) && !offerCanApplyToChildOrderItems) {
                    break;
                }
                applyOrderItemAdjustment(itemOffer, itemPriceDetail);
                break;
            }
        }
    }
}
Also used : PromotableOrderItem(org.broadleafcommerce.core.offer.service.discount.domain.PromotableOrderItem) DiscreteOrderItem(org.broadleafcommerce.core.order.domain.DiscreteOrderItem) OrderItem(org.broadleafcommerce.core.order.domain.OrderItem) PromotionDiscount(org.broadleafcommerce.core.offer.service.discount.PromotionDiscount) PromotableOrderItemPriceDetail(org.broadleafcommerce.core.offer.service.discount.domain.PromotableOrderItemPriceDetail)

Example 77 with OrderItem

use of org.broadleafcommerce.core.order.domain.OrderItem in project BroadleafCommerce by BroadleafCommerce.

the class InventoryServiceImpl method buildSkuInventoryMap.

@Override
public Map<Sku, Integer> buildSkuInventoryMap(Order order) {
    // map to hold skus and quantity purchased
    HashMap<Sku, Integer> skuInventoryMap = new HashMap<Sku, Integer>();
    for (OrderItem orderItem : order.getOrderItems()) {
        if (orderItem instanceof DiscreteOrderItem) {
            Sku sku = ((DiscreteOrderItem) orderItem).getSku();
            Integer quantity = skuInventoryMap.get(sku);
            if (quantity == null) {
                quantity = orderItem.getQuantity();
            } else {
                quantity += orderItem.getQuantity();
            }
            if (InventoryType.CHECK_QUANTITY.equals(sku.getInventoryType())) {
                skuInventoryMap.put(sku, quantity);
            }
        } else if (orderItem instanceof BundleOrderItem) {
            BundleOrderItem bundleItem = (BundleOrderItem) orderItem;
            if (InventoryType.CHECK_QUANTITY.equals(bundleItem.getSku().getInventoryType())) {
                // add the bundle sku of quantities to decrement
                skuInventoryMap.put(bundleItem.getSku(), bundleItem.getQuantity());
            }
            // Now add all of the discrete items within the bundl
            List<DiscreteOrderItem> discreteItems = bundleItem.getDiscreteOrderItems();
            for (DiscreteOrderItem discreteItem : discreteItems) {
                if (InventoryType.CHECK_QUANTITY.equals(discreteItem.getSku().getInventoryType())) {
                    Integer quantity = skuInventoryMap.get(discreteItem.getSku());
                    if (quantity == null) {
                        quantity = (discreteItem.getQuantity() * bundleItem.getQuantity());
                    } else {
                        quantity += (discreteItem.getQuantity() * bundleItem.getQuantity());
                    }
                    skuInventoryMap.put(discreteItem.getSku(), quantity);
                }
            }
        }
    }
    return skuInventoryMap;
}
Also used : DiscreteOrderItem(org.broadleafcommerce.core.order.domain.DiscreteOrderItem) BundleOrderItem(org.broadleafcommerce.core.order.domain.BundleOrderItem) HashMap(java.util.HashMap) DiscreteOrderItem(org.broadleafcommerce.core.order.domain.DiscreteOrderItem) OrderItem(org.broadleafcommerce.core.order.domain.OrderItem) BundleOrderItem(org.broadleafcommerce.core.order.domain.BundleOrderItem) List(java.util.List) Sku(org.broadleafcommerce.core.catalog.domain.Sku)

Example 78 with OrderItem

use of org.broadleafcommerce.core.order.domain.OrderItem in project BroadleafCommerce by BroadleafCommerce.

the class FulfillmentGroupOfferProcessorTest method testApplyAllFulfillmentGroupOffersWithOrderItemOffers.

public void testApplyAllFulfillmentGroupOffersWithOrderItemOffers() throws Exception {
    final ThreadLocal<Order> myOrder = new ThreadLocal<Order>();
    EasyMock.expect(orderItemDaoMock.createOrderItemPriceDetail()).andAnswer(OfferDataItemProvider.getCreateOrderItemPriceDetailAnswer()).anyTimes();
    EasyMock.expect(orderItemDaoMock.createOrderItemQualifier()).andAnswer(OfferDataItemProvider.getCreateOrderItemQualifierAnswer()).atLeastOnce();
    EasyMock.expect(fgServiceMock.addItemToFulfillmentGroup(EasyMock.isA(FulfillmentGroupItemRequest.class), EasyMock.eq(false))).andAnswer(OfferDataItemProvider.getAddItemToFulfillmentGroupAnswer()).anyTimes();
    EasyMock.expect(orderServiceMock.removeItem(EasyMock.isA(Long.class), EasyMock.isA(Long.class), EasyMock.eq(false))).andAnswer(OfferDataItemProvider.getRemoveItemFromOrderAnswer()).anyTimes();
    EasyMock.expect(orderServiceMock.save(EasyMock.isA(Order.class), EasyMock.isA(Boolean.class))).andAnswer(OfferDataItemProvider.getSaveOrderAnswer()).anyTimes();
    EasyMock.expect(offerServiceUtilitiesMock.orderMeetsQualifyingSubtotalRequirements(EasyMock.isA(PromotableOrder.class), EasyMock.isA(Offer.class), EasyMock.isA(HashMap.class))).andReturn(true).anyTimes();
    EasyMock.expect(offerServiceUtilitiesMock.orderMeetsSubtotalRequirements(EasyMock.isA(PromotableOrder.class), EasyMock.isA(Offer.class))).andReturn(true).anyTimes();
    EasyMock.expect(orderServiceMock.getAutomaticallyMergeLikeItems()).andReturn(true).anyTimes();
    EasyMock.expect(orderItemServiceMock.saveOrderItem(EasyMock.isA(OrderItem.class))).andAnswer(OfferDataItemProvider.getSaveOrderItemAnswer()).anyTimes();
    EasyMock.expect(fgItemDaoMock.save(EasyMock.isA(FulfillmentGroupItem.class))).andAnswer(OfferDataItemProvider.getSaveFulfillmentGroupItemAnswer()).anyTimes();
    EasyMock.expect(offerDaoMock.createOrderItemPriceDetailAdjustment()).andAnswer(OfferDataItemProvider.getCreateOrderItemPriceDetailAdjustmentAnswer()).anyTimes();
    EasyMock.expect(offerDaoMock.createFulfillmentGroupAdjustment()).andAnswer(OfferDataItemProvider.getCreateFulfillmentGroupAdjustmentAnswer()).anyTimes();
    EasyMock.expect(orderServiceMock.findOrderById(EasyMock.isA(Long.class))).andAnswer(new IAnswer<Order>() {

        @Override
        public Order answer() throws Throwable {
            return myOrder.get();
        }
    }).anyTimes();
    EasyMock.expect(multishipOptionServiceMock.findOrderMultishipOptions(EasyMock.isA(Long.class))).andAnswer(new IAnswer<List<OrderMultishipOption>>() {

        @Override
        public List<OrderMultishipOption> answer() throws Throwable {
            List<OrderMultishipOption> options = new ArrayList<OrderMultishipOption>();
            PromotableOrder order = dataProvider.createBasicPromotableOrder();
            for (FulfillmentGroup fg : order.getOrder().getFulfillmentGroups()) {
                Address address = fg.getAddress();
                for (FulfillmentGroupItem fgItem : fg.getFulfillmentGroupItems()) {
                    for (int j = 0; j < fgItem.getQuantity(); j++) {
                        OrderMultishipOption option = new OrderMultishipOptionImpl();
                        option.setOrder(order.getOrder());
                        option.setAddress(address);
                        option.setOrderItem(fgItem.getOrderItem());
                        options.add(option);
                    }
                }
            }
            return options;
        }
    }).anyTimes();
    multishipOptionServiceMock.deleteAllOrderMultishipOptions(EasyMock.isA(Order.class));
    EasyMock.expectLastCall().anyTimes();
    EasyMock.expect(fgServiceMock.collapseToOneShippableFulfillmentGroup(EasyMock.isA(Order.class), EasyMock.eq(false))).andAnswer(new IAnswer<Order>() {

        @Override
        public Order answer() throws Throwable {
            Order order = (Order) EasyMock.getCurrentArguments()[0];
            order.getFulfillmentGroups().get(0).getFulfillmentGroupItems().addAll(order.getFulfillmentGroups().get(1).getFulfillmentGroupItems());
            order.getFulfillmentGroups().remove(order.getFulfillmentGroups().get(1));
            return order;
        }
    }).anyTimes();
    EasyMock.expect(fgItemDaoMock.create()).andAnswer(OfferDataItemProvider.getCreateFulfillmentGroupItemAnswer()).anyTimes();
    fgItemDaoMock.delete(EasyMock.isA(FulfillmentGroupItem.class));
    EasyMock.expectLastCall().anyTimes();
    EasyMock.expect(offerTimeZoneProcessorMock.getTimeZone(EasyMock.isA(OfferImpl.class))).andReturn(TimeZone.getTimeZone("CST")).anyTimes();
    replay();
    PromotableOrder promotableOrder = dataProvider.createBasicPromotableOrder();
    Order order = promotableOrder.getOrder();
    myOrder.set(promotableOrder.getOrder());
    List<PromotableCandidateFulfillmentGroupOffer> qualifiedOffers = new ArrayList<PromotableCandidateFulfillmentGroupOffer>();
    List<Offer> offers = dataProvider.createFGBasedOffer("order.subTotal.getAmount()>20", "fulfillmentGroup.address.postalCode==75244", OfferDiscountType.PERCENT_OFF);
    offers.addAll(dataProvider.createFGBasedOfferWithItemCriteria("order.subTotal.getAmount()>20", "fulfillmentGroup.address.postalCode==75244", OfferDiscountType.PERCENT_OFF, "([MVEL.eval(\"toUpperCase()\",\"test1\")] contains MVEL.eval(\"toUpperCase()\", discreteOrderItem.category.name))"));
    offers.get(1).setName("secondOffer");
    offers.addAll(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))"));
    offerService.applyAndSaveOffersToOrder(offers, promotableOrder.getOrder());
    offers.get(0).setTotalitarianOffer(true);
    offerService.applyAndSaveFulfillmentGroupOffersToOrder(offers, promotableOrder.getOrder());
    int fgAdjustmentCount = 0;
    for (FulfillmentGroup fg : order.getFulfillmentGroups()) {
        fgAdjustmentCount += fg.getFulfillmentGroupAdjustments().size();
    }
    // The totalitarian offer that applies to both fg's is not combinable and is a worse offer than the order item offers
    // - it is therefore ignored
    // However, the second combinable fg offer is allowed to be applied.
    assertTrue(fgAdjustmentCount == 1);
    promotableOrder = dataProvider.createBasicPromotableOrder();
    myOrder.set(promotableOrder.getOrder());
    offers.get(2).setValue(new BigDecimal("1"));
    offerService.applyAndSaveOffersToOrder(offers, promotableOrder.getOrder());
    offerService.applyAndSaveFulfillmentGroupOffersToOrder(offers, promotableOrder.getOrder());
    fgAdjustmentCount = 0;
    order = promotableOrder.getOrder();
    for (FulfillmentGroup fg : order.getFulfillmentGroups()) {
        fgAdjustmentCount += fg.getFulfillmentGroupAdjustments().size();
    }
    // The totalitarian fg offer is now a better deal than the order item offers, therefore the totalitarian fg offer is applied
    // and the order item offers are removed
    assertTrue(fgAdjustmentCount == 2);
    int itemAdjustmentCount = 0;
    for (OrderItem item : order.getOrderItems()) {
        for (OrderItemPriceDetail detail : item.getOrderItemPriceDetails()) {
            itemAdjustmentCount += detail.getOrderItemPriceDetailAdjustments().size();
        }
    }
    // Confirm that the order item offers are removed
    assertTrue(itemAdjustmentCount == 0);
    verify();
}
Also used : PromotableOrder(org.broadleafcommerce.core.offer.service.discount.domain.PromotableOrder) Order(org.broadleafcommerce.core.order.domain.Order) Address(org.broadleafcommerce.profile.core.domain.Address) OrderMultishipOptionImpl(org.broadleafcommerce.core.order.domain.OrderMultishipOptionImpl) ArrayList(java.util.ArrayList) PromotableOrder(org.broadleafcommerce.core.offer.service.discount.domain.PromotableOrder) BigDecimal(java.math.BigDecimal) IAnswer(org.easymock.IAnswer) CandidateFulfillmentGroupOffer(org.broadleafcommerce.core.offer.domain.CandidateFulfillmentGroupOffer) PromotableCandidateFulfillmentGroupOffer(org.broadleafcommerce.core.offer.service.discount.domain.PromotableCandidateFulfillmentGroupOffer) CandidateItemOffer(org.broadleafcommerce.core.offer.domain.CandidateItemOffer) Offer(org.broadleafcommerce.core.offer.domain.Offer) FulfillmentGroupItem(org.broadleafcommerce.core.order.domain.FulfillmentGroupItem) PromotableOrderItem(org.broadleafcommerce.core.offer.service.discount.domain.PromotableOrderItem) OrderItem(org.broadleafcommerce.core.order.domain.OrderItem) OrderMultishipOption(org.broadleafcommerce.core.order.domain.OrderMultishipOption) FulfillmentGroup(org.broadleafcommerce.core.order.domain.FulfillmentGroup) PromotableFulfillmentGroup(org.broadleafcommerce.core.offer.service.discount.domain.PromotableFulfillmentGroup) PromotableCandidateFulfillmentGroupOffer(org.broadleafcommerce.core.offer.service.discount.domain.PromotableCandidateFulfillmentGroupOffer) OrderItemPriceDetail(org.broadleafcommerce.core.order.domain.OrderItemPriceDetail)

Example 79 with OrderItem

use of org.broadleafcommerce.core.order.domain.OrderItem in project BroadleafCommerce by BroadleafCommerce.

the class FulfillmentItemPricingActivityTest method testBundleDistributionWithoutItemSum.

public void testBundleDistributionWithoutItemSum() throws Exception {
    Order order = dataProvider.createOrderWithBundle();
    Money subTotal = new Money(order.getCurrency());
    for (OrderItem orderItem : order.getOrderItems()) {
        if (orderItem instanceof BundleOrderItem) {
            BundleOrderItem bItem = (BundleOrderItem) orderItem;
            bItem.getProductBundle().setPricingModel(ProductBundlePricingModelType.BUNDLE);
        }
        subTotal = subTotal.add(orderItem.getTotalPrice());
    }
    order.setSubTotal(subTotal);
    OrderAdjustment adjustment = new OrderAdjustmentImpl();
    adjustment.setValue(new Money(new BigDecimal("1"), order.getCurrency()));
    adjustment.setOrder(order);
    order.getOrderAdjustments().add(adjustment);
    ProcessContext<Order> context = new DefaultProcessContextImpl<Order>();
    context.setSeedData(order);
    fulfillmentItemPricingActivity.execute(context);
    assertTrue(sumProratedOfferAdjustments(order).equals(new Money(new BigDecimal("1"), order.getCurrency())));
}
Also used : Order(org.broadleafcommerce.core.order.domain.Order) Money(org.broadleafcommerce.common.money.Money) OrderAdjustmentImpl(org.broadleafcommerce.core.offer.domain.OrderAdjustmentImpl) BundleOrderItem(org.broadleafcommerce.core.order.domain.BundleOrderItem) OrderAdjustment(org.broadleafcommerce.core.offer.domain.OrderAdjustment) DefaultProcessContextImpl(org.broadleafcommerce.core.workflow.DefaultProcessContextImpl) OrderItem(org.broadleafcommerce.core.order.domain.OrderItem) BundleOrderItem(org.broadleafcommerce.core.order.domain.BundleOrderItem) BigDecimal(java.math.BigDecimal)

Example 80 with OrderItem

use of org.broadleafcommerce.core.order.domain.OrderItem in project BroadleafCommerce by BroadleafCommerce.

the class FulfillmentItemPricingActivityTest method testRoundingRequired.

public void testRoundingRequired() throws Exception {
    Order order = dataProvider.createBasicOrder();
    Money subTotal = new Money(order.getCurrency());
    for (OrderItem orderItem : order.getOrderItems()) {
        orderItem.getOrderItemPriceDetails().clear();
        orderItem.setQuantity(2);
        orderItem.setSalePrice(new Money(10D));
        subTotal = subTotal.add(orderItem.getTotalPrice());
    }
    order.setSubTotal(subTotal);
    OrderAdjustment adjustment = new OrderAdjustmentImpl();
    adjustment.setValue(new Money(new BigDecimal(".05"), order.getCurrency()));
    adjustment.setOrder(order);
    order.getOrderAdjustments().add(adjustment);
    ProcessContext<Order> context = new DefaultProcessContextImpl<Order>();
    context.setSeedData(order);
    fulfillmentItemPricingActivity.execute(context);
    assertTrue(sumProratedOfferAdjustments(order).equals(new Money(new BigDecimal(".05"), order.getCurrency())));
}
Also used : Order(org.broadleafcommerce.core.order.domain.Order) Money(org.broadleafcommerce.common.money.Money) OrderAdjustmentImpl(org.broadleafcommerce.core.offer.domain.OrderAdjustmentImpl) OrderAdjustment(org.broadleafcommerce.core.offer.domain.OrderAdjustment) DefaultProcessContextImpl(org.broadleafcommerce.core.workflow.DefaultProcessContextImpl) OrderItem(org.broadleafcommerce.core.order.domain.OrderItem) BundleOrderItem(org.broadleafcommerce.core.order.domain.BundleOrderItem) BigDecimal(java.math.BigDecimal)

Aggregations

OrderItem (org.broadleafcommerce.core.order.domain.OrderItem)100 DiscreteOrderItem (org.broadleafcommerce.core.order.domain.DiscreteOrderItem)69 BundleOrderItem (org.broadleafcommerce.core.order.domain.BundleOrderItem)54 Order (org.broadleafcommerce.core.order.domain.Order)46 ArrayList (java.util.ArrayList)32 GiftWrapOrderItem (org.broadleafcommerce.core.order.domain.GiftWrapOrderItem)23 FulfillmentGroupItem (org.broadleafcommerce.core.order.domain.FulfillmentGroupItem)20 FulfillmentGroup (org.broadleafcommerce.core.order.domain.FulfillmentGroup)19 Transactional (org.springframework.transaction.annotation.Transactional)19 Test (org.testng.annotations.Test)16 Money (org.broadleafcommerce.common.money.Money)13 OrderItemRequestDTO (org.broadleafcommerce.core.order.service.call.OrderItemRequestDTO)13 HashMap (java.util.HashMap)11 Sku (org.broadleafcommerce.core.catalog.domain.Sku)10 CartOperationRequest (org.broadleafcommerce.core.order.service.workflow.CartOperationRequest)9 PromotableOrderItem (org.broadleafcommerce.core.offer.service.discount.domain.PromotableOrderItem)7 BigDecimal (java.math.BigDecimal)5 ItemNotFoundException (org.broadleafcommerce.core.order.service.exception.ItemNotFoundException)5 List (java.util.List)4 Product (org.broadleafcommerce.core.catalog.domain.Product)4