use of org.broadleafcommerce.core.order.domain.FulfillmentGroupItem in project BroadleafCommerce by BroadleafCommerce.
the class OfferDataItemProvider method getRemoveItemFromOrderAnswer.
public static IAnswer<Order> getRemoveItemFromOrderAnswer() {
return new IAnswer<Order>() {
@Override
public Order answer() throws Throwable {
Long orderId = (Long) EasyMock.getCurrentArguments()[0];
Order order = orders.get(orderId);
Iterator<OrderItem> orderItemItr = order.getOrderItems().listIterator();
while (orderItemItr.hasNext()) {
OrderItem item = orderItemItr.next();
if (item.getId().equals(EasyMock.getCurrentArguments()[1])) {
orderItemItr.remove();
}
}
for (FulfillmentGroup fg : order.getFulfillmentGroups()) {
Iterator<FulfillmentGroupItem> itr = fg.getFulfillmentGroupItems().iterator();
while (itr.hasNext()) {
if (itr.next().getOrderItem().getId().equals(EasyMock.getCurrentArguments()[1])) {
itr.remove();
}
}
}
return order;
}
};
}
use of org.broadleafcommerce.core.order.domain.FulfillmentGroupItem in project BroadleafCommerce by BroadleafCommerce.
the class CheckoutTest method addSampleItemToOrder.
private void addSampleItemToOrder(Order order, FulfillmentGroup group) {
DiscreteOrderItem item = new DiscreteOrderItemImpl();
item.setOrder(order);
item.setQuantity(1);
Sku newSku = new SkuImpl();
newSku.setName("Under Armor T-Shirt -- Red");
newSku.setRetailPrice(new Money(14.99));
newSku.setActiveStartDate(SystemTime.asDate());
newSku.setDiscountable(false);
newSku = catalogService.saveSku(newSku);
item.setSku(newSku);
item = (DiscreteOrderItem) orderItemService.saveOrderItem(item);
List<OrderItem> items = new ArrayList<>();
items.add(item);
order.setOrderItems(items);
FulfillmentGroupItem fgItem = new FulfillmentGroupItemImpl();
fgItem.setFulfillmentGroup(group);
fgItem.setOrderItem(item);
fgItem.setQuantity(1);
// fgItem.setPrice(new Money(0D));
group.addFulfillmentGroupItem(fgItem);
}
use of org.broadleafcommerce.core.order.domain.FulfillmentGroupItem in project BroadleafCommerce by BroadleafCommerce.
the class OfferServiceTest method testOrderItemOfferWithGiftWrap.
@Test(groups = { "testOffersWithGiftWrap" }, dependsOnGroups = { "testShippingInsert" })
@Transactional
public void testOrderItemOfferWithGiftWrap() throws PricingException {
Order order = createTestOrderWithOfferAndGiftWrap();
OfferDataItemProvider dataProvider = new OfferDataItemProvider();
List<Offer> offers = dataProvider.createItemBasedOfferWithItemCriteria("order.subTotal.getAmount()>20", OfferDiscountType.PERCENT_OFF, "([MVEL.eval(\"toUpperCase()\",\"Test Sku\")] contains MVEL.eval(\"toUpperCase()\", discreteOrderItem.sku.name))", "([MVEL.eval(\"toUpperCase()\",\"Test Sku\")] contains MVEL.eval(\"toUpperCase()\", discreteOrderItem.sku.name))");
for (Offer offer : offers) {
offer.setName("testOffer");
// //reset the offer is the targets and qualifiers, otherwise the reference is incorrect
// for (OfferItemCriteria criteria : offer.getTargetItemCriteria()) {
// criteria.setTargetOffer(null);
// }
// for (OfferItemCriteria criteria : offer.getQualifyingItemCriteria()) {
// criteria.setQualifyingOffer(null);
// }
offerService.save(offer);
}
order = orderService.save(order, false);
Set<OrderMultishipOption> options = new HashSet<OrderMultishipOption>();
for (FulfillmentGroup fg : order.getFulfillmentGroups()) {
Address address = fg.getAddress();
for (FulfillmentGroupItem fgItem : fg.getFulfillmentGroupItems()) {
for (int j = 0; j < fgItem.getQuantity(); j++) {
OrderMultishipOption option = new OrderMultishipOptionImpl();
option.setOrder(order);
option.setAddress(address);
option.setOrderItem(fgItem.getOrderItem());
option.setFulfillmentOption(fg.getFulfillmentOption());
options.add(option);
}
}
}
for (OrderMultishipOption option : options) {
orderMultishipOptionService.save(option);
}
order = fulfillmentGroupService.matchFulfillmentGroupsToMultishipOptions(order, true);
assert order.getOrderItems().size() == 3;
assert order.getTotalTax().equals(new Money("2.00"));
assert order.getTotalShipping().equals(new Money("8.50"));
assert order.getSubTotal().equals(new Money("40.00"));
assert order.getTotal().equals(new Money("50.50"));
boolean foundGiftItemAndCorrectQuantity = false;
for (OrderItem orderItem : order.getOrderItems()) {
if (orderItem instanceof GiftWrapOrderItem && ((GiftWrapOrderItem) orderItem).getWrappedItems().size() == 1) {
foundGiftItemAndCorrectQuantity = true;
break;
}
}
assert foundGiftItemAndCorrectQuantity;
}
use of org.broadleafcommerce.core.order.domain.FulfillmentGroupItem in project BroadleafCommerce by BroadleafCommerce.
the class LegacyOrderServiceImpl method createFulfillmentGroupItemFromOrderItem.
protected FulfillmentGroupItem createFulfillmentGroupItemFromOrderItem(OrderItem orderItem, FulfillmentGroup fulfillmentGroup, int quantity) {
FulfillmentGroupItem fgi = fulfillmentGroupItemDao.create();
fgi.setFulfillmentGroup(fulfillmentGroup);
fgi.setOrderItem(orderItem);
fgi.setQuantity(quantity);
return fgi;
}
use of org.broadleafcommerce.core.order.domain.FulfillmentGroupItem in project BroadleafCommerce by BroadleafCommerce.
the class FulfillmentGroupItemStrategyImpl method onItemUpdated.
@Override
public CartOperationRequest onItemUpdated(CartOperationRequest request) throws PricingException {
Order order = request.getOrder();
OrderItem orderItem = request.getOrderItem();
Integer orderItemQuantityDelta = request.getOrderItemQuantityDelta();
if (orderItemQuantityDelta == 0) {
// If the quantity didn't change, nothing needs to happen
return request;
} else {
List<FulfillmentGroupItem> fgisToDelete = new ArrayList<FulfillmentGroupItem>();
if (orderItem instanceof BundleOrderItem) {
List<OrderItem> itemsToUpdate = new ArrayList<OrderItem>(((BundleOrderItem) orderItem).getDiscreteOrderItems());
for (OrderItem oi : itemsToUpdate) {
int quantityPer = oi.getQuantity();
fgisToDelete.addAll(updateItemQuantity(order, oi, (quantityPer * orderItemQuantityDelta)));
}
} else {
fgisToDelete.addAll(updateItemQuantity(order, orderItem, orderItemQuantityDelta));
List<OrderItem> itemsToUpdate = new ArrayList<>(orderItem.getChildOrderItems());
for (OrderItem oi : itemsToUpdate) {
int quantityPer = oi.getQuantity() / orderItem.getQuantity();
fgisToDelete.addAll(updateItemQuantity(order, oi, (quantityPer * orderItemQuantityDelta)));
}
}
request.setFgisToDelete(fgisToDelete);
}
return request;
}
Aggregations