Search in sources :

Example 1 with OrderItem

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

the class OfferDataItemProvider method getRemoveItemFromOrderAnswer.

public static IAnswer<Order> getRemoveItemFromOrderAnswer() {
    return new IAnswer<Order>() {

        @Override
        public Order answer() throws Throwable {
            Long orderId = (Long) EasyMock.getCurrentArguments()[0];
            Order order = orders.get(orderId);
            Iterator<OrderItem> orderItemItr = order.getOrderItems().listIterator();
            while (orderItemItr.hasNext()) {
                OrderItem item = orderItemItr.next();
                if (item.getId().equals(EasyMock.getCurrentArguments()[1])) {
                    orderItemItr.remove();
                }
            }
            for (FulfillmentGroup fg : order.getFulfillmentGroups()) {
                Iterator<FulfillmentGroupItem> itr = fg.getFulfillmentGroupItems().iterator();
                while (itr.hasNext()) {
                    if (itr.next().getOrderItem().getId().equals(EasyMock.getCurrentArguments()[1])) {
                        itr.remove();
                    }
                }
            }
            return order;
        }
    };
}
Also used : PromotableOrder(org.broadleafcommerce.core.offer.service.discount.domain.PromotableOrder) Order(org.broadleafcommerce.core.order.domain.Order) IAnswer(org.easymock.IAnswer) OrderItem(org.broadleafcommerce.core.order.domain.OrderItem) DiscreteOrderItem(org.broadleafcommerce.core.order.domain.DiscreteOrderItem) BundleOrderItem(org.broadleafcommerce.core.order.domain.BundleOrderItem) FulfillmentGroupItem(org.broadleafcommerce.core.order.domain.FulfillmentGroupItem) FulfillmentGroup(org.broadleafcommerce.core.order.domain.FulfillmentGroup)

Example 2 with OrderItem

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

the class OfferDataItemProvider method getAddOrderItemToOrderAnswer.

public static IAnswer<OrderItem> getAddOrderItemToOrderAnswer() {
    return new IAnswer<OrderItem>() {

        @Override
        public OrderItem answer() throws Throwable {
            Order order = (Order) EasyMock.getCurrentArguments()[0];
            order.getOrderItems().add((OrderItem) EasyMock.getCurrentArguments()[1]);
            if (((OrderItem) EasyMock.getCurrentArguments()[1]).getId() == null) {
                ((OrderItem) EasyMock.getCurrentArguments()[1]).setId(OfferDataItemProvider.getOrderItemId());
            }
            return (OrderItem) EasyMock.getCurrentArguments()[1];
        }
    };
}
Also used : PromotableOrder(org.broadleafcommerce.core.offer.service.discount.domain.PromotableOrder) Order(org.broadleafcommerce.core.order.domain.Order) IAnswer(org.easymock.IAnswer) OrderItem(org.broadleafcommerce.core.order.domain.OrderItem) DiscreteOrderItem(org.broadleafcommerce.core.order.domain.DiscreteOrderItem) BundleOrderItem(org.broadleafcommerce.core.order.domain.BundleOrderItem)

Example 3 with OrderItem

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

the class CheckoutTest method addSampleItemToOrder.

private void addSampleItemToOrder(Order order, FulfillmentGroup group) {
    DiscreteOrderItem item = new DiscreteOrderItemImpl();
    item.setOrder(order);
    item.setQuantity(1);
    Sku newSku = new SkuImpl();
    newSku.setName("Under Armor T-Shirt -- Red");
    newSku.setRetailPrice(new Money(14.99));
    newSku.setActiveStartDate(SystemTime.asDate());
    newSku.setDiscountable(false);
    newSku = catalogService.saveSku(newSku);
    item.setSku(newSku);
    item = (DiscreteOrderItem) orderItemService.saveOrderItem(item);
    List<OrderItem> items = new ArrayList<>();
    items.add(item);
    order.setOrderItems(items);
    FulfillmentGroupItem fgItem = new FulfillmentGroupItemImpl();
    fgItem.setFulfillmentGroup(group);
    fgItem.setOrderItem(item);
    fgItem.setQuantity(1);
    // fgItem.setPrice(new Money(0D));
    group.addFulfillmentGroupItem(fgItem);
}
Also used : DiscreteOrderItem(org.broadleafcommerce.core.order.domain.DiscreteOrderItem) Money(org.broadleafcommerce.common.money.Money) SkuImpl(org.broadleafcommerce.core.catalog.domain.SkuImpl) DiscreteOrderItemImpl(org.broadleafcommerce.core.order.domain.DiscreteOrderItemImpl) OrderItem(org.broadleafcommerce.core.order.domain.OrderItem) DiscreteOrderItem(org.broadleafcommerce.core.order.domain.DiscreteOrderItem) FulfillmentGroupItem(org.broadleafcommerce.core.order.domain.FulfillmentGroupItem) ArrayList(java.util.ArrayList) Sku(org.broadleafcommerce.core.catalog.domain.Sku) FulfillmentGroupItemImpl(org.broadleafcommerce.core.order.domain.FulfillmentGroupItemImpl)

Example 4 with OrderItem

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

the class MVELTest method testOfferAppliesToHatsWhenOneLawnmowerIsPurchased.

