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;
}
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()))));
}
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();
}
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;
}
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);
}
Aggregations