Search in sources :

Example 66 with OrderItem

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

the class UpdateOrderMultishipOptionActivity method execute.

@Override
public ProcessContext<CartOperationRequest> execute(ProcessContext<CartOperationRequest> context) throws Exception {
    CartOperationRequest request = context.getSeedData();
    Long orderItemId = request.getItemRequest().getOrderItemId();
    Integer orderItemQuantityDelta = request.getOrderItemQuantityDelta();
    if (orderItemQuantityDelta < 0) {
        int numToDelete = -1 * orderItemQuantityDelta;
        // find the qty in the default fg
        OrderItem orderItem = request.getOrderItem();
        int qty = 0;
        if (!CollectionUtils.isEmpty(orderItem.getOrder().getFulfillmentGroups())) {
            FulfillmentGroup fg = orderItem.getOrder().getFulfillmentGroups().get(0);
            if (fg.getAddress() == null && fg.getFulfillmentOption() == null) {
                for (FulfillmentGroupItem fgItem : fg.getFulfillmentGroupItems()) {
                    if (fgItem.getOrderItem().getId().equals(orderItemId)) {
                        qty += fgItem.getQuantity();
                    }
                }
            }
        }
        if (numToDelete >= qty) {
            request.getMultishipOptionsToDelete().add(new Long[] { orderItemId, (long) (numToDelete - qty) });
        }
    }
    return context;
}
Also used : CartOperationRequest(org.broadleafcommerce.core.order.service.workflow.CartOperationRequest) OrderItem(org.broadleafcommerce.core.order.domain.OrderItem) FulfillmentGroupItem(org.broadleafcommerce.core.order.domain.FulfillmentGroupItem) FulfillmentGroup(org.broadleafcommerce.core.order.domain.FulfillmentGroup)

Example 67 with OrderItem

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

the class PricingTest method testShipping.

