@Override public OrderItem clone() { GiftWrapOrderItem orderItem = (GiftWrapOrderItem) super.clone(); if (wrappedItems != null) orderItem.getWrappedItems().addAll(wrappedItems); return orderItem; }
protected boolean updateRetailPrice() { if (isRetailPriceOverride()) { return false; } Money skuRetailPrice = getSku().getRetailPrice(); // Override retail/sale prices from skuBundle. if (skuBundleItem != null) { if (skuBundleItem.getRetailPrice() != null) { skuRetailPrice = skuBundleItem.getRetailPrice(); } } boolean updated = false; //use the sku prices - the retail and sale prices could be null if (skuRetailPrice != null && !skuRetailPrice.getAmount().equals(retailPrice)) { baseRetailPrice = skuRetailPrice.getAmount(); retailPrice = skuRetailPrice.getAmount(); updated = true; } // Adjust prices by adding in fees if they are attached. if (getDiscreteOrderItemFeePrices() != null) { for (DiscreteOrderItemFeePrice fee : getDiscreteOrderItemFeePrices()) { Money returnPrice = convertToMoney(retailPrice); retailPrice = returnPrice.add(fee.getAmount()).getAmount(); } } return updated; }
@Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (!super.equals(obj)) return false; if (!getClass().isAssignableFrom(obj.getClass())) return false; GiftWrapOrderItemImpl other = (GiftWrapOrderItemImpl) obj; if (!super.equals(obj)) { return false; } if (id != null && other.id != null) { return id.equals(other.id); } if (wrappedItems == null) { if (other.wrappedItems != null) return false; } else if (!wrappedItems.equals(other.wrappedItems)) return false; return true; } }
protected boolean updateSalePrice() { if (isSalePriceOverride()) { return false; DynamicSkuPrices priceData = getSku().getPriceData(); if (priceData != null) { skuSalePrice = priceData.getPriceForQuantity(quantity); skuSalePrice = getSku().getSalePrice(); if (getDiscreteOrderItemFeePrices() != null) { for (DiscreteOrderItemFeePrice fee : getDiscreteOrderItemFeePrices()) { Money returnPrice = convertToMoney(salePrice); if (returnPrice != null) { salePrice = returnPrice.add(fee.getAmount()).getAmount();
DiscreteOrderItemImpl orderItem1 = new DiscreteOrderItemImpl(); orderItem1.setCategory(category1); orderItem1.setName("test1"); orderItem1.setOrderItemType(OrderItemType.DISCRETE); orderItem1.setProduct(product1); orderItem1.setQuantity(2); orderItem1.setSku(sku1); orderItem1.setOrder(order);
@Override protected void setUp() throws Exception { PromotableOrder promotableOrder = new PromotableOrderImpl(new OrderImpl(), new PromotableItemFactoryImpl(), false); DiscreteOrderItemImpl discreteOrderItem1 = new DiscreteOrderItemImpl(); discreteOrderItem1.setName("test1"); discreteOrderItem1.setOrderItemType(OrderItemType.DISCRETE); discreteOrderItem1.setQuantity(2); discreteOrderItem1.setRetailPrice(new Money(19.99D)); OrderItemPriceDetail pdetail = new OrderItemPriceDetailImpl(); pdetail.setOrderItem(discreteOrderItem1); pdetail.setQuantity(2); PromotableOrderItem orderItem1 = new PromotableOrderItemImpl(discreteOrderItem1, null, new PromotableItemFactoryImpl(), false); priceDetail1 = new PromotableOrderItemPriceDetailImpl(orderItem1, 2); OfferDataItemProvider dataProvider = new OfferDataItemProvider(); offer = dataProvider.createItemBasedOfferWithItemCriteria( "order.subTotal.getAmount()>20", OfferDiscountType.PERCENT_OFF, "([MVEL.eval(\"toUpperCase()\",\"test1\"), MVEL.eval(\"toUpperCase()\",\"test2\")] contains MVEL.eval(\"toUpperCase()\", discreteOrderItem.category.name))", "([MVEL.eval(\"toUpperCase()\",\"test1\"), MVEL.eval(\"toUpperCase()\",\"test2\")] contains MVEL.eval(\"toUpperCase()\", discreteOrderItem.category.name))" ).get(0); candidateOffer = new PromotableCandidateItemOfferImpl(promotableOrder, offer); }
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);
@DataProvider(name = "basicDiscreteOrderItem") public static Object[][] provideBasicDiscreteSalesOrderItem() { OrderItemImpl soi = new DiscreteOrderItemImpl(); soi.setRetailPrice(new Money(BigDecimal.valueOf(10.25))); soi.setQuantity(3); return new Object[][] { { soi } }; }
@Test public void testOfferAppliesToSpecificItems() { DiscreteOrderItemImpl orderItem = new DiscreteOrderItemImpl(); Sku sku = new SkuImpl(); sku.setRetailPrice(new Money("1")); sku.setId(1234L); orderItem.setSku(sku); OfferImpl offer = new OfferImpl(); offer.setType(OfferType.ORDER_ITEM); //Set up MVEL Context ParserContext context = new ParserContext(); //Import OfferType into the MVEL context since it may be used context.addImport("OfferType", OfferType.class); context.addImport("FulfillmentType", FulfillmentType.class); //Compile the MVEL Expression Serializable domainExp1 = MVEL.compileExpression("offer.type == OfferType.ORDER_ITEM and (currentItem.sku.id in [1234, 2345, 5678])", context); //Add variables to a HashMap that should be passed in to execute the expression HashMap<String, Object> domainVars = new HashMap<>(); domainVars.put("currentItem", orderItem); domainVars.put("offer", offer); //Execute the expression Boolean expressionOutcome1 = (Boolean)MVEL.executeExpression(domainExp1, domainVars); assert expressionOutcome1 != null && expressionOutcome1; }
Product product = createProduct(); DiscreteOrderItemImpl orderItem = new DiscreteOrderItemImpl(); ArrayList<CategoryProductXref> categories = new ArrayList<>(); CategoryProductXref categoryXref = new CategoryProductXrefImpl(); categories.add(categoryXref); product.setAllParentCategoryXrefs(categories); orderItem.setProduct(product);
@Override public CreateResponse<DiscreteOrderItem> createOrRetrieveCopyInstance(MultiTenantCopyContext context) throws CloneNotSupportedException { CreateResponse<DiscreteOrderItem> createResponse = super.createOrRetrieveCopyInstance(context); if (createResponse.isAlreadyPopulated()) { return createResponse; } DiscreteOrderItem cloned = createResponse.getClone(); cloned.setBaseRetailPrice(getBaseRetailPrice()); cloned.setBaseSalePrice(getBaseSalePrice()); cloned.setProduct(product); cloned.setSku(sku); cloned.setCategory(category); ((DiscreteOrderItemImpl)cloned).discountsAllowed = discountsAllowed; cloned.setName(name); // dont clone cloned.setOrder(order); return createResponse; }
@Override public void setSku(Sku sku) { this.sku = sku; Money retail = sku.getBaseRetailPrice(); if (retail != null) { this.baseRetailPrice = retail.getAmount(); } Money sale = sku.getBaseSalePrice(); if (sale != null) { this.baseSalePrice = sale.getAmount(); } this.itemTaxable = sku.isTaxable(); setName(sku.getName()); }
@Override public Money getBaseRetailPrice() { return convertToMoney(baseRetailPrice); }
@Override public CreateResponse<DiscreteOrderItem> createOrRetrieveCopyInstance(MultiTenantCopyContext context) throws CloneNotSupportedException { CreateResponse<DiscreteOrderItem> createResponse = super.createOrRetrieveCopyInstance(context); if (createResponse.isAlreadyPopulated()) { return createResponse; } GiftWrapOrderItem cloned = (GiftWrapOrderItem)createResponse.getClone(); for(OrderItem entry : wrappedItems){ OrderItem clonedEntry = ((OrderItemImpl)entry).createOrRetrieveCopyInstance(context).getClone(); clonedEntry.setGiftWrapOrderItem(cloned); cloned.getWrappedItems().add(clonedEntry); } return createResponse; }
DiscreteOrderItem orderItem = new DiscreteOrderItemImpl(); Sku sku = new SkuImpl();
@Override public Money getBaseSalePrice() { return convertToMoney(baseSalePrice); }
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); }
@Override public OrderItem clone() { DiscreteOrderItem orderItem = (DiscreteOrderItem) super.clone(); if (discreteOrderItemFeePrices != null) { for (DiscreteOrderItemFeePrice feePrice : discreteOrderItemFeePrices) { DiscreteOrderItemFeePrice cloneFeePrice = feePrice.clone(); cloneFeePrice.setDiscreteOrderItem(orderItem); orderItem.getDiscreteOrderItemFeePrices().add(cloneFeePrice); } } if (additionalAttributes != null) { orderItem.getAdditionalAttributes().putAll(additionalAttributes); } orderItem.setBaseRetailPrice(convertToMoney(baseRetailPrice)); orderItem.setBaseSalePrice(convertToMoney(baseSalePrice)); orderItem.setBundleOrderItem(bundleOrderItem); orderItem.setProduct(product); orderItem.setSku(sku); if (orderItem.getOrder() == null) { throw new IllegalStateException("Either an Order or a BundleOrderItem must be set on the DiscreteOrderItem"); } return orderItem; }
private DiscreteOrderItem createDiscreteOrderItem(Long skuId, Double retailPrice, Double salePrice, boolean isDiscountable, int quantity, Order order) { DiscreteOrderItem item = new DiscreteOrderItemImpl(); Sku sku = catalogService.findSkuById(skuId); sku.setRetailPrice(new Money(retailPrice)); if (salePrice != null) { sku.setSalePrice(new Money(salePrice)); } else { sku.setSalePrice(null); } sku.setDiscountable(isDiscountable); sku.setName("test"); sku = catalogService.saveSku(sku); item.setSku(sku); item.setQuantity(quantity); Product product = new ProductImpl(); product.setDefaultSku(sku); product = catalogService.saveProduct(product); item.setProduct(product); item.setOrder(order); item = (DiscreteOrderItem) orderItemService.saveOrderItem(item); return item; } }
order.setTotal(total); DiscreteOrderItem item = new DiscreteOrderItemImpl(); Sku sku = new SkuImpl(); sku.setRetailPrice(new Money(15D));