/// <summary> /// Adds a line item to the collection /// </summary> /// <param name="container"> /// The container. /// </param> /// <param name="lineItemType"> /// The line Item Type. /// </param> /// <param name="name"> /// The name. /// </param> /// <param name="sku"> /// The sku. /// </param> /// <param name="quantity"> /// The quantity. /// </param> /// <param name="amount"> /// The amount. /// </param> /// <param name="extendedData"> /// The extended Data. /// </param> public static void AddItem(this ILineItemContainer container, LineItemType lineItemType, string name, string sku, int quantity, decimal amount, ExtendedDataCollection extendedData) { var lineItem = new ItemCacheLineItem(lineItemType, name, sku, quantity, amount, extendedData) { ContainerKey = container.Key }; container.AddItem(lineItem); }
public void Can_Format_Currency_BasedOn_US_CountryCode() { //// Arrange var lineItem = new ItemCacheLineItem(LineItemType.Product, "Product", "Sku", 10, 100); //// Act var price = lineItem.FormatPrice(); Console.Write(price); }
public void Can_Add_A_CustomLineItemType_To_The_Basket() { //// Arrange var typefield = EnumTypeFieldConverter.LineItemType.Custom("CcFee"); Assert.NotNull(typefield); // create a custom line item var itemCacheLineItem = new ItemCacheLineItem(typefield.TypeKey, typefield.Name, "fee", 1, 10, new ExtendedDataCollection()); _basket.Items.Add(itemCacheLineItem); }
/// <summary> /// Creates a template discount line item. /// </summary> /// <returns> /// The <see cref="ILineItem"/>. /// </returns> protected ILineItem CreateTemplateDiscountLineItem() { // get the discount line item setup // assume being executed from sale preparation so it will be an ItemCacheLineItem var discountLineItem = new ItemCacheLineItem( LineItemType.Discount, this.GetRewardLineItemName(), this.OfferCode, 1, 0); return(discountLineItem); }
/// <summary> /// Adds a line item to the customer item cache /// </summary> /// <param name="name"> /// The name. /// </param> /// <param name="sku"> /// The SKU. /// </param> /// <param name="quantity"> /// The quantity. /// </param> /// <param name="price"> /// The price. /// </param> /// <param name="extendedData"> /// The extended Data. /// </param> public void AddItem(string name, string sku, int quantity, decimal price, ExtendedDataCollection extendedData) { if (quantity <= 0) { quantity = 1; } if (price < 0) { price = 0; } var lineItem = new ItemCacheLineItem(LineItemType.Product, name, sku, quantity, price, extendedData); _itemCache.AddItem(lineItem); }
public void Can_Add_Custom_Discount_ToBasket_And_Transfer_It_To_CheckoutManager() { //// Arrange var basket = CurrentCustomer.Basket(); var discount = new ItemCacheLineItem(LineItemType.Discount, "Test discount", "test", 1, 2, new ExtendedDataCollection()); basket.AddItem(_product1, 10); basket.AddItem(_product2, 5); basket.AddItem(_product3, 1); var preDiscountTotal = basket.TotalBasketPrice; basket.AddItem(discount); var postDiscountTotal = basket.TotalBasketPrice; Assert.AreEqual(postDiscountTotal, preDiscountTotal - 2, "Discount failed to calculate correctly"); var total = CurrentCustomer.Basket().TotalBasketPrice; this.CurrentCustomer.Basket().Save(); Assert.AreEqual(4, CurrentCustomer.Basket().Items.Count()); // var shipping = MockAddressMaker.GetAddress("US"); var billing = MockAddressMaker.GetAddress("US"); var checkoutManager = this.CurrentCustomer.Basket().GetCheckoutManager(); checkoutManager.Customer.SaveShipToAddress(shipping); checkoutManager.Customer.SaveBillToAddress(billing); var shipment = this.CurrentCustomer.Basket().PackageBasket(shipping).FirstOrDefault(); var quotes = shipment.ShipmentRateQuotes().ToArray(); Assert.NotNull(quotes); Assert.IsTrue(quotes.Any(), "The collection of quotes was empty"); checkoutManager.Shipping.SaveShipmentRateQuote(quotes.First()); //// Act checkoutManager.Context.Settings.InvoiceNumberPrefix = "rss"; var invoice = checkoutManager.Payment.PrepareInvoice(); //// Assert Assert.NotNull(invoice); Assert.IsTrue(invoice.PrefixedInvoiceNumber().StartsWith("rss")); }
public ItemCacheLineItem BuildEntity(ItemCacheItemDto dto) { var lineItem = new ItemCacheLineItem(dto.LineItemTfKey, dto.Name, dto.Sku, dto.Quantity, dto.Price, string.IsNullOrEmpty(dto.ExtendedData) ? new ExtendedDataCollection() : new ExtendedDataCollection(dto.ExtendedData)) { Key = dto.Key, ContainerKey = dto.ContainerKey, Exported = dto.Exported, UpdateDate = dto.UpdateDate, CreateDate = dto.CreateDate }; lineItem.ResetDirtyProperties(); return(lineItem); }
public void Can_Add_An_Item_To_An_ItemCache() { //// Arrange var basket = _itemCacheService.GetItemCacheWithKey(_anonymous, ItemCacheType.Basket); //// Act var lineItem = new ItemCacheLineItem(LineItemType.Product, "Kosher Salt", "KS", 1, 2.5M) { ContainerKey = basket.Key }; basket.Items.Add(lineItem); //// Assert Assert.IsTrue(basket.Items.Any()); }
public void Can_Convert_A_LineItem_Of_Type_ItemCacheLineItem_To_A_InvoiceLineItem() { //// Arrange var product = MockProductDataMaker.MockProductForInserting(); var extendedData = new ExtendedDataCollection(); extendedData.AddProductVariantValues(((Product)product).MasterVariant); var itemCacheLineItem = new ItemCacheLineItem(LineItemType.Product, product.Name, product.Sku, 2, 2 * product.Price, extendedData); //// Act var invoiceLineItem = itemCacheLineItem.AsLineItemOf <InvoiceLineItem>(); //// Assert Assert.NotNull(invoiceLineItem); Assert.AreEqual(Guid.Empty, invoiceLineItem.ContainerKey); Assert.AreEqual(typeof(InvoiceLineItem), invoiceLineItem.GetType()); }
/// <summary> /// Creates a template discount line item. /// </summary> /// <param name="audits"> /// Reward audit log /// </param> /// <returns> /// The <see cref="ILineItem"/>. /// </returns> protected ILineItem CreateTemplateDiscountLineItem(IEnumerable <CouponRewardAdjustmentAudit> audits = null) { // get the discount line item setup // assume being executed from sale preparation so it will be an ItemCacheLineItem var discountLineItem = new ItemCacheLineItem( LineItemType.Discount, this.GetRewardLineItemName(), this.OfferCode, 1, 0); if (audits != null) { discountLineItem.ExtendedData.SetValue(Core.Constants.ExtendedDataKeys.CouponRewardLog, JsonConvert.SerializeObject(audits)); } return(discountLineItem); }
/// <summary> /// Turns a product into an InvoiceLineItem /// </summary> /// <param name="product"></param> /// <param name="qty"></param> /// <param name="taxIncludedInProductPrice"></param> /// <returns></returns> internal static InvoiceLineItem ToInvoiceLineItem(this ProductDisplay product, int qty = 1, bool taxIncludedInProductPrice = false) { var extendedData = new ExtendedDataCollection(); extendedData.AddProductValues(product); if (taxIncludedInProductPrice) { extendedData.TryAdd(Constants.ExtendedDataKeys.TaxIncludedInProductPrice, true.ToString()); } // See if this variant is on sale var price = product.OnSale ? product.SalePrice : product.Price; // TODO - Can we remove this extra step to turn into a line item var itemCacheLineItem = new ItemCacheLineItem(LineItemType.Product, product.Name, product.Sku, qty, price, extendedData); return(itemCacheLineItem.AsLineItemOf <InvoiceLineItem>()); }
public void Can_Add_And_Save_An_Item_To_ItemCache() { //// Arrange var basket = _itemCacheService.GetItemCacheWithKey(_anonymous, ItemCacheType.Basket); var lineItem = new ItemCacheLineItem(LineItemType.Product, "Kosher Salt", "KS", 1, 2.5M) { ContainerKey = basket.Key }; basket.Items.Add(lineItem); //// Act _itemCacheService.Save(basket); //// Assert Assert.IsFalse(basket.IsDirty()); Assert.IsTrue(basket.HasIdentity); Assert.IsFalse(basket.Items.IsEmpty); }
/// <summary> /// Adds a line item to the customer item cache /// </summary> /// <param name="name"> /// The name. /// </param> /// <param name="sku"> /// The SKU. /// </param> /// <param name="quantity"> /// The quantity. /// </param> /// <param name="price"> /// The price. /// </param> /// <param name="extendedData"> /// The extended Data. /// </param> public void AddItem(string name, string sku, int quantity, decimal price, ExtendedDataCollection extendedData) { var lineItem = new ItemCacheLineItem(LineItemType.Product, name, sku, quantity, price, extendedData); AddItem(lineItem); }