Exemplo n.º 1
0
        /// <summary>
        /// Adds a <see cref="ILineItem"/> to the collection of items
        /// </summary>
        /// <param name="lineItem">
        /// The line item.
        /// </param>
        /// <remarks>
        /// Intended for custom line item types
        /// http://issues.merchello.com/youtrack/issue/M-381
        /// </remarks>
        public void AddItem(ILineItem lineItem)
        {
            Mandate.ParameterNotNullOrEmpty(lineItem.Sku, "The line item must have a sku");
            Mandate.ParameterNotNullOrEmpty(lineItem.Name, "The line item must have a name");

            if (lineItem.Quantity <= 0)
            {
                lineItem.Quantity = 1;
            }
            if (lineItem.Price < 0)
            {
                lineItem.Price = 0;
            }

            if (lineItem.LineItemType == LineItemType.Custom)
            {
                if (!new LineItemTypeField().CustomTypeFields.Select(x => x.TypeKey).Contains(lineItem.LineItemTfKey))
                {
                    var argError = new ArgumentException("The LineItemTfKey was not found in merchello.config custom type fields");
                    LogHelper.Error <SalePreparationBase>("The LineItemTfKey was not found in merchello.config custom type fields", argError);

                    throw argError;
                }
            }

            _itemCache.AddItem(lineItem);
        }
Exemplo n.º 2
0
 /// <summary>
 /// Adds a line item to the wish list
 /// </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;
     }
     _itemCache.AddItem(LineItemType.Product, name, sku, quantity, price, extendedData);
 }
        /// <summary>
        /// Adds a line item to the customer item cache.
        /// </summary>
        /// <param name="lineItem">
        /// The <see cref="IItemCacheLineItem"/>.
        /// </param>
        public void AddItem(IItemCacheLineItem lineItem)
        {
            if (lineItem.Quantity <= 0)
            {
                lineItem.Quantity = 1;
            }
            if (lineItem.Price < 0)
            {
                lineItem.Price = 0;
            }

            if (AddingItem.IsRaisedEventCancelled(new Core.Events.NewEventArgs <ILineItem>(lineItem), this))
            {
                return;
            }

            _itemCache.AddItem(lineItem);

            AddedItem.RaiseEvent(new Core.Events.NewEventArgs <ILineItem>(lineItem), this);
        }
Exemplo n.º 4
0
        public virtual void Init()
        {
            Customer = PreTestDataWorker.MakeExistingAnonymousCustomer();
            Basket = Web.Workflow.Basket.GetBasket(MerchelloContext, Customer);

            var odd = true;
            for (var i = 0; i < ProductCount; i++)
            {

                var product = PreTestDataWorker.MakeExistingProduct(true, WeightPerProduct, PricePerProduct);
                product.AddToCatalogInventory(PreTestDataWorker.WarehouseCatalog);
                product.CatalogInventories.First().Count = 10;
                product.TrackInventory = true;
                PreTestDataWorker.ProductService.Save(product);
                Basket.AddItem(product, 2);

                odd = !odd;
            }

            BillingAddress = new Address()
            {
                Name = "Out there",
                Address1 = "some street",
                Locality = "some city",
                Region = "ST",
                PostalCode = "98225",
                CountryCode = "US"
            };

            var origin = new Address()
            {
                Name = "Somewhere",
                Address1 = "origin street",
                Locality = "origin city",
                Region = "ST",
                PostalCode = "98225",
                CountryCode = "US"
            };

            PreTestDataWorker.DeleteAllItemCaches();
            PreTestDataWorker.DeleteAllInvoices();

            Customer.ExtendedData.AddAddress(BillingAddress, AddressType.Billing);
            ItemCache = new Core.Models.ItemCache(Customer.EntityKey, ItemCacheType.Checkout);

            PreTestDataWorker.ItemCacheService.Save(ItemCache);

            foreach (var item in Basket.Items)
            {
                ItemCache.AddItem(item.AsLineItemOf<ItemCacheLineItem>());
            }

            // setup the checkout
            SalePreparationMock = new SalePreparationMock(MerchelloContext, ItemCache, Customer);

            // add the shipment rate quote
            var shipment = Basket.PackageBasket(MerchelloContext, BillingAddress).First();
            var shipRateQuote = shipment.ShipmentRateQuotes(MerchelloContext).FirstOrDefault();

            //_checkoutMock.ItemCache.Items.Add(shipRateQuote.AsLineItemOf<InvoiceLineItem>());
            SalePreparationMock.SaveShipmentRateQuote(shipRateQuote);
        }
Exemplo n.º 5
0
 /// <summary>
 /// Maps the <see cref="IShipmentRateQuote"/> to a <see cref="ILineItem"/>
 /// </summary>
 /// <param name="shipmentRateQuote">The <see cref="IShipmentRateQuote"/> to be added as a <see cref="ILineItem"/></param>
 private void AddShipmentRateQuoteLineItem(IShipmentRateQuote shipmentRateQuote)
 {
     _itemCache.AddItem(shipmentRateQuote.AsLineItemOf <ItemCacheLineItem>());
 }
Exemplo n.º 6
0
        public virtual void Init()
        {
            Customer = PreTestDataWorker.MakeExistingAnonymousCustomer();
            Basket   = Web.Workflow.Basket.GetBasket(MerchelloContext.Current, Customer);

            var odd = true;

            for (var i = 0; i < ProductCount; i++)
            {
                var product = PreTestDataWorker.MakeExistingProduct(true, WeightPerProduct, PricePerProduct);
                product.AddToCatalogInventory(PreTestDataWorker.WarehouseCatalog);
                product.CatalogInventories.First().Count = 10;
                product.TrackInventory = true;
                PreTestDataWorker.ProductService.Save(product);
                Basket.AddItem(product, 2);

                odd = !odd;
            }

            BillingAddress = new Address()
            {
                Name        = "Out there",
                Address1    = "some street",
                Locality    = "some city",
                Region      = "ST",
                PostalCode  = "98225",
                CountryCode = "US"
            };

            var origin = new Address()
            {
                Name        = "Somewhere",
                Address1    = "origin street",
                Locality    = "origin city",
                Region      = "ST",
                PostalCode  = "98225",
                CountryCode = "US"
            };



            PreTestDataWorker.DeleteAllItemCaches();
            PreTestDataWorker.DeleteAllInvoices();


            Customer.ExtendedData.AddAddress(BillingAddress, AddressType.Billing);
            ItemCache = new Core.Models.ItemCache(Customer.Key, ItemCacheType.Checkout);

            PreTestDataWorker.ItemCacheService.Save(ItemCache);

            foreach (var item in Basket.Items)
            {
                ItemCache.AddItem(item.AsLineItemOf <ItemCacheLineItem>());
            }


            // setup the checkout
            SalePreparationMock = new SalePreparationMock(MerchelloContext.Current, ItemCache, Customer);

            // add the shipment rate quote
            var shipment      = Basket.PackageBasket(MerchelloContext.Current, BillingAddress).First();
            var shipRateQuote = shipment.ShipmentRateQuotes(MerchelloContext.Current).FirstOrDefault();

            //_checkoutMock.ItemCache.Items.Add(shipRateQuote.AsLineItemOf<InvoiceLineItem>());
            SalePreparationMock.SaveShipmentRateQuote(shipRateQuote);
        }