use of org.broadleafcommerce.core.order.domain.OrderItem 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.OrderItem in project BroadleafCommerce by BroadleafCommerce.
the class OfferDataItemProvider method getAddOrderItemToOrderAnswer.
public static IAnswer<OrderItem> getAddOrderItemToOrderAnswer() {
return new IAnswer<OrderItem>() {
@Override
public OrderItem answer() throws Throwable {
Order order = (Order) EasyMock.getCurrentArguments()[0];
order.getOrderItems().add((OrderItem) EasyMock.getCurrentArguments()[1]);
if (((OrderItem) EasyMock.getCurrentArguments()[1]).getId() == null) {
((OrderItem) EasyMock.getCurrentArguments()[1]).setId(OfferDataItemProvider.getOrderItemId());
}
return (OrderItem) EasyMock.getCurrentArguments()[1];
}
};
}
use of org.broadleafcommerce.core.order.domain.OrderItem 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.OrderItem in project BroadleafCommerce by BroadleafCommerce.
the class MVELTest method testOfferAppliesToHatsWhenOneLawnmowerIsPurchased.
// @Test
// TODO fix this test
public void testOfferAppliesToHatsWhenOneLawnmowerIsPurchased() {
OrderImpl order = new OrderImpl();
ArrayList<OrderItem> items = new ArrayList<>();
order.setOrderItems(items);
DiscreteOrderItemImpl item = new DiscreteOrderItemImpl();
Money amount = new Money(10D);
items.add(item);
item.setSalePrice(amount);
ProductImpl product = new ProductImpl();
CategoryImpl category = new CategoryImpl();
category.setName("hat");
product.setDefaultCategory(category);
item.setProduct(product);
item.setQuantity(3);
DiscreteOrderItemImpl item2 = new DiscreteOrderItemImpl();
Money amount2 = new Money(250D);
items.add(item2);
item2.setSalePrice(amount2);
ProductImpl product2 = new ProductImpl();
CategoryImpl category2 = new CategoryImpl();
category2.setName("lawnmower");
product2.setDefaultCategory(category2);
item2.setProduct(product2);
item2.setQuantity(1);
HashMap<String, Object> vars = new HashMap<>();
vars.put("currentItem", item);
vars.put("order", order);
vars.put("doMark", false);
// This test makes use of the static MVEL function "orderContains(quantity)".
StringBuffer expression = new StringBuffer(functions);
expression.append("def evalItemForOrderContains(item) {").append(" return item.product.defaultCategory.name == 'lawnmower'").append(" } ").append(" return (orderContainsPlusMark(1) and currentItem.product.defaultCategory.name == 'hat');");
Boolean result = (Boolean) MVEL.eval(expression.toString(), vars);
assert result != null && result;
}
use of org.broadleafcommerce.core.order.domain.OrderItem 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;
}
Aggregations