/// <summary>
        /// Adds the variants to the catalog.
        /// </summary>
        /// <param name="variant">
        /// The variant.
        /// </param>
        private void AddToCatalog(IProductVariant variant)
        {
            var matching = this.GetOrignalMatchingVariant(variant);
            var catalogKeys = matching.CatalogInventories.Select(x => x.CatalogKey).ToArray();

            foreach (var key in catalogKeys)
            {
                if (variant.CatalogInventories.All(x => x.CatalogKey != key))
                {
                    var catalog = _warehouseCatalogs.Value.FirstOrDefault(x => x.Key == key);
                    if (catalog != null) variant.AddToCatalogInventory(catalog);   
                }
            }
        }
Exemple #2
0
        /// <summary>
        /// Adds the variants to the catalog.
        /// </summary>
        /// <param name="variant">
        /// The variant.
        /// </param>
        private void AddToCatalog(IProductVariant variant)
        {
            var matching    = this.GetOrignalMatchingVariant(variant);
            var catalogKeys = matching.CatalogInventories.Select(x => x.CatalogKey).ToArray();

            foreach (var key in catalogKeys)
            {
                if (variant.CatalogInventories.All(x => x.CatalogKey != key))
                {
                    var catalog = _warehouseCatalogs.Value.FirstOrDefault(x => x.Key == key);
                    if (catalog != null)
                    {
                        variant.AddToCatalogInventory(catalog);
                    }
                }
            }
        }