// @Test
// TODO fix this test
public void testOfferAppliesToHatsWhenOneLawnmowerIsPurchased() {
    OrderImpl order = new OrderImpl();
    ArrayList<OrderItem> items = new ArrayList<>();
    order.setOrderItems(items);
    DiscreteOrderItemImpl item = new DiscreteOrderItemImpl();
    Money amount = new Money(10D);
    items.add(item);
    item.setSalePrice(amount);
    ProductImpl product = new ProductImpl();
    CategoryImpl category = new CategoryImpl();
    category.setName("hat");
    product.setDefaultCategory(category);
    item.setProduct(product);
    item.setQuantity(3);
    DiscreteOrderItemImpl item2 = new DiscreteOrderItemImpl();
    Money amount2 = new Money(250D);
    items.add(item2);
    item2.setSalePrice(amount2);
    ProductImpl product2 = new ProductImpl();
    CategoryImpl category2 = new CategoryImpl();
    category2.setName("lawnmower");
    product2.setDefaultCategory(category2);
    item2.setProduct(product2);
    item2.setQuantity(1);
    HashMap<String, Object> vars = new HashMap<>();
    vars.put("currentItem", item);
    vars.put("order", order);
    vars.put("doMark", false);
    // This test makes use of the static MVEL function "orderContains(quantity)".
    StringBuffer expression = new StringBuffer(functions);
    expression.append("def evalItemForOrderContains(item) {").append("             return item.product.defaultCategory.name == 'lawnmower'").append("          } ").append("          return (orderContainsPlusMark(1) and currentItem.product.defaultCategory.name == 'hat');");
    Boolean result = (Boolean) MVEL.eval(expression.toString(), vars);
    assert result != null && result;
}
Also used : DiscreteOrderItemImpl(org.broadleafcommerce.core.order.domain.DiscreteOrderItemImpl) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) CategoryImpl(org.broadleafcommerce.core.catalog.domain.CategoryImpl) Money(org.broadleafcommerce.common.money.Money) ProductImpl(org.broadleafcommerce.core.catalog.domain.ProductImpl) OrderItem(org.broadleafcommerce.core.order.domain.OrderItem) OrderImpl(org.broadleafcommerce.core.order.domain.OrderImpl)

Example 5 with OrderItem

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

the class OfferServiceTest method testOrderItemOfferWithGiftWrap.

@Test(groups = { "testOffersWithGiftWrap" }, dependsOnGroups = { "testShippingInsert" })
@Transactional
public void testOrderItemOfferWithGiftWrap() throws PricingException {
    Order order = createTestOrderWithOfferAndGiftWrap();
    OfferDataItemProvider dataProvider = new OfferDataItemProvider();
    List<Offer> offers = dataProvider.createItemBasedOfferWithItemCriteria("order.subTotal.getAmount()>20", OfferDiscountType.PERCENT_OFF, "([MVEL.eval(\"toUpperCase()\",\"Test Sku\")] contains MVEL.eval(\"toUpperCase()\", discreteOrderItem.sku.name))", "([MVEL.eval(\"toUpperCase()\",\"Test Sku\")] contains MVEL.eval(\"toUpperCase()\", discreteOrderItem.sku.name))");
    for (Offer offer : offers) {
        offer.setName("testOffer");
        // //reset the offer is the targets and qualifiers, otherwise the reference is incorrect
        // for (OfferItemCriteria criteria : offer.getTargetItemCriteria()) {
        // criteria.setTargetOffer(null);
        // }
        // for (OfferItemCriteria criteria : offer.getQualifyingItemCriteria()) {
        // criteria.setQualifyingOffer(null);
        // }
        offerService.save(offer);
    }
    order = orderService.save(order, false);
    Set<OrderMultishipOption> options = new HashSet<OrderMultishipOption>();
    for (FulfillmentGroup fg : order.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);
                option.setAddress(address);
                option.setOrderItem(fgItem.getOrderItem());
                option.setFulfillmentOption(fg.getFulfillmentOption());
                options.add(option);
            }
        }
    }
    for (OrderMultishipOption option : options) {
        orderMultishipOptionService.save(option);
    }
    order = fulfillmentGroupService.matchFulfillmentGroupsToMultishipOptions(order, true);
    assert order.getOrderItems().size() == 3;
    assert order.getTotalTax().equals(new Money("2.00"));
    assert order.getTotalShipping().equals(new Money("8.50"));
    assert order.getSubTotal().equals(new Money("40.00"));
    assert order.getTotal().equals(new Money("50.50"));
    boolean foundGiftItemAndCorrectQuantity = false;
    for (OrderItem orderItem : order.getOrderItems()) {
        if (orderItem instanceof GiftWrapOrderItem && ((GiftWrapOrderItem) orderItem).getWrappedItems().size() == 1) {
            foundGiftItemAndCorrectQuantity = true;
            break;
        }
    }
    assert foundGiftItemAndCorrectQuantity;
}
Also used : Order(org.broadleafcommerce.core.order.domain.Order) Address(org.broadleafcommerce.profile.core.domain.Address) OrderMultishipOptionImpl(org.broadleafcommerce.core.order.domain.OrderMultishipOptionImpl) Money(org.broadleafcommerce.common.money.Money) Offer(org.broadleafcommerce.core.offer.domain.Offer) FulfillmentGroupItem(org.broadleafcommerce.core.order.domain.FulfillmentGroupItem) DiscreteOrderItem(org.broadleafcommerce.core.order.domain.DiscreteOrderItem) OrderItem(org.broadleafcommerce.core.order.domain.OrderItem) GiftWrapOrderItem(org.broadleafcommerce.core.order.domain.GiftWrapOrderItem) OrderMultishipOption(org.broadleafcommerce.core.order.domain.OrderMultishipOption) GiftWrapOrderItem(org.broadleafcommerce.core.order.domain.GiftWrapOrderItem) FulfillmentGroup(org.broadleafcommerce.core.order.domain.FulfillmentGroup) HashSet(java.util.HashSet) Test(org.testng.annotations.Test) CommonSetupBaseTest(org.broadleafcommerce.test.CommonSetupBaseTest) Transactional(org.springframework.transaction.annotation.Transactional)

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