Search in sources :

Example 1 with GiftWrapOrderItem

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

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

the class OrderServiceImpl method addGiftWrapItemToOrder.

@Override
@Transactional("blTransactionManager")
public OrderItem addGiftWrapItemToOrder(Order order, GiftWrapOrderItemRequest itemRequest, boolean priceOrder) throws PricingException {
    GiftWrapOrderItem item = orderItemService.createGiftWrapOrderItem(itemRequest);
    item.setOrder(order);
    item = (GiftWrapOrderItem) orderItemService.saveOrderItem(item);
    order.getOrderItems().add(item);
    order = save(order, priceOrder);
    return item;
}
Also used : GiftWrapOrderItem(org.broadleafcommerce.core.order.domain.GiftWrapOrderItem) Transactional(org.springframework.transaction.annotation.Transactional)

Example 3 with GiftWrapOrderItem

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

the class LegacyMergeCartServiceImpl method removeExpiredGiftWrapOrderItems.

protected Order removeExpiredGiftWrapOrderItems(MergeCartResponse mergeCartResponse, Order customerCart, Map<OrderItem, OrderItem> oldNewItemMap) throws PricingException {
    // clear out any Gift Wrap items that contain one or more removed wrapped items
    Iterator<OrderItem> addedItems = mergeCartResponse.getAddedItems().iterator();
    while (addedItems.hasNext()) {
        OrderItem addedItem = addedItems.next();
        if (addedItem instanceof GiftWrapOrderItem) {
            GiftWrapOrderItem giftWrapOrderItem = (GiftWrapOrderItem) addedItem;
            boolean removeItem = false;
            for (OrderItem wrappedItem : giftWrapOrderItem.getWrappedItems()) {
                if (mergeCartResponse.getRemovedItems().contains(wrappedItem)) {
                    removeItem = true;
                    break;
                }
            }
            if (removeItem) {
                for (OrderItem wrappedItem : giftWrapOrderItem.getWrappedItems()) {
                    wrappedItem.setGiftWrapOrderItem(null);
                }
                giftWrapOrderItem.getWrappedItems().clear();
                for (OrderItem cartItem : customerCart.getOrderItems()) {
                    if (cartItem.getGiftWrapOrderItem() != null && oldNewItemMap.containsKey(cartItem.getGiftWrapOrderItem())) {
                        cartItem.setGiftWrapOrderItem(null);
                    }
                }
                customerCart = removeItemFromOrder(customerCart, giftWrapOrderItem, false);
                addedItems.remove();
                mergeCartResponse.getRemovedItems().add(giftWrapOrderItem);
            }
        }
    }
    return customerCart;
}
Also used : DiscreteOrderItem(org.broadleafcommerce.core.order.domain.DiscreteOrderItem) OrderItem(org.broadleafcommerce.core.order.domain.OrderItem) GiftWrapOrderItem(org.broadleafcommerce.core.order.domain.GiftWrapOrderItem) BundleOrderItem(org.broadleafcommerce.core.order.domain.BundleOrderItem) GiftWrapOrderItem(org.broadleafcommerce.core.order.domain.GiftWrapOrderItem)

Example 4 with GiftWrapOrderItem

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

the class LegacyMergeCartServiceImpl method reconstructCart.

@Override
public ReconstructCartResponse reconstructCart(Customer customer, boolean priceOrder) throws PricingException {
    ReconstructCartResponse reconstructCartResponse = new ReconstructCartResponse();
    Order customerCart = orderService.findCartForCustomer(customer);
    if (customerCart != null) {
        List<OrderItem> itemsToRemove = new ArrayList<OrderItem>();
        for (OrderItem orderItem : customerCart.getOrderItems()) {
            if (orderItem instanceof DiscreteOrderItem) {
                DiscreteOrderItem discreteOrderItem = (DiscreteOrderItem) orderItem;
                if (discreteOrderItem.getSku().getActiveStartDate() != null) {
                    if (!discreteOrderItem.getSku().isActive(discreteOrderItem.getProduct(), orderItem.getCategory())) {
                        itemsToRemove.add(orderItem);
                    }
                } else {
                    if (!discreteOrderItem.getProduct().isActive() || !orderItem.getCategory().isActive()) {
                        itemsToRemove.add(orderItem);
                    }
                }
            } else if (orderItem instanceof BundleOrderItem) {
                BundleOrderItem bundleOrderItem = (BundleOrderItem) orderItem;
                boolean removeBundle = false;
                for (DiscreteOrderItem discreteOrderItem : bundleOrderItem.getDiscreteOrderItems()) {
                    if (discreteOrderItem.getSku().getActiveStartDate() != null) {
                        if (!discreteOrderItem.getSku().isActive(discreteOrderItem.getProduct(), orderItem.getCategory())) {
                            /*
                                 * Bundle has an inactive item in it -- remove the
                                 * whole bundle
                                 */
                            removeBundle = true;
                            break;
                        }
                    } else {
                        if (!discreteOrderItem.getProduct().isActive() || !orderItem.getCategory().isActive()) {
                            removeBundle = true;
                            break;
                        }
                    }
                }
                if (removeBundle) {
                    itemsToRemove.add(orderItem);
                }
            }
        }
        // Remove any giftwrap items who have one or more wrapped item members that have been removed
        for (OrderItem orderItem : customerCart.getOrderItems()) {
            if (orderItem instanceof GiftWrapOrderItem) {
                for (OrderItem wrappedItem : ((GiftWrapOrderItem) orderItem).getWrappedItems()) {
                    if (itemsToRemove.contains(wrappedItem)) {
                        itemsToRemove.add(orderItem);
                        break;
                    }
                }
            }
        }
        for (OrderItem item : itemsToRemove) {
            removeItemFromOrder(customerCart, item, priceOrder);
        }
        reconstructCartResponse.setRemovedItems(itemsToRemove);
    }
    reconstructCartResponse.setOrder(customerCart);
    return reconstructCartResponse;
}
Also used : Order(org.broadleafcommerce.core.order.domain.Order) DiscreteOrderItem(org.broadleafcommerce.core.order.domain.DiscreteOrderItem) BundleOrderItem(org.broadleafcommerce.core.order.domain.BundleOrderItem) DiscreteOrderItem(org.broadleafcommerce.core.order.domain.DiscreteOrderItem) OrderItem(org.broadleafcommerce.core.order.domain.OrderItem) GiftWrapOrderItem(org.broadleafcommerce.core.order.domain.GiftWrapOrderItem) BundleOrderItem(org.broadleafcommerce.core.order.domain.BundleOrderItem) ArrayList(java.util.ArrayList) GiftWrapOrderItem(org.broadleafcommerce.core.order.domain.GiftWrapOrderItem) ReconstructCartResponse(org.broadleafcommerce.core.order.service.call.ReconstructCartResponse)