Exemple #3
0
        public HttpResponseMessage PutProductVariant(ProductVariantDisplay productVariant)
        {
            var response = Request.CreateResponse(HttpStatusCode.OK);

            try
            {
                IProductVariant merchProductVariant = _productVariantService.GetByKey(productVariant.Key);

                if (productVariant.TrackInventory && !merchProductVariant.CatalogInventories.Any())
                {
                    merchProductVariant.AddToCatalogInventory(_warehouseService.GetDefaultWarehouse().DefaultCatalog());
                }

                merchProductVariant = productVariant.ToProductVariant(merchProductVariant);

                _productVariantService.Save(merchProductVariant);
            }
            catch (Exception ex) // I think this is not required as the server will create the error response message anyway
            {
                response = Request.CreateResponse(HttpStatusCode.NotFound, String.Format("{0}", ex.Message));
            }

            return(response);
        }
 /// <summary>
 /// Associates a product variant with a warehouse
 /// </summary>
 /// <param name="productVariant">
 /// The <see cref="IProductVariant"/>
 /// </param>
 /// <param name="catalogKey">
 /// The catalog Key.
 /// </param>
 public static void AddToCatalogInventory(this IProductVariant productVariant, Guid catalogKey)
 {
     productVariant.AddToCatalogInventory(new CatalogInventory(catalogKey, productVariant.Key));
 }
 /// <summary>
 /// Associates a product variant with a warehouse
 /// </summary>
 /// <param name="productVariant">The <see cref="IProductVariant"/></param>
 /// <param name="catalog">The <see cref="IWarehouseCatalog"/></param>
 public static void AddToCatalogInventory(this IProductVariant productVariant, IWarehouseCatalog catalog)
 {
     productVariant.AddToCatalogInventory(catalog.Key);
 }
        internal static IProductVariant ToProductVariant(this ProductVariantDisplay productVariantDisplay, IProductVariant destination)
        {
            if (productVariantDisplay.Key != Guid.Empty)
            {
                destination.Key = productVariantDisplay.Key;
            }
            if( !String.IsNullOrEmpty(productVariantDisplay.Name) )
            {
                destination.Name = productVariantDisplay.Name;
            }
            if( !String.IsNullOrEmpty(productVariantDisplay.Sku) )
            {
                destination.Sku = productVariantDisplay.Sku;
            }
            destination.Price = productVariantDisplay.Price;
            destination.CostOfGoods = productVariantDisplay.CostOfGoods;
            destination.SalePrice = productVariantDisplay.SalePrice;
            destination.OnSale = productVariantDisplay.OnSale;
            destination.Manufacturer = productVariantDisplay.Manufacturer;
            destination.ManufacturerModelNumber = productVariantDisplay.ManufacturerModelNumber;
            destination.Weight = productVariantDisplay.Weight;
            destination.Length = productVariantDisplay.Length;
            destination.Width = productVariantDisplay.Width;
            destination.Height = productVariantDisplay.Height;
            destination.Barcode = productVariantDisplay.Barcode;
            destination.Available = productVariantDisplay.Available;
            destination.TrackInventory = productVariantDisplay.TrackInventory;
            destination.OutOfStockPurchase = productVariantDisplay.OutOfStockPurchase;
            destination.Taxable = productVariantDisplay.Taxable;
            destination.Shippable = productVariantDisplay.Shippable;
            destination.Download = productVariantDisplay.Download;
            destination.DownloadMediaId = productVariantDisplay.DownloadMediaId;

            destination.ProductKey = productVariantDisplay.ProductKey;

            // We need to refactor the CatalogInventories to not be immutable if we are
            // going to need to do operations like this.  In the UI, the user "unchecks" a catalog that was
            // previously checked - so we need to remove it.
            var deletedCatalogKeys =
                destination.CatalogInventories.Where(
                    x => !productVariantDisplay.CatalogInventories.Select(ci => ci.CatalogKey).Contains(x.CatalogKey)).Select(x => x.CatalogKey).ToArray();
            foreach (var deletedCatalogKey in deletedCatalogKeys)
            {
                destination.RemoveFromCatalogInventory(deletedCatalogKey);
            }

            foreach (var catalogInventory in productVariantDisplay.CatalogInventories)
            {
                var catInv = destination.CatalogInventories.FirstOrDefault(x => x.CatalogKey == catalogInventory.CatalogKey);

                if (catInv != null)
                {
                    var destinationCatalogInventory = catInv;

                    destinationCatalogInventory = catalogInventory.ToCatalogInventory(destinationCatalogInventory);
                }
                else if (!Guid.Empty.Equals(catalogInventory.CatalogKey) && destination.HasIdentity)
                {
                    //// Add to a new catalog
                    destination.AddToCatalogInventory(catalogInventory.CatalogKey);
                }
            }

            foreach (var attribute in productVariantDisplay.Attributes)
            {
                IProductAttribute destinationProductAttribute;

                var attr = destination.Attributes.FirstOrDefault(x => x.Key == attribute.Key);
                if (attr != null)
                {
                    destinationProductAttribute = attr;

                    destinationProductAttribute = attribute.ToProductAttribute(destinationProductAttribute);
                }
                else
                {
                    destinationProductAttribute = new ProductAttribute(attribute.Name, attribute.Sku);

                    destinationProductAttribute = attribute.ToProductAttribute(destinationProductAttribute);

                    ProductAttributeCollection variantAttributes = destination.Attributes as ProductAttributeCollection;
                    variantAttributes.Add(destinationProductAttribute);
                }
            }

            destination.AddOrUpdateDetachedContent(productVariantDisplay);

            return destination;
        }
        internal static IProductVariant ToProductVariant(this ProductVariantDisplay productVariantDisplay, IProductVariant destination)
        {
            if (productVariantDisplay.Key != Guid.Empty)
            {
                destination.Key = productVariantDisplay.Key;
            }
            if (!String.IsNullOrEmpty(productVariantDisplay.Name))
            {
                destination.Name = productVariantDisplay.Name;
            }
            if (!String.IsNullOrEmpty(productVariantDisplay.Sku))
            {
                destination.Sku = productVariantDisplay.Sku;
            }
            destination.Price                   = productVariantDisplay.Price;
            destination.CostOfGoods             = productVariantDisplay.CostOfGoods;
            destination.SalePrice               = productVariantDisplay.SalePrice;
            destination.OnSale                  = productVariantDisplay.OnSale;
            destination.Manufacturer            = productVariantDisplay.Manufacturer;
            destination.ManufacturerModelNumber = productVariantDisplay.ManufacturerModelNumber;
            destination.Weight                  = productVariantDisplay.Weight;
            destination.Length                  = productVariantDisplay.Length;
            destination.Width                   = productVariantDisplay.Width;
            destination.Height                  = productVariantDisplay.Height;
            destination.Barcode                 = productVariantDisplay.Barcode;
            destination.Available               = productVariantDisplay.Available;
            destination.TrackInventory          = productVariantDisplay.TrackInventory;
            destination.OutOfStockPurchase      = productVariantDisplay.OutOfStockPurchase;
            destination.Taxable                 = productVariantDisplay.Taxable;
            destination.Shippable               = productVariantDisplay.Shippable;
            destination.Download                = productVariantDisplay.Download;
            destination.DownloadMediaId         = productVariantDisplay.DownloadMediaId;

            destination.ProductKey = productVariantDisplay.ProductKey;

            // We need to refactor the CatalogInventories to not be immutable if we are
            // going to need to do operations like this.  In the UI, the user "unchecks" a catalog that was
            // previously checked - so we need to remove it.
            var deletedCatalogKeys =
                destination.CatalogInventories.Where(
                    x => !productVariantDisplay.CatalogInventories.Select(ci => ci.CatalogKey).Contains(x.CatalogKey)).Select(x => x.CatalogKey).ToArray();

            foreach (var deletedCatalogKey in deletedCatalogKeys)
            {
                destination.RemoveFromCatalogInventory(deletedCatalogKey);
            }

            foreach (var catalogInventory in productVariantDisplay.CatalogInventories)
            {
                var catInv = destination.CatalogInventories.FirstOrDefault(x => x.CatalogKey == catalogInventory.CatalogKey);

                if (catInv != null)
                {
                    var destinationCatalogInventory = catInv;

                    destinationCatalogInventory = catalogInventory.ToCatalogInventory(destinationCatalogInventory);
                }
                else if (!Guid.Empty.Equals(catalogInventory.CatalogKey) && destination.HasIdentity)
                {
                    //// Add to a new catalog
                    destination.AddToCatalogInventory(catalogInventory.CatalogKey);
                }
            }

            foreach (var attribute in productVariantDisplay.Attributes)
            {
                IProductAttribute destinationProductAttribute;

                var attr = destination.Attributes.FirstOrDefault(x => x.Key == attribute.Key);
                if (attr != null)
                {
                    destinationProductAttribute = attr;

                    destinationProductAttribute = attribute.ToProductAttribute(destinationProductAttribute);
                }
                else
                {
                    destinationProductAttribute = new ProductAttribute(attribute.Name, attribute.Sku);

                    destinationProductAttribute = attribute.ToProductAttribute(destinationProductAttribute);

                    ProductAttributeCollection variantAttributes = destination.Attributes as ProductAttributeCollection;
                    variantAttributes.Add(destinationProductAttribute);
                }
            }

            destination.AddOrUpdateDetachedContent(productVariantDisplay);

            return(destination);
        }
        internal static IProductVariant ToProductVariant(this ProductVariantDisplay productVariantDisplay, IProductVariant destination)
        {
            if (productVariantDisplay.Key != Guid.Empty)
            {
                destination.Key = productVariantDisplay.Key;
            }
            if( !String.IsNullOrEmpty(productVariantDisplay.Name) )
            {
                destination.Name = productVariantDisplay.Name;
            }
            if( !String.IsNullOrEmpty(productVariantDisplay.Sku) )
            {
                destination.Sku = productVariantDisplay.Sku;
            }
            destination.Price = productVariantDisplay.Price;
            destination.CostOfGoods = productVariantDisplay.CostOfGoods;
            destination.SalePrice = productVariantDisplay.SalePrice;
            destination.OnSale = productVariantDisplay.OnSale;
            destination.Manufacturer = productVariantDisplay.Manufacturer;
            destination.ManufacturerModelNumber = productVariantDisplay.ManufacturerModelNumber;
            destination.Weight = productVariantDisplay.Weight;
            destination.Length = productVariantDisplay.Length;
            destination.Width = productVariantDisplay.Width;
            destination.Height = productVariantDisplay.Height;
            destination.Barcode = productVariantDisplay.Barcode;
            destination.Available = productVariantDisplay.Available;
            destination.TrackInventory = productVariantDisplay.TrackInventory;
            destination.OutOfStockPurchase = productVariantDisplay.OutOfStockPurchase;
            destination.Taxable = productVariantDisplay.Taxable;
            destination.Shippable = productVariantDisplay.Shippable;
            destination.Download = productVariantDisplay.Download;
            destination.DownloadMediaId = productVariantDisplay.DownloadMediaId;

            destination.ProductKey = productVariantDisplay.ProductKey;

            foreach (var catalogInventory in productVariantDisplay.CatalogInventories)
            {
				var catInv = destination.CatalogInventories.FirstOrDefault(x => x.CatalogKey == catalogInventory.CatalogKey);
				
				if (catInv != null)
				{
					var destinationCatalogInventory = catInv;
				
					destinationCatalogInventory = catalogInventory.ToCatalogInventory(destinationCatalogInventory);
				}
				else if (!Guid.Empty.Equals(catalogInventory.CatalogKey) && destination.HasIdentity)
				{
					//// Add to a new catalog
					destination.AddToCatalogInventory(catalogInventory.CatalogKey);
				}
            }

            foreach (var attribute in productVariantDisplay.Attributes)
            {
                IProductAttribute destinationProductAttribute;

                var attr = destination.Attributes.First(x => x.Key == attribute.Key);
                if (attr != null)
                {
                    destinationProductAttribute = attr;

                    destinationProductAttribute = attribute.ToProductAttribute(destinationProductAttribute);
                }
                else
                {
                    destinationProductAttribute = new ProductAttribute(attribute.Name, attribute.Sku);

                    destinationProductAttribute = attribute.ToProductAttribute(destinationProductAttribute);

                    ProductAttributeCollection variantAttributes = destination.Attributes as ProductAttributeCollection;
                    variantAttributes.Add(destinationProductAttribute);
                }
            }

            return destination;
        }
