Search in sources :

Example 11 with OrderItemRequestDTO

use of org.broadleafcommerce.core.order.service.call.OrderItemRequestDTO in project BroadleafCommerce by BroadleafCommerce.

the class OrderBaseTest method setUpCartWithInactiveSku.

public Order setUpCartWithInactiveSku() throws AddToCartException {
    Customer customer = customerService.saveCustomer(createNamedCustomer());
    Order order = orderService.createNewCartForCustomer(customer);
    Product newProduct = addTestProduct("Plastic Crate Should Be Inactive", "Crates");
    Category newCategory = newProduct.getDefaultCategory();
    order = orderService.addItem(order.getId(), new OrderItemRequestDTO(newProduct.getId(), newProduct.getDefaultSku().getId(), newCategory.getId(), 1), true);
    // Make the SKU inactive
    newProduct.getDefaultSku().setActiveEndDate(DateUtils.addDays(new Date(), -1));
    catalogService.saveSku(newProduct.getDefaultSku());
    return order;
}
Also used : Order(org.broadleafcommerce.core.order.domain.Order) Category(org.broadleafcommerce.core.catalog.domain.Category) OrderItemRequestDTO(org.broadleafcommerce.core.order.service.call.OrderItemRequestDTO) Customer(org.broadleafcommerce.profile.core.domain.Customer) Product(org.broadleafcommerce.core.catalog.domain.Product) Date(java.util.Date)

Example 12 with OrderItemRequestDTO

use of org.broadleafcommerce.core.order.service.call.OrderItemRequestDTO in project BroadleafCommerce by BroadleafCommerce.

the class OrderTest method testIllegalAddScenarios.

