Search in sources :

Example 31 with DiscreteOrderItem

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

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

the class OfferTest method createDiscreteOrderItem.

private DiscreteOrderItem createDiscreteOrderItem(Long skuId, Double retailPrice, Double salePrice, boolean isDiscountable, int quantity, Order order) {
    DiscreteOrderItem item = new DiscreteOrderItemImpl();
    Sku sku = catalogService.findSkuById(skuId);
    sku.setRetailPrice(new Money(retailPrice));
    if (salePrice != null) {
        sku.setSalePrice(new Money(salePrice));
    } else {
        sku.setSalePrice(null);
    }
    sku.setDiscountable(isDiscountable);
    sku.setName("test");
    sku = catalogService.saveSku(sku);
    item.setSku(sku);
    item.setQuantity(quantity);
    Product product = new ProductImpl();
    product.setDefaultSku(sku);
    product = catalogService.saveProduct(product);
    item.setProduct(product);
    item.setOrder(order);
    item = (DiscreteOrderItem) orderItemService.saveOrderItem(item);
    return item;
}
Also used : DiscreteOrderItem(org.broadleafcommerce.core.order.domain.DiscreteOrderItem) Money(org.broadleafcommerce.common.money.Money) ProductImpl(org.broadleafcommerce.core.catalog.domain.ProductImpl) DiscreteOrderItemImpl(org.broadleafcommerce.core.order.domain.DiscreteOrderItemImpl) Product(org.broadleafcommerce.core.catalog.domain.Product) Sku(org.broadleafcommerce.core.catalog.domain.Sku)

Example 33 with DiscreteOrderItem

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

the class OrderTest method addItemToOrder.

@Test(groups = { "addItemToOrder" }, dependsOnGroups = { "findCurrentCartForCustomer", "createSku", "testCatalog" })
@Rollback(false)
@Transactional(propagation = Propagation.REQUIRES_NEW)
public void addItemToOrder() throws AddToCartException {
    numOrderItems++;
    // In the database, some Skus are inactive and some are active. This ensures that we pull back an active one
    // to test a successful cart add
    Sku sku = getFirstActiveSku();
    Order order = orderService.findOrderById(orderId);
    assert order != null;
    assert sku.getId() != null;
    OrderItemRequestDTO itemRequest = new OrderItemRequestDTO();
    itemRequest.setQuantity(1);
    itemRequest.setSkuId(sku.getId());
    order = orderService.addItem(orderId, itemRequest, true);
    DiscreteOrderItem item = (DiscreteOrderItem) orderService.findLastMatchingItem(order, sku.getId(), null);
    assert item != null;
    assert item.getQuantity() == numOrderItems;
    assert item.getSku() != null;
    assert item.getSku().equals(sku);
    assert order.getFulfillmentGroups().size() == 1;
    FulfillmentGroup fg = order.getFulfillmentGroups().get(0);
    assert fg.getFulfillmentGroupItems().size() == 1;
    FulfillmentGroupItem fgItem = fg.getFulfillmentGroupItems().get(0);
    assert fgItem.getOrderItem().equals(item);
    assert fgItem.getQuantity() == item.getQuantity();
}
Also used : Order(org.broadleafcommerce.core.order.domain.Order) DiscreteOrderItem(org.broadleafcommerce.core.order.domain.DiscreteOrderItem) OrderItemRequestDTO(org.broadleafcommerce.core.order.service.call.OrderItemRequestDTO) FulfillmentGroupItem(org.broadleafcommerce.core.order.domain.FulfillmentGroupItem) FulfillmentGroup(org.broadleafcommerce.core.order.domain.FulfillmentGroup) 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 34 with DiscreteOrderItem

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

the class OrderTest method addAnotherItemToOrder.