Exemple #9
0
        internal static IProductVariant ToProductVariant(this ProductVariantDisplay productVariantDisplay, IProductVariant destination)
        {
            if (productVariantDisplay.Key != Guid.Empty)
            {
                destination.Key = productVariantDisplay.Key;
            }
            if (!String.IsNullOrEmpty(productVariantDisplay.Name))
            {
                destination.Name = productVariantDisplay.Name;
            }
            if (!String.IsNullOrEmpty(productVariantDisplay.Sku))
            {
                destination.Sku = productVariantDisplay.Sku;
            }
            destination.Price                   = productVariantDisplay.Price;
            destination.CostOfGoods             = productVariantDisplay.CostOfGoods;
            destination.SalePrice               = productVariantDisplay.SalePrice;
            destination.OnSale                  = productVariantDisplay.OnSale;
            destination.Manufacturer            = productVariantDisplay.Manufacturer;
            destination.ManufacturerModelNumber = productVariantDisplay.ManufacturerModelNumber;
            destination.Weight                  = productVariantDisplay.Weight;
            destination.Length                  = productVariantDisplay.Length;
            destination.Width                   = productVariantDisplay.Width;
            destination.Height                  = productVariantDisplay.Height;
            destination.Barcode                 = productVariantDisplay.Barcode;
            destination.Available               = productVariantDisplay.Available;
            destination.TrackInventory          = productVariantDisplay.TrackInventory;
            destination.OutOfStockPurchase      = productVariantDisplay.OutOfStockPurchase;
            destination.Taxable                 = productVariantDisplay.Taxable;
            destination.Shippable               = productVariantDisplay.Shippable;
            destination.Download                = productVariantDisplay.Download;
            destination.DownloadMediaId         = productVariantDisplay.DownloadMediaId;

            destination.ProductKey = productVariantDisplay.ProductKey;

            foreach (var catalogInventory in productVariantDisplay.CatalogInventories)
            {
                var catInv = destination.CatalogInventories.FirstOrDefault(x => x.CatalogKey == catalogInventory.CatalogKey);

                if (catInv != null)
                {
                    var destinationCatalogInventory = catInv;

                    destinationCatalogInventory = catalogInventory.ToCatalogInventory(destinationCatalogInventory);
                }
                else if (!Guid.Empty.Equals(catalogInventory.CatalogKey) && destination.HasIdentity)
                {
                    //// Add to a new catalog
                    destination.AddToCatalogInventory(catalogInventory.CatalogKey);
                }
            }

            foreach (var attribute in productVariantDisplay.Attributes)
            {
                IProductAttribute destinationProductAttribute;

                var attr = destination.Attributes.FirstOrDefault(x => x.Key == attribute.Key);
                if (attr != null)
                {
                    destinationProductAttribute = attr;

                    destinationProductAttribute = attribute.ToProductAttribute(destinationProductAttribute);
                }
                else
                {
                    destinationProductAttribute = new ProductAttribute(attribute.Name, attribute.Sku);

                    destinationProductAttribute = attribute.ToProductAttribute(destinationProductAttribute);

                    ProductAttributeCollection variantAttributes = destination.Attributes as ProductAttributeCollection;
                    variantAttributes.Add(destinationProductAttribute);
                }
            }

            return(destination);
        }