Search in sources :

Example 6 with GiftWrapOrderItem

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

the class OrderItemDaoImpl method delete.

@Override
@Transactional("blTransactionManager")
public void delete(OrderItem orderItem) {
    if (!em.contains(orderItem)) {
        orderItem = readOrderItemById(orderItem.getId());
    }
    if (GiftWrapOrderItem.class.isAssignableFrom(orderItem.getClass())) {
        final GiftWrapOrderItem giftItem = (GiftWrapOrderItem) orderItem;
        for (OrderItem wrappedItem : giftItem.getWrappedItems()) {
            wrappedItem.setGiftWrapOrderItem(null);
            wrappedItem = save(wrappedItem);
        }
    }
    em.remove(orderItem);
    em.flush();
}
Also used : OrderItem(org.broadleafcommerce.core.order.domain.OrderItem) GiftWrapOrderItem(org.broadleafcommerce.core.order.domain.GiftWrapOrderItem) GiftWrapOrderItem(org.broadleafcommerce.core.order.domain.GiftWrapOrderItem) Transactional(org.springframework.transaction.annotation.Transactional)

Example 7 with GiftWrapOrderItem

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

the class OfferServiceTest method createTestOrderWithOfferAndGiftWrap.

private Order createTestOrderWithOfferAndGiftWrap() throws PricingException {
    Customer customer = customerService.createCustomerFromId(null);
    Order order = orderService.createNewCartForCustomer(customer);
    customerService.saveCustomer(order.getCustomer());
    createCountry();
    createState();
    Address address = new AddressImpl();
    address.setAddressLine1("123 Test Rd");
    address.setCity("Dallas");
    address.setFirstName("Jeff");
    address.setLastName("Fischer");
    address.setPostalCode("75240");
    address.setPrimaryPhone("972-978-9067");
    address.setState(stateService.findStateByAbbreviation("KY"));
    address.setCountry(countryService.findCountryByAbbreviation("US"));
    address.setIsoCountrySubdivision("US-KY");
    address.setIsoCountryAlpha2(isoService.findISOCountryByAlpha2Code("US"));
    FulfillmentGroup group = new FulfillmentGroupImpl();
    group.setAddress(address);
    group.setIsShippingPriceTaxable(true);
    List<FulfillmentGroup> groups = new ArrayList<FulfillmentGroup>();
    FixedPriceFulfillmentOption option = new FixedPriceFulfillmentOptionImpl();
    option.setPrice(new Money("8.50"));
    option.setFulfillmentType(FulfillmentType.PHYSICAL_SHIP);
    group.setFulfillmentOption(option);
    group.setFulfillmentOption(option);
    group.setOrder(order);
    groups.add(group);
    order.setFulfillmentGroups(groups);
    Money total = new Money(5D);
    group.setRetailShippingPrice(total);
    group.setShippingPrice(total);
    DiscreteOrderItem item1;
    {
        item1 = new DiscreteOrderItemImpl();
        Sku sku = new SkuImpl();
        sku.setName("Test Sku");
        sku.setRetailPrice(new Money(10D));
        sku.setDiscountable(true);
        sku = catalogService.saveSku(sku);
        item1.setSku(sku);
        item1.setQuantity(2);
        item1.setOrder(order);
        item1.setOrderItemType(OrderItemType.DISCRETE);
        item1 = (DiscreteOrderItem) orderItemService.saveOrderItem(item1);
        order.addOrderItem(item1);
        FulfillmentGroupItem fgItem = new FulfillmentGroupItemImpl();
        fgItem.setFulfillmentGroup(group);
        fgItem.setOrderItem(item1);
        fgItem.setQuantity(2);
        // fgItem.setPrice(new Money(0D));
        group.addFulfillmentGroupItem(fgItem);
    }
    {
        DiscreteOrderItem item = new DiscreteOrderItemImpl();
        Sku sku = new SkuImpl();
        sku.setName("Test Product 2");
        sku.setRetailPrice(new Money(20D));
        sku.setDiscountable(true);
        sku = catalogService.saveSku(sku);
        item.setSku(sku);
        item.setQuantity(1);
        item.setOrder(order);
        item.setOrderItemType(OrderItemType.DISCRETE);
        item = (DiscreteOrderItem) orderItemService.saveOrderItem(item);
        order.addOrderItem(item);
        FulfillmentGroupItem fgItem = new FulfillmentGroupItemImpl();
        fgItem.setFulfillmentGroup(group);
        fgItem.setOrderItem(item);
        fgItem.setQuantity(1);
        // fgItem.setPrice(new Money(0D));
        group.addFulfillmentGroupItem(fgItem);
    }
    {
        GiftWrapOrderItem item = new GiftWrapOrderItemImpl();
        Sku sku = new SkuImpl();
        sku.setName("Test GiftWrap");
        sku.setRetailPrice(new Money(1D));
        sku.setDiscountable(true);
        sku = catalogService.saveSku(sku);
        item.setSku(sku);
        item.setQuantity(1);
        item.setOrder(order);
        item.getWrappedItems().add(item1);
        item.setOrderItemType(OrderItemType.GIFTWRAP);
        item = (GiftWrapOrderItem) orderItemService.saveOrderItem(item);
        order.addOrderItem(item);
        FulfillmentGroupItem fgItem = new FulfillmentGroupItemImpl();
        fgItem.setFulfillmentGroup(group);
        fgItem.setOrderItem(item);
        fgItem.setQuantity(1);
        // fgItem.setPrice(new Money(0D));
        group.addFulfillmentGroupItem(fgItem);
    }
    return order;
}
Also used : Order(org.broadleafcommerce.core.order.domain.Order) DiscreteOrderItem(org.broadleafcommerce.core.order.domain.DiscreteOrderItem) FulfillmentGroupImpl(org.broadleafcommerce.core.order.domain.FulfillmentGroupImpl) Address(org.broadleafcommerce.profile.core.domain.Address) Customer(org.broadleafcommerce.profile.core.domain.Customer) DiscreteOrderItemImpl(org.broadleafcommerce.core.order.domain.DiscreteOrderItemImpl) ArrayList(java.util.ArrayList) Money(org.broadleafcommerce.common.money.Money) SkuImpl(org.broadleafcommerce.core.catalog.domain.SkuImpl) FixedPriceFulfillmentOption(org.broadleafcommerce.core.order.fulfillment.domain.FixedPriceFulfillmentOption) FulfillmentGroupItem(org.broadleafcommerce.core.order.domain.FulfillmentGroupItem) AddressImpl(org.broadleafcommerce.profile.core.domain.AddressImpl) GiftWrapOrderItem(org.broadleafcommerce.core.order.domain.GiftWrapOrderItem) FulfillmentGroup(org.broadleafcommerce.core.order.domain.FulfillmentGroup) GiftWrapOrderItemImpl(org.broadleafcommerce.core.order.domain.GiftWrapOrderItemImpl) Sku(org.broadleafcommerce.core.catalog.domain.Sku) FixedPriceFulfillmentOptionImpl(org.broadleafcommerce.core.order.fulfillment.domain.FixedPriceFulfillmentOptionImpl) FulfillmentGroupItemImpl(org.broadleafcommerce.core.order.domain.FulfillmentGroupItemImpl)

