Ejemplo n.º 1
0
        public static LineItem AsLineItem(this Product product)
        {
            var variant = product.Variants.First();
            var lineItem = new LineItem
                           {
                               Product = product,
                               Variant = variant,
                               ProductId = product.Id,
                               VariantId = variant.Id,
                               Handle = product.Handle,
                               Price = variant.NumericPrice,
                               RequiresShipping = String.IsNullOrEmpty(product.Type) ||
                                    !String.IsNullOrEmpty(product.Type) && product.Type.Equals("Physical", StringComparison.OrdinalIgnoreCase),
                               Quantity = 1,
                               Url = product.Url,
                               Title = product.Title,
                               Image = product.FeaturedImage.Src
                           };

            return lineItem;
        }
Ejemplo n.º 2
0
        public static LineItem AsWebModel(this Data.CartItem item)
        {
            var product = new Product
                          {
                              Title = item.Name,
                              Description = item.Name,
                              Excerpt = item.Name,
                              Handle = item.ProductId
                          };

            var variant = new Variant();

            var ret = new LineItem
                      {
                          Id = item.Id,
                          Handle = item.ProductId,
                          ProductId = item.ProductId,
                          Title = item.Name,
                          Price = item.PlacedPrice,
                          Quantity = item.Quantity,
                          RequiresShipping = item.RequiredShipping,
                          Sku = item.ProductCode,
                          VariantId = item.ProductId,
                          Image = item.ImageUrl,
                          Variant = variant,
                          Product = product,
                          Url = String.Format("/products/{0}", item.ProductId),
                          Taxable = item.TaxIncluded,
                          TaxAmount = item.TaxTotal
                      };

            return ret;
        }
Ejemplo n.º 3
0
        public static LineItem AsLineItemModel(this QuoteItem quoteItemModel)
        {
            var lineItemModel = new LineItem();

            lineItemModel.Image = quoteItemModel.ImageUrl;
            lineItemModel.Price = quoteItemModel.SelectedTierPrice.Price;
            lineItemModel.ProductId = quoteItemModel.ProductId;
            lineItemModel.Quantity = quoteItemModel.SelectedTierPrice.Quantity;
            lineItemModel.Sku = quoteItemModel.Sku;
            lineItemModel.Title = quoteItemModel.Title;

            return lineItemModel;
        }
Ejemplo n.º 4
0
        public static LineItem AsWebModel(this ApiClient.DataContracts.Orders.LineItem lineItem)
        {
            var ret = new LineItem
                      {
                          Fulfillment = null,
                          Grams = 0,
                          Handle = null,
                          Id = lineItem.Id,
                          Image = lineItem.ImageUrl,
                          Price = lineItem.Price,
                          Product = null,
                          ProductId = lineItem.ProductId,
                          Quantity = lineItem.Quantity,
                          RequiresShipping = false,
                          Sku = null,
                          TaxAmount = lineItem.Tax,
                          TaxType = lineItem.TaxType,
                          Title = lineItem.Name,
                          Url = null,
                          Variant = null,
                          VariantId = null,
                          Vendor = null
                      };

            return ret;
        }
Ejemplo n.º 5
0
        public Cart AddLineItem(LineItem lineItem)
        {
            var existingLineItem = Items.FirstOrDefault(i => i.ProductId == lineItem.ProductId);

            if (existingLineItem != null)
            {
                existingLineItem.Quantity = lineItem.Quantity;
            }
            else
            {
                lineItem.Id = null;
                Items.Add(lineItem);
            }

            return this;
        }