@Test(groups = { "testIllegalAddScenarios" }, dependsOnGroups = { "addItemToOrder" })
@Transactional
public void testIllegalAddScenarios() throws AddToCartException {
    Order order = orderService.findOrderById(orderId);
    assert order != null;
    Product activeProduct = addTestProduct("mug", "cups", true);
    Product inactiveProduct = addTestProduct("cup", "cups", false);
    // Inactive skus should not be added
    OrderItemRequestDTO itemRequest = new OrderItemRequestDTO().setQuantity(1).setSkuId(inactiveProduct.getDefaultSku().getId());
    boolean addSuccessful = true;
    try {
        order = orderService.addItem(orderId, itemRequest, true);
    } catch (AddToCartException e) {
        addSuccessful = false;
    }
    assert !addSuccessful;
    // Products that have SKUs marked as inactive should not be added either
    itemRequest = new OrderItemRequestDTO().setQuantity(1).setProductId(inactiveProduct.getId());
    addSuccessful = true;
    try {
        order = orderService.addItem(orderId, itemRequest, true);
    } catch (AddToCartException e) {
        addSuccessful = false;
    }
    assert !addSuccessful;
    // Negative quantities are not allowed
    itemRequest = new OrderItemRequestDTO().setQuantity(-1).setSkuId(activeProduct.getDefaultSku().getId());
    addSuccessful = true;
    try {
        order = orderService.addItem(orderId, itemRequest, true);
    } catch (AddToCartException e) {
        addSuccessful = false;
        assert e.getCause() instanceof IllegalArgumentException;
    }
    assert !addSuccessful;
    // Order must exist
    itemRequest = new OrderItemRequestDTO().setQuantity(1).setSkuId(activeProduct.getDefaultSku().getId());
    addSuccessful = true;
    try {
        order = orderService.addItem(-1L, itemRequest, true);
    } catch (AddToCartException e) {
        addSuccessful = false;
        assert e.getCause() instanceof IllegalArgumentException;
    }
    assert !addSuccessful;
    // If a product is provided, it must exist
    itemRequest = new OrderItemRequestDTO().setQuantity(1).setProductId(-1L);
    addSuccessful = true;
    try {
        order = orderService.addItem(orderId, itemRequest, true);
    } catch (AddToCartException e) {
        addSuccessful = false;
        assert e.getCause() instanceof IllegalArgumentException;
    }
    assert !addSuccessful;
    // The SKU must exist
    itemRequest = new OrderItemRequestDTO().setQuantity(1).setSkuId(-1L);
    addSuccessful = true;
    try {
        order = orderService.addItem(orderId, itemRequest, true);
    } catch (AddToCartException e) {
        addSuccessful = false;
        assert e.getCause() instanceof IllegalArgumentException;
    }
    assert !addSuccessful;
}
Also used : Order(org.broadleafcommerce.core.order.domain.Order) OrderItemRequestDTO(org.broadleafcommerce.core.order.service.call.OrderItemRequestDTO) AddToCartException(org.broadleafcommerce.core.order.service.exception.AddToCartException) Product(org.broadleafcommerce.core.catalog.domain.Product) Test(org.testng.annotations.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 13 with OrderItemRequestDTO

use of org.broadleafcommerce.core.order.service.call.OrderItemRequestDTO in project BroadleafCommerce by BroadleafCommerce.

the class OrderTest method addBundleToOrder.

@Test(groups = { "addBundleToOrder" }, dependsOnGroups = { "addAnotherItemToOrder" })
@Rollback(false)
@Transactional
public void addBundleToOrder() throws AddToCartException {
    numOrderItems++;
    Sku sku = skuDao.readFirstSku();
    Order order = orderService.findOrderById(orderId);
    assert order != null;
    assert sku.getId() != null;
    ProductBundle bundleItem = addProductBundle();
    OrderItemRequestDTO orderItemRequestDTO = new OrderItemRequestDTO();
    orderItemRequestDTO.setProductId(bundleItem.getId());
    orderItemRequestDTO.setSkuId(bundleItem.getDefaultSku().getId());
    orderItemRequestDTO.setQuantity(1);
    order = orderService.addItem(order.getId(), orderItemRequestDTO, true);
    BundleOrderItem item = (BundleOrderItem) orderService.findLastMatchingItem(order, bundleItem.getDefaultSku().getId(), null);
    bundleOrderItemId = item.getId();
    assert item != null;
    assert item.getQuantity() == 1;
    assert item.getDiscreteOrderItems().size() == 1;
}
Also used : Order(org.broadleafcommerce.core.order.domain.Order) OrderItemRequestDTO(org.broadleafcommerce.core.order.service.call.OrderItemRequestDTO) BundleOrderItem(org.broadleafcommerce.core.order.domain.BundleOrderItem) ProductBundle(org.broadleafcommerce.core.catalog.domain.ProductBundle) 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 14 with OrderItemRequestDTO

use of org.broadleafcommerce.core.order.service.call.OrderItemRequestDTO in project BroadleafCommerce by BroadleafCommerce.

the class OrderTest method updateItemsInOrder.

@Test(groups = { "updateItemsInOrder" }, dependsOnGroups = { "getItemsForOrder" })
@Transactional
public void updateItemsInOrder() throws UpdateCartException, RemoveFromCartException {
    // Grab the order and the first OrderItem
    Order order = orderService.findOrderById(orderId);
    List<OrderItem> orderItems = order.getOrderItems();
    assert orderItems.size() > 0;
    OrderItem item = orderItems.get(0);
    // Set the quantity of the first OrderItem to 10
    OrderItemRequestDTO orderItemRequestDTO = new OrderItemRequestDTO();
    orderItemRequestDTO.setOrderItemId(item.getId());
    orderItemRequestDTO.setQuantity(10);
    order = orderService.updateItemQuantity(order.getId(), orderItemRequestDTO, true);
    // Assert that the quantity has changed
    OrderItem updatedItem = orderItemService.readOrderItemById(item.getId());
    assert updatedItem != null;
    assert updatedItem.getQuantity() == 10;
    // Assert that the appropriate fulfillment group item has changed
    assert order.getFulfillmentGroups().size() == 1;
    FulfillmentGroup fg = order.getFulfillmentGroups().get(0);
    assert fg.getFulfillmentGroupItems().size() == 1;
    boolean fgItemUpdated = false;
    for (FulfillmentGroupItem fgi : fg.getFulfillmentGroupItems()) {
        if (fgi.getOrderItem().equals(updatedItem)) {
            assert fgi.getQuantity() == 10;
            fgItemUpdated = true;
        }
    }
    assert fgItemUpdated;
    // Set the quantity of the first OrderItem to 5
    orderItemRequestDTO = new OrderItemRequestDTO();
    orderItemRequestDTO.setOrderItemId(item.getId());
    orderItemRequestDTO.setQuantity(5);
    order = orderService.updateItemQuantity(order.getId(), orderItemRequestDTO, true);
    // Assert that the quantity has changed - going to a smaller quantity is also ok
    updatedItem = orderItemService.readOrderItemById(item.getId());
    assert updatedItem != null;
    assert updatedItem.getQuantity() == 5;
    // Assert that the appropriate fulfillment group item has changed
    assert order.getFulfillmentGroups().size() == 1;
    fg = order.getFulfillmentGroups().get(0);
    assert fg.getFulfillmentGroupItems().size() == 1;
    fgItemUpdated = false;
    for (FulfillmentGroupItem fgi : fg.getFulfillmentGroupItems()) {
        if (fgi.getOrderItem().equals(updatedItem)) {
            assert fgi.getQuantity() == 5;
            fgItemUpdated = true;
        }
    }
    assert fgItemUpdated;
    // Setting the quantity to 0 should in fact remove the item completely
    int startingSize = order.getOrderItems().size();
    orderItemRequestDTO = new OrderItemRequestDTO();
    orderItemRequestDTO.setOrderItemId(item.getId());
    orderItemRequestDTO.setQuantity(0);
    order = orderService.updateItemQuantity(order.getId(), orderItemRequestDTO, true);
    // Assert that the item has been removed
    updatedItem = orderItemService.readOrderItemById(item.getId());
    assert updatedItem == null;
    assert order.getOrderItems().size() == startingSize - 1;
    // Assert that the appropriate fulfillment group item has been removed
    assert order.getFulfillmentGroups().size() == 0;
/*
        TODO Since we commented out some tests above, there is no longer an additional item
        in the cart, hence the fulfillment group is removed

        fg = order.getFulfillmentGroups().get(0);
        assert fg.getFulfillmentGroupItems().size() == startingSize - 1;
        boolean fgItemRemoved = true;
        for (FulfillmentGroupItem fgi : fg.getFulfillmentGroupItems()) {
            if (fgi.getOrderItem().equals(updatedItem)) {
                fgItemRemoved = false;
            }
        }
        assert fgItemRemoved;*/
}
Also used : Order(org.broadleafcommerce.core.order.domain.Order) OrderItemRequestDTO(org.broadleafcommerce.core.order.service.call.OrderItemRequestDTO) 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) FulfillmentGroup(org.broadleafcommerce.core.order.domain.FulfillmentGroup) Test(org.testng.annotations.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 15 with OrderItemRequestDTO

use of org.broadleafcommerce.core.order.service.call.OrderItemRequestDTO in project BroadleafCommerce by BroadleafCommerce.

the class OrderTest method testIllegalUpdateScenarios.

@Test(groups = { "testIllegalUpdateScenarios" }, dependsOnGroups = { "addItemToOrder" })
@Transactional
public void testIllegalUpdateScenarios() throws UpdateCartException, AddToCartException, RemoveFromCartException {
    Order order = orderService.findOrderById(orderId);
    assert order != null;
    Product activeProduct = addTestProduct("mug", "cups", true);
    Product inactiveProduct = addTestProduct("cup", "cups", false);
    // Inactive skus should not be added
    OrderItemRequestDTO itemRequest = new OrderItemRequestDTO().setQuantity(1).setSkuId(activeProduct.getDefaultSku().getId());
    boolean addSuccessful = true;
    try {
        order = orderService.addItem(orderId, itemRequest, true);
    } catch (AddToCartException e) {
        addSuccessful = false;
    }
    assert addSuccessful;
    // should not be able to update to negative quantity
    OrderItem item = orderService.findLastMatchingItem(order, activeProduct.getDefaultSku().getId(), activeProduct.getId());
    itemRequest = new OrderItemRequestDTO().setQuantity(-3).setOrderItemId(item.getId());
    boolean updateSuccessful = true;
    try {
        orderService.updateItemQuantity(orderId, itemRequest, true);
    } catch (UpdateCartException e) {
        updateSuccessful = false;
    }
    assert !updateSuccessful;
    // shouldn't be able to update the quantity of a DOI inside of a bundle
    ProductBundle bundle = addProductBundle();
    itemRequest = new OrderItemRequestDTO().setQuantity(1).setProductId(bundle.getId()).setSkuId(bundle.getDefaultSku().getId());
    addSuccessful = true;
    try {
        order = orderService.addItem(orderId, itemRequest, true);
    } catch (AddToCartException e) {
        addSuccessful = false;
    }
    assert addSuccessful;
    BundleOrderItem bundleItem = (BundleOrderItem) orderService.findLastMatchingItem(order, bundle.getDefaultSku().getId(), bundle.getId());
    // should just be a single DOI inside the bundle
    DiscreteOrderItem doi = bundleItem.getDiscreteOrderItems().get(0);
    itemRequest = new OrderItemRequestDTO().setQuantity(4).setOrderItemId(doi.getId());
    try {
        orderService.updateItemQuantity(orderId, itemRequest, true);
    } catch (UpdateCartException e) {
        updateSuccessful = false;
    }
    assert !updateSuccessful;
}
Also used : Order(org.broadleafcommerce.core.order.domain.Order) DiscreteOrderItem(org.broadleafcommerce.core.order.domain.DiscreteOrderItem) OrderItemRequestDTO(org.broadleafcommerce.core.order.service.call.OrderItemRequestDTO) BundleOrderItem(org.broadleafcommerce.core.order.domain.BundleOrderItem) AddToCartException(org.broadleafcommerce.core.order.service.exception.AddToCartException) DiscreteOrderItem(org.broadleafcommerce.core.order.domain.DiscreteOrderItem) OrderItem(org.broadleafcommerce.core.order.domain.OrderItem) BundleOrderItem(org.broadleafcommerce.core.order.domain.BundleOrderItem) ProductBundle(org.broadleafcommerce.core.catalog.domain.ProductBundle) Product(org.broadleafcommerce.core.catalog.domain.Product) UpdateCartException(org.broadleafcommerce.core.order.service.exception.UpdateCartException) Test(org.testng.annotations.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

OrderItemRequestDTO (org.broadleafcommerce.core.order.service.call.OrderItemRequestDTO)30 Order (org.broadleafcommerce.core.order.domain.Order)19 DiscreteOrderItem (org.broadleafcommerce.core.order.domain.DiscreteOrderItem)14 OrderItem (org.broadleafcommerce.core.order.domain.OrderItem)13 Transactional (org.springframework.transaction.annotation.Transactional)10 CartOperationRequest (org.broadleafcommerce.core.order.service.workflow.CartOperationRequest)9 Product (org.broadleafcommerce.core.catalog.domain.Product)8 BundleOrderItem (org.broadleafcommerce.core.order.domain.BundleOrderItem)8 Test (org.testng.annotations.Test)7 Sku (org.broadleafcommerce.core.catalog.domain.Sku)6 NonDiscreteOrderItemRequestDTO (org.broadleafcommerce.core.order.service.call.NonDiscreteOrderItemRequestDTO)5 FulfillmentGroup (org.broadleafcommerce.core.order.domain.FulfillmentGroup)4 FulfillmentGroupItem (org.broadleafcommerce.core.order.domain.FulfillmentGroupItem)4 ArrayList (java.util.ArrayList)3 Category (org.broadleafcommerce.core.catalog.domain.Category)3 ConfigurableOrderItemRequest (org.broadleafcommerce.core.order.service.call.ConfigurableOrderItemRequest)3 AddToCartException (org.broadleafcommerce.core.order.service.exception.AddToCartException)3 Customer (org.broadleafcommerce.profile.core.domain.Customer)3 Rollback (org.springframework.test.annotation.Rollback)3 ProductBundle (org.broadleafcommerce.core.catalog.domain.ProductBundle)2