@Test(groups = { "testShipping" }, dependsOnGroups = { "testShippingInsert", "createCustomerIdGeneration" })
@Transactional
public void testShipping() throws Exception {
    Order order = orderService.createNewCartForCustomer(createCustomer());
    customerService.saveCustomer(order.getCustomer());
    FulfillmentGroup group1 = new FulfillmentGroupImpl();
    FulfillmentGroup group2 = new FulfillmentGroupImpl();
    // setup group1 - standard
    group1.setMethod("standard");
    group1.setService(ShippingServiceType.BANDED_SHIPPING.getType());
    Country country = new CountryImpl();
    country.setAbbreviation("US");
    country.setName("United States");
    country = countryService.save(country);
    ISOCountry isoCountry = new ISOCountryImpl();
    isoCountry.setAlpha2("US");
    isoCountry.setName("UNITED STATES");
    isoCountry = isoService.save(isoCountry);
    State state = new StateImpl();
    state.setAbbreviation("TX");
    state.setName("Texas");
    state.setCountry(country);
    state = stateService.save(state);
    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(state);
    address.setCountry(country);
    address.setIsoCountrySubdivision("US-TX");
    address.setIsoCountryAlpha2(isoCountry);
    group1.setAddress(address);
    group1.setOrder(order);
    // setup group2 - truck
    group2.setMethod("truck");
    group2.setService(ShippingServiceType.BANDED_SHIPPING.getType());
    group2.setOrder(order);
    List<FulfillmentGroup> groups = new ArrayList<>();
    groups.add(group1);
    // groups.add(group2);
    order.setFulfillmentGroups(groups);
    Money total = new Money(8.5D);
    group1.setShippingPrice(total);
    group2.setShippingPrice(total);
    // group1.setTotalTax(new Money(1D));
    // group2.setTotalTax(new Money(1D));
    order.setSubTotal(total);
    order.setTotal(total);
    DiscreteOrderItem item = new DiscreteOrderItemImpl();
    Sku sku = new SkuImpl();
    sku.setRetailPrice(new Money(15D));
    sku.setDiscountable(true);
    sku.setName("Test Sku");
    sku = catalogService.saveSku(sku);
    item.setSku(sku);
    item.setQuantity(1);
    item.setOrder(order);
    item = (DiscreteOrderItem) orderItemService.saveOrderItem(item);
    List<OrderItem> items = new ArrayList<>();
    items.add(item);
    order.setOrderItems(items);
    for (OrderItem orderItem : items) {
        FulfillmentGroupItem fgi = new FulfillmentGroupItemImpl();
        fgi.setOrderItem(orderItem);
        fgi.setQuantity(orderItem.getQuantity());
        fgi.setFulfillmentGroup(group1);
        // fgi.setRetailPrice(new Money(15D));
        group1.addFulfillmentGroupItem(fgi);
    }
    order.setTotalShipping(new Money(0D));
    orderService.save(order, true);
    assert (order.getTotal().greaterThan(order.getSubTotal()));
    // Shipping price is not taxable
    assert (order.getTotalTax().equals(order.getSubTotal().multiply(0.05D)));
    assert (order.getTotal().equals(order.getSubTotal().add(order.getTotalTax().add(order.getTotalShipping()))));
}
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) DiscreteOrderItemImpl(org.broadleafcommerce.core.order.domain.DiscreteOrderItemImpl) StateImpl(org.broadleafcommerce.profile.core.domain.StateImpl) ArrayList(java.util.ArrayList) Money(org.broadleafcommerce.common.money.Money) SkuImpl(org.broadleafcommerce.core.catalog.domain.SkuImpl) ISOCountryImpl(org.broadleafcommerce.common.i18n.domain.ISOCountryImpl) CountryImpl(org.broadleafcommerce.profile.core.domain.CountryImpl) State(org.broadleafcommerce.profile.core.domain.State) OrderItem(org.broadleafcommerce.core.order.domain.OrderItem) DiscreteOrderItem(org.broadleafcommerce.core.order.domain.DiscreteOrderItem) FulfillmentGroupItem(org.broadleafcommerce.core.order.domain.FulfillmentGroupItem) Country(org.broadleafcommerce.profile.core.domain.Country) ISOCountry(org.broadleafcommerce.common.i18n.domain.ISOCountry) AddressImpl(org.broadleafcommerce.profile.core.domain.AddressImpl) FulfillmentGroup(org.broadleafcommerce.core.order.domain.FulfillmentGroup) ISOCountryImpl(org.broadleafcommerce.common.i18n.domain.ISOCountryImpl) Sku(org.broadleafcommerce.core.catalog.domain.Sku) ISOCountry(org.broadleafcommerce.common.i18n.domain.ISOCountry) FulfillmentGroupItemImpl(org.broadleafcommerce.core.order.domain.FulfillmentGroupItemImpl) Test(org.testng.annotations.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 68 with OrderItem

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

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

the class OrderItemDaoTest method deleteGiftWrapOrderItemsById.

@Test(groups = { "deleteGiftWrapOrderItemsById" }, dependsOnGroups = { "readGiftWrapOrderItemsById" })
@Rollback(false)
public void deleteGiftWrapOrderItemsById() {
    OrderItem result = orderItemDao.readOrderItemById(giftWrapItemId);
    orderItemDao.delete(result);
    assert orderItemDao.readOrderItemById(giftWrapItemId) == null;
}
Also used : DiscreteOrderItem(org.broadleafcommerce.core.order.domain.DiscreteOrderItem) OrderItem(org.broadleafcommerce.core.order.domain.OrderItem) GiftWrapOrderItem(org.broadleafcommerce.core.order.domain.GiftWrapOrderItem) Test(org.testng.annotations.Test) Rollback(org.springframework.test.annotation.Rollback)

Example 70 with OrderItem

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

the class CartTest method testAddAllItemsToCartFromNamedOrderWithoutExistingCart.

@Test(groups = { "testCartAndNamedOrder" })
@Transactional
public void testAddAllItemsToCartFromNamedOrderWithoutExistingCart() throws RemoveFromCartException, AddToCartException {
    Order namedOrder = setUpNamedOrder();
    List<OrderItem> namedOrderItems = new ArrayList<>();
    namedOrderItems.addAll(namedOrder.getOrderItems());
    orderService.setMoveNamedOrderItems(false);
    Order cart = orderService.addAllItemsFromNamedOrder(namedOrder, true);
    orderService.setMoveNamedOrderItems(true);
    assert cartContainsOnlyTheseItems(cart, namedOrderItems);
}
Also used : Order(org.broadleafcommerce.core.order.domain.Order) DiscreteOrderItem(org.broadleafcommerce.core.order.domain.DiscreteOrderItem) OrderItem(org.broadleafcommerce.core.order.domain.OrderItem) ArrayList(java.util.ArrayList) Test(org.testng.annotations.Test) 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