use of org.broadleafcommerce.core.order.domain.FulfillmentGroupItem in project BroadleafCommerce by BroadleafCommerce.
the class AddWorkflowPriceOrderIfNecessaryActivity method getOiFgiMap.
protected void getOiFgiMap(Order order, Map<OrderItem, List<FulfillmentGroupItem>> oiFgiMap, OrderItem oi) {
List<FulfillmentGroupItem> fgis = new ArrayList<>();
for (FulfillmentGroup fg : order.getFulfillmentGroups()) {
for (FulfillmentGroupItem fgi : fg.getFulfillmentGroupItems()) {
if (fgi.getOrderItem().equals(oi)) {
fgis.add(fgi);
}
}
}
oiFgiMap.put(oi, fgis);
}
use of org.broadleafcommerce.core.order.domain.FulfillmentGroupItem in project BroadleafCommerce by BroadleafCommerce.
the class OfferTest method createFulfillmentGroups.
private List<FulfillmentGroup> createFulfillmentGroups(FulfillmentOption option, Double shippingPrice, Order order) {
List<FulfillmentGroup> groups = new ArrayList<FulfillmentGroup>();
FulfillmentGroup group = new FulfillmentGroupImpl();
group.setFulfillmentOption(option);
groups.add(group);
group.setRetailShippingPrice(new Money(shippingPrice));
group.setOrder(order);
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");
Country country = new CountryImpl();
country.setAbbreviation("US");
country.setName("United States");
countryService.save(country);
ISOCountry isoCountry = new ISOCountryImpl();
isoCountry.setAlpha2("US");
isoCountry.setName("UNITED STATES");
isoService.save(isoCountry);
State state = new StateImpl();
state.setAbbreviation("TX");
state.setName("Texas");
state.setCountry(country);
stateService.save(state);
address.setState(state);
address.setCountry(country);
address.setIsoCountrySubdivision("US-TX");
address.setIsoCountryAlpha2(isoCountry);
for (OrderItem orderItem : order.getOrderItems()) {
FulfillmentGroupItem fgItem = new FulfillmentGroupItemImpl();
fgItem.setFulfillmentGroup(group);
fgItem.setOrderItem(orderItem);
fgItem.setQuantity(orderItem.getQuantity());
group.addFulfillmentGroupItem(fgItem);
}
group.setAddress(address);
return groups;
}
use of org.broadleafcommerce.core.order.domain.FulfillmentGroupItem in project BroadleafCommerce by BroadleafCommerce.
the class FulfillmentGroupItemDaoTest method createFulfillmentGroupItem.
@Test(groups = { "createFulfillmentGroupItem" }, dataProvider = "basicDiscreteOrderItem", dataProviderClass = OrderItemDataProvider.class, dependsOnGroups = { "createOrder", "createSku", "createItemFulfillmentGroup" })
@Rollback(false)
@Transactional
public void createFulfillmentGroupItem(DiscreteOrderItem orderItem) throws PricingException {
Sku si = skuDao.readFirstSku();
orderItem.setSku(si);
orderItem = (DiscreteOrderItem) orderItemDao.save(orderItem);
orderItem.setOrder(salesOrder);
salesOrder.addOrderItem(orderItem);
orderDao.save(salesOrder);
FulfillmentGroupItemRequest fulfillmentGroupItemRequest = new FulfillmentGroupItemRequest();
fulfillmentGroupItemRequest.setOrderItem(orderItem);
fulfillmentGroupItemRequest.setFulfillmentGroup(fulfillmentGroup);
fulfillmentGroupService.addItemToFulfillmentGroup(fulfillmentGroupItemRequest, true);
FulfillmentGroupItem fgi = fulfillmentGroup.getFulfillmentGroupItems().get(fulfillmentGroup.getFulfillmentGroupItems().size() - 1);
assert fgi.getId() != null;
fulfillmentGroupItemId = fgi.getId();
}
use of org.broadleafcommerce.core.order.domain.FulfillmentGroupItem in project BroadleafCommerce by BroadleafCommerce.
the class FulfillmentItemPricingActivityTest method testDistributeOneDollarAcrossFiveEqualItems.
public void testDistributeOneDollarAcrossFiveEqualItems() throws Exception {
Order order = dataProvider.createBasicOrder();
Money subTotal = new Money(order.getCurrency());
for (OrderItem orderItem : order.getOrderItems()) {
orderItem.setSalePrice(new Money(10D));
orderItem.getOrderItemPriceDetails().clear();
subTotal = subTotal.add(orderItem.getTotalPrice());
}
OrderAdjustment adjustment = new OrderAdjustmentImpl();
adjustment.setValue(new Money(new BigDecimal("1"), order.getCurrency()));
order.getOrderAdjustments().add(adjustment);
adjustment.setOrder(order);
order.setSubTotal(subTotal);
ProcessContext<Order> context = new DefaultProcessContextImpl<Order>();
context.setSeedData(order);
fulfillmentItemPricingActivity.execute(context);
// Each item is equally priced, so the adjustment should be .20 per item.
Money proratedAdjustment = new Money(".20");
for (FulfillmentGroup fulfillmentGroup : order.getFulfillmentGroups()) {
for (FulfillmentGroupItem fulfillmentGroupItem : fulfillmentGroup.getFulfillmentGroupItems()) {
assertTrue(fulfillmentGroupItem.getProratedOrderAdjustmentAmount().compareTo(proratedAdjustment.multiply(fulfillmentGroupItem.getQuantity())) == 0);
}
}
}
use of org.broadleafcommerce.core.order.domain.FulfillmentGroupItem 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;*/
}
Aggregations