Search in sources :

Example 1 with FulfillmentGroupItem

use of org.broadleafcommerce.core.order.domain.FulfillmentGroupItem 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 FulfillmentGroupItem

use of org.broadleafcommerce.core.order.domain.FulfillmentGroupItem 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 3 with FulfillmentGroupItem

use of org.broadleafcommerce.core.order.domain.FulfillmentGroupItem 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)

Example 4 with FulfillmentGroupItem

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

the class LegacyOrderServiceImpl method createFulfillmentGroupItemFromOrderItem.

protected FulfillmentGroupItem createFulfillmentGroupItemFromOrderItem(OrderItem orderItem, FulfillmentGroup fulfillmentGroup, int quantity) {
    FulfillmentGroupItem fgi = fulfillmentGroupItemDao.create();
    fgi.setFulfillmentGroup(fulfillmentGroup);
    fgi.setOrderItem(orderItem);
    fgi.setQuantity(quantity);
    return fgi;
}
Also used : FulfillmentGroupItem(org.broadleafcommerce.core.order.domain.FulfillmentGroupItem)

Example 5 with FulfillmentGroupItem

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

the class FulfillmentGroupItemStrategyImpl method onItemUpdated.

@Override
public CartOperationRequest onItemUpdated(CartOperationRequest request) throws PricingException {
    Order order = request.getOrder();
    OrderItem orderItem = request.getOrderItem();
    Integer orderItemQuantityDelta = request.getOrderItemQuantityDelta();
    if (orderItemQuantityDelta == 0) {
        // If the quantity didn't change, nothing needs to happen
        return request;
    } else {
        List<FulfillmentGroupItem> fgisToDelete = new ArrayList<FulfillmentGroupItem>();
        if (orderItem instanceof BundleOrderItem) {
            List<OrderItem> itemsToUpdate = new ArrayList<OrderItem>(((BundleOrderItem) orderItem).getDiscreteOrderItems());
            for (OrderItem oi : itemsToUpdate) {
                int quantityPer = oi.getQuantity();
                fgisToDelete.addAll(updateItemQuantity(order, oi, (quantityPer * orderItemQuantityDelta)));
            }
        } else {
            fgisToDelete.addAll(updateItemQuantity(order, orderItem, orderItemQuantityDelta));
            List<OrderItem> itemsToUpdate = new ArrayList<>(orderItem.getChildOrderItems());
            for (OrderItem oi : itemsToUpdate) {
                int quantityPer = oi.getQuantity() / orderItem.getQuantity();
                fgisToDelete.addAll(updateItemQuantity(order, oi, (quantityPer * orderItemQuantityDelta)));
            }
        }
        request.setFgisToDelete(fgisToDelete);
    }
    return request;
}
Also used : Order(org.broadleafcommerce.core.order.domain.Order) BundleOrderItem(org.broadleafcommerce.core.order.domain.BundleOrderItem) DiscreteOrderItem(org.broadleafcommerce.core.order.domain.DiscreteOrderItem) OrderItem(org.broadleafcommerce.core.order.domain.OrderItem) BundleOrderItem(org.broadleafcommerce.core.order.domain.BundleOrderItem) FulfillmentGroupItem(org.broadleafcommerce.core.order.domain.FulfillmentGroupItem) ArrayList(java.util.ArrayList)

Aggregations

FulfillmentGroupItem (org.broadleafcommerce.core.order.domain.FulfillmentGroupItem)48 FulfillmentGroup (org.broadleafcommerce.core.order.domain.FulfillmentGroup)39 DiscreteOrderItem (org.broadleafcommerce.core.order.domain.DiscreteOrderItem)25 Order (org.broadleafcommerce.core.order.domain.Order)21 OrderItem (org.broadleafcommerce.core.order.domain.OrderItem)20 Money (org.broadleafcommerce.common.money.Money)18 ArrayList (java.util.ArrayList)16 BundleOrderItem (org.broadleafcommerce.core.order.domain.BundleOrderItem)15 Sku (org.broadleafcommerce.core.catalog.domain.Sku)12 Transactional (org.springframework.transaction.annotation.Transactional)11 FulfillmentGroupItemImpl (org.broadleafcommerce.core.order.domain.FulfillmentGroupItemImpl)9 Address (org.broadleafcommerce.profile.core.domain.Address)9 BigDecimal (java.math.BigDecimal)8 Test (org.testng.annotations.Test)8 SkuImpl (org.broadleafcommerce.core.catalog.domain.SkuImpl)7 DiscreteOrderItemImpl (org.broadleafcommerce.core.order.domain.DiscreteOrderItemImpl)7 FulfillmentGroupImpl (org.broadleafcommerce.core.order.domain.FulfillmentGroupImpl)7 HashMap (java.util.HashMap)6 AddressImpl (org.broadleafcommerce.profile.core.domain.AddressImpl)6 ISOCountry (org.broadleafcommerce.common.i18n.domain.ISOCountry)5