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;
}
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;
}
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;
}
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;*/
}
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;
}
Aggregations