Example 8 with GiftWrapOrderItem

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

the class OrderItemDaoTest method createGiftWrapOrderItem.

@Test(groups = { "createGiftWrapOrderItem" }, dataProvider = "basicGiftWrapOrderItem", dataProviderClass = OrderItemDataProvider.class, dependsOnGroups = { "readOrderItemsById" })
@Rollback(false)
@Transactional
public void createGiftWrapOrderItem(GiftWrapOrderItem orderItem) {
    Sku si = skuDao.readFirstSku();
    assert si.getId() != null;
    orderItem.setSku(si);
    assert orderItem.getId() == null;
    OrderItem discreteItem = orderItemDao.readOrderItemById(orderItemId);
    orderItem.getWrappedItems().add(discreteItem);
    discreteItem.setGiftWrapOrderItem(orderItem);
    orderItem = (GiftWrapOrderItem) orderItemDao.save(orderItem);
    assert orderItem.getId() != null;
    giftWrapItemId = orderItem.getId();
}
Also used : DiscreteOrderItem(org.broadleafcommerce.core.order.domain.DiscreteOrderItem) OrderItem(org.broadleafcommerce.core.order.domain.OrderItem) GiftWrapOrderItem(org.broadleafcommerce.core.order.domain.GiftWrapOrderItem) Sku(org.broadleafcommerce.core.catalog.domain.Sku) Test(org.testng.annotations.Test) Rollback(org.springframework.test.annotation.Rollback) Transactional(org.springframework.transaction.annotation.Transactional)