@Test(groups = { "addAnotherItemToOrder" }, dependsOnGroups = { "addItemToOrder" })
@Rollback(false)
@Transactional
public void addAnotherItemToOrder() throws AddToCartException, PricingException, RemoveFromCartException {
    // In the database, some Skus are inactive and some are active. This ensures that we pull back an active one
    // to test a successful cart add
    Sku sku = getFirstActiveSku();
    Order order = orderService.findOrderById(orderId);
    assert order != null;
    assert sku.getId() != null;
    orderService.setAutomaticallyMergeLikeItems(true);
    OrderItemRequestDTO itemRequest = new OrderItemRequestDTO();
    itemRequest.setQuantity(1);
    itemRequest.setSkuId(sku.getId());
    // Note that we are not incrementing the numOrderItems count because it should have gotten merged
    order = orderService.addItem(orderId, itemRequest, true);
    DiscreteOrderItem item = (DiscreteOrderItem) orderService.findLastMatchingItem(order, sku.getId(), null);
    assert item.getSku() != null;
    assert item.getSku().equals(sku);
    // item-was merged with prior item.
    assert item.getQuantity() == 2;
    order = orderService.findOrderById(orderId);
    assert (order.getOrderItems().size() == 1);
    assert (order.getOrderItems().get(0).getQuantity() == 2);
    assert order.getFulfillmentGroups().size() == 1;
    FulfillmentGroup fg = order.getFulfillmentGroups().get(0);
    assert fg.getFulfillmentGroupItems().size() == 1;
    FulfillmentGroupItem fgItem = fg.getFulfillmentGroupItems().get(0);
    assert fgItem.getOrderItem().equals(item);
    assert fgItem.getQuantity() == item.getQuantity();
    // add the same item multiple times to the cart without merging or pricing
    boolean currentVal = orderService.getAutomaticallyMergeLikeItems();
    orderService.setAutomaticallyMergeLikeItems(false);
    itemRequest = new OrderItemRequestDTO();
    itemRequest.setQuantity(1);
    itemRequest.setSkuId(sku.getId());
    order = orderService.addItem(orderId, itemRequest, false);
    order = orderService.addItem(orderId, itemRequest, false);
    DiscreteOrderItem item2 = (DiscreteOrderItem) orderService.findLastMatchingItem(order, sku.getId(), null);
    assert item2.getSku() != null;
    assert item2.getSku().equals(sku);
    // item-was not auto-merged with prior items.
    assert item2.getQuantity() == 1;
    order = orderService.findOrderById(orderId);
    assert (order.getOrderItems().size() == 3);
    // reset the cart state back to what it was prior
    order = orderService.removeItem(order.getId(), order.getOrderItems().get(1).getId(), true);
    order = orderService.removeItem(order.getId(), order.getOrderItems().get(1).getId(), true);
    orderService.setAutomaticallyMergeLikeItems(currentVal);
    assert (order.getOrderItems().size() == 1);
    assert (order.getOrderItems().get(0).getQuantity() == 2);
/*
        This test is not supported currently, as the order service may only do like item merging

        // re-price the order without automatically merging.
        orderService.setAutomaticallyMergeLikeItems(false);
        numOrderItems++;
        
        itemRequest = new OrderItemRequestDTO();
        itemRequest.setQuantity(1);
        itemRequest.setSkuId(sku.getId());
        order = orderService.addItem(orderId, itemRequest, true);
        DiscreteOrderItem item2 = (DiscreteOrderItem) orderService.findLastMatchingItem(order, sku.getId(), null);

        assert item2.getSku() != null;
        assert item2.getSku().equals(sku);
        assert item2.getQuantity() == 1;  // item-was not auto-merged with prior items.

        order = orderService.findOrderById(orderId);

        assert(order.getOrderItems().size()==2);
        assert(order.getOrderItems().get(0).getQuantity()==2);
        assert(order.getOrderItems().get(1).getQuantity()==1);
        
        assert order.getFulfillmentGroups().size() == 1;
        
        fg = order.getFulfillmentGroups().get(0);
        assert fg.getFulfillmentGroupItems().size() == 2;
        
        for (FulfillmentGroupItem fgi : fg.getFulfillmentGroupItems()) {
            assert fgi.getQuantity() == fgi.getOrderItem().getQuantity();
        }*/
}
Also used : Order(org.broadleafcommerce.core.order.domain.Order) DiscreteOrderItem(org.broadleafcommerce.core.order.domain.DiscreteOrderItem) OrderItemRequestDTO(org.broadleafcommerce.core.order.service.call.OrderItemRequestDTO) FulfillmentGroupItem(org.broadleafcommerce.core.order.domain.FulfillmentGroupItem) FulfillmentGroup(org.broadleafcommerce.core.order.domain.FulfillmentGroup) 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 35 with DiscreteOrderItem

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

the class OfferServiceUtilitiesImpl method isAddOnOrderItem.

@Override
public boolean isAddOnOrderItem(OrderItem orderItem) {
    if (DiscreteOrderItem.class.isAssignableFrom(orderItem.getClass())) {
        DiscreteOrderItem discreteOrderItem = (DiscreteOrderItem) orderItem;
        Map<String, String> attributes = discreteOrderItem.getAdditionalAttributes();
        boolean isAddOnOrderItem = attributes.containsKey("addOnXrefId");
        boolean isChildOrderItem = discreteOrderItem.isChildOrderItem();
        return isChildOrderItem && isAddOnOrderItem;
    }
    return false;
}
Also used : DiscreteOrderItem(org.broadleafcommerce.core.order.domain.DiscreteOrderItem)

Aggregations

DiscreteOrderItem (org.broadleafcommerce.core.order.domain.DiscreteOrderItem)57 BundleOrderItem (org.broadleafcommerce.core.order.domain.BundleOrderItem)30 OrderItem (org.broadleafcommerce.core.order.domain.OrderItem)27 Order (org.broadleafcommerce.core.order.domain.Order)19 ArrayList (java.util.ArrayList)18 FulfillmentGroupItem (org.broadleafcommerce.core.order.domain.FulfillmentGroupItem)18 FulfillmentGroup (org.broadleafcommerce.core.order.domain.FulfillmentGroup)17 Sku (org.broadleafcommerce.core.catalog.domain.Sku)16 HashMap (java.util.HashMap)11 OrderItemRequestDTO (org.broadleafcommerce.core.order.service.call.OrderItemRequestDTO)10 Money (org.broadleafcommerce.common.money.Money)9 Product (org.broadleafcommerce.core.catalog.domain.Product)9 DiscreteOrderItemImpl (org.broadleafcommerce.core.order.domain.DiscreteOrderItemImpl)8 Transactional (org.springframework.transaction.annotation.Transactional)8 SkuImpl (org.broadleafcommerce.core.catalog.domain.SkuImpl)7 FulfillmentGroupItemImpl (org.broadleafcommerce.core.order.domain.FulfillmentGroupItemImpl)7 GiftWrapOrderItem (org.broadleafcommerce.core.order.domain.GiftWrapOrderItem)7 FulfillmentGroupImpl (org.broadleafcommerce.core.order.domain.FulfillmentGroupImpl)6 List (java.util.List)5 ProductBundle (org.broadleafcommerce.core.catalog.domain.ProductBundle)5