Example #1
0
        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());
        }
Example #2
0
        /// <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>());
        }