Example 9 with GiftWrapOrderItem

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

the class MergeCartServiceImpl method reconstructCart.

@Override
public ReconstructCartResponse reconstructCart(Customer customer, boolean priceOrder) throws PricingException, RemoveFromCartException {
    ReconstructCartResponse reconstructCartResponse = new ReconstructCartResponse();
    Order customerCart = orderService.findCartForCustomerWithEnhancements(customer);
    if (customerCart != null) {
        List<OrderItem> itemsToRemove = new ArrayList<OrderItem>();
        for (OrderItem orderItem : customerCart.getOrderItems()) {
            if (orderItem instanceof DiscreteOrderItem) {
                DiscreteOrderItem doi = (DiscreteOrderItem) orderItem;
                if (!checkActive(doi) || !checkInventory(doi) || !checkOtherValidity(orderItem)) {
                    itemsToRemove.add(orderItem);
                }
            } else if (orderItem instanceof BundleOrderItem) {
                BundleOrderItem bundleOrderItem = (BundleOrderItem) orderItem;
                for (DiscreteOrderItem doi : bundleOrderItem.getDiscreteOrderItems()) {
                    if (!checkActive(doi) || !checkInventory(doi) || !checkOtherValidity(orderItem)) {
                        itemsToRemove.add(doi.getBundleOrderItem());
                    }
                }
            }
        }
        // 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) {
            orderService.removeItem(customerCart.getId(), item.getId(), false);
        }
        reconstructCartResponse.setRemovedItems(itemsToRemove);
        customerCart = orderService.save(customerCart, priceOrder);
    }
    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 10 with GiftWrapOrderItem

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

the class LegacyMergeCartServiceImpl method mergeGiftWrapOrderItems.

