Esempio n. 1
0
        /// <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);
        }
Esempio n. 3
0
        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);
        }
        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());
        }
Esempio n. 5
0
        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;
        }
Esempio n. 6
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());
        }
Esempio n. 7
0
        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 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);
        }
Esempio n. 9
0
 /// <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);
 }
Esempio n. 10
0
 /// <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);
 }