Example 5 with GiftWrapOrderItem

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

the class OrderItemServiceImpl method createGiftWrapOrderItem.

@Override
public GiftWrapOrderItem createGiftWrapOrderItem(final GiftWrapOrderItemRequest itemRequest) {
    final GiftWrapOrderItem item = (GiftWrapOrderItem) orderItemDao.create(OrderItemType.GIFTWRAP);
    item.setSku(itemRequest.getSku());
    item.setOrder(itemRequest.getOrder());
    item.setBundleOrderItem(itemRequest.getBundleOrderItem());
    item.setQuantity(itemRequest.getQuantity());
    item.setCategory(itemRequest.getCategory());
    item.setProduct(itemRequest.getProduct());
    item.setBaseSalePrice(itemRequest.getSku().getSalePrice());
    item.setBaseRetailPrice(itemRequest.getSku().getRetailPrice());
    item.setDiscreteOrderItemFeePrices(itemRequest.getDiscreteOrderItemFeePrices());
    if (itemRequest.getSalePriceOverride() != null) {
        item.setSalePriceOverride(Boolean.TRUE);
        item.setSalePrice(itemRequest.getSalePriceOverride());
        item.setBaseSalePrice(itemRequest.getSalePriceOverride());
    }
    if (itemRequest.getRetailPriceOverride() != null) {
        item.setRetailPriceOverride(Boolean.TRUE);
        item.setRetailPrice(itemRequest.getRetailPriceOverride());
        item.setBaseRetailPrice(itemRequest.getRetailPriceOverride());
    }
    // item.updatePrices();
    item.updateSaleAndRetailPrices();
    item.assignFinalPrice();
    item.getWrappedItems().addAll(itemRequest.getWrappedItems());
    for (OrderItem orderItem : item.getWrappedItems()) {
        orderItem.setGiftWrapOrderItem(item);
    }
    applyAdditionalOrderItemProperties(item);
    return item;
}
Also used : DiscreteOrderItem(org.broadleafcommerce.core.order.domain.DiscreteOrderItem) OrderItem(org.broadleafcommerce.core.order.domain.OrderItem) GiftWrapOrderItem(org.broadleafcommerce.core.order.domain.GiftWrapOrderItem) BundleOrderItem(org.broadleafcommerce.core.order.domain.BundleOrderItem) GiftWrapOrderItem(org.broadleafcommerce.core.order.domain.GiftWrapOrderItem)

Aggregations

GiftWrapOrderItem (org.broadleafcommerce.core.order.domain.GiftWrapOrderItem)10 DiscreteOrderItem (org.broadleafcommerce.core.order.domain.DiscreteOrderItem)8 OrderItem (org.broadleafcommerce.core.order.domain.OrderItem)8 BundleOrderItem (org.broadleafcommerce.core.order.domain.BundleOrderItem)5 ArrayList (java.util.ArrayList)4 Order (org.broadleafcommerce.core.order.domain.Order)4 Transactional (org.springframework.transaction.annotation.Transactional)4 Money (org.broadleafcommerce.common.money.Money)2 Sku (org.broadleafcommerce.core.catalog.domain.Sku)2 FulfillmentGroup (org.broadleafcommerce.core.order.domain.FulfillmentGroup)2 FulfillmentGroupItem (org.broadleafcommerce.core.order.domain.FulfillmentGroupItem)2 ReconstructCartResponse (org.broadleafcommerce.core.order.service.call.ReconstructCartResponse)2 Address (org.broadleafcommerce.profile.core.domain.Address)2 Test (org.testng.annotations.Test)2 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Iterator (java.util.Iterator)1 List (java.util.List)1 Map (java.util.Map)1 SkuImpl (org.broadleafcommerce.core.catalog.domain.SkuImpl)1