protected Order mergeGiftWrapOrderItems(MergeCartResponse mergeCartResponse, Order customerCart, Map<OrderItem, OrderItem> oldNewItemMap) throws PricingException {
    // update any remaining gift wrap items with their cloned wrapped item values, instead of the originals
    Iterator<OrderItem> addedItems = mergeCartResponse.getAddedItems().iterator();
    while (addedItems.hasNext()) {
        OrderItem addedItem = addedItems.next();
        if (addedItem instanceof GiftWrapOrderItem) {
            GiftWrapOrderItem giftItem = (GiftWrapOrderItem) addedItem;
            List<OrderItem> itemsToAdd = new ArrayList<OrderItem>();
            Iterator<OrderItem> wrappedItems = giftItem.getWrappedItems().iterator();
            while (wrappedItems.hasNext()) {
                OrderItem wrappedItem = wrappedItems.next();
                if (oldNewItemMap.containsKey(wrappedItem)) {
                    OrderItem newItem = oldNewItemMap.get(wrappedItem);
                    newItem.setGiftWrapOrderItem(giftItem);
                    itemsToAdd.add(newItem);
                    wrappedItem.setGiftWrapOrderItem(null);
                    wrappedItems.remove();
                }
            }
            giftItem.getWrappedItems().addAll(itemsToAdd);
        } else if (addedItem instanceof BundleOrderItem) {
            // a GiftWrapOrderItem inside a BundleOrderItem can only wrap other members of that bundle
            // or root members of the order - not members of an entirely different bundle
            boolean isValidBundle = true;
            Map<String, DiscreteOrderItem> newItemsMap = new HashMap<String, DiscreteOrderItem>();
            for (DiscreteOrderItem newItem : ((BundleOrderItem) addedItem).getDiscreteOrderItems()) {
                newItemsMap.put(newItem.getSku().getId() + "_" + newItem.getPrice(), newItem);
            }
            checkBundle: {
                for (DiscreteOrderItem itemFromBundle : ((BundleOrderItem) addedItem).getDiscreteOrderItems()) {
                    if (itemFromBundle instanceof GiftWrapOrderItem) {
                        GiftWrapOrderItem giftItem = (GiftWrapOrderItem) itemFromBundle;
                        List<OrderItem> itemsToAdd = new ArrayList<OrderItem>();
                        Iterator<OrderItem> wrappedItems = giftItem.getWrappedItems().iterator();
                        while (wrappedItems.hasNext()) {
                            OrderItem wrappedItem = wrappedItems.next();
                            if (oldNewItemMap.containsKey(wrappedItem)) {
                                OrderItem newItem = oldNewItemMap.get(wrappedItem);
                                newItem.setGiftWrapOrderItem(giftItem);
                                itemsToAdd.add(newItem);
                                wrappedItem.setGiftWrapOrderItem(null);
                                wrappedItems.remove();
                            } else if (wrappedItem instanceof DiscreteOrderItem) {
                                DiscreteOrderItem discreteWrappedItem = (DiscreteOrderItem) wrappedItem;
                                String itemKey = discreteWrappedItem.getSku().getId() + "_" + discreteWrappedItem.getPrice();
                                if (newItemsMap.containsKey(itemKey)) {
                                    OrderItem newItem = newItemsMap.get(itemKey);
                                    newItem.setGiftWrapOrderItem(giftItem);
                                    itemsToAdd.add(newItem);
                                    discreteWrappedItem.setGiftWrapOrderItem(null);
                                    wrappedItems.remove();
                                } else {
                                    isValidBundle = false;
                                    break checkBundle;
                                }
                            } else {
                                isValidBundle = false;
                                break checkBundle;
                            }
                        }
                        giftItem.getWrappedItems().addAll(itemsToAdd);
                    }
                }
            }
            if (!isValidBundle) {
                customerCart = removeItemFromOrder(customerCart, addedItem, false);
                addedItems.remove();
                mergeCartResponse.getRemovedItems().add(addedItem);
            }
        }
    }
    // If found, remove, because this is invalid. A GiftWrapOrderItem cannot wrap OrderItems located in an entirely different bundle.
    for (OrderItem addedItem : mergeCartResponse.getAddedItems()) {
        if (addedItem instanceof BundleOrderItem) {
            boolean containsGiftWrap = false;
            for (DiscreteOrderItem discreteOrderItem : ((BundleOrderItem) addedItem).getDiscreteOrderItems()) {
                if (discreteOrderItem instanceof GiftWrapOrderItem) {
                    containsGiftWrap = true;
                    break;
                }
            }
            if (!containsGiftWrap) {
                for (DiscreteOrderItem discreteOrderItem : ((BundleOrderItem) addedItem).getDiscreteOrderItems()) {
                    discreteOrderItem.setGiftWrapOrderItem(null);
                }
            }
        }
    }
    return customerCart;
}
Also used : DiscreteOrderItem(org.broadleafcommerce.core.order.domain.DiscreteOrderItem) ArrayList(java.util.ArrayList) 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) Iterator(java.util.Iterator) GiftWrapOrderItem(org.broadleafcommerce.core.order.domain.GiftWrapOrderItem) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map)

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