public ProductDisplay AddProduct(ProductDisplay product)
        {
            var merchProduct = _productService.CreateProduct(product.Name, product.Sku, product.Price);

            merchProduct = product.ToProduct(merchProduct);
            _productService.Save(merchProduct);

            //// special case where a catalog was associated before the creation of the product
            //if (product.CatalogInventories.Any())
            //{
            //    foreach (var cat in product.CatalogInventories)
            //    {
            //        ((Product)merchProduct).MasterVariant.AddToCatalogInventory(cat.CatalogKey);
            //    }
            //}

            _productService.Save(merchProduct);

            //if (!merchProduct.ProductOptions.Any()) return merchProduct.ToProductDisplay();

            //var attributeLists = merchProduct.GetPossibleProductAttributeCombinations();

            //foreach (var list in attributeLists)
            //{
            //    _productVariantService.CreateProductVariantWithKey(merchProduct, list.ToProductAttributeCollection());
            //}

            return(merchProduct.ToProductDisplay());
        }
示例#2
0
        private IProduct AddProduct(ProductDisplay product)
        {
            var p = _productService.CreateProduct(product.Name, product.Sku, product.Price);

            p = product.ToProduct(p);
            _productService.Save(p);
            return(p);
        }
        public ProductDisplay AddProduct(ProductDisplay product)
        {
            var merchProduct = _productService.CreateProduct(product.Name, product.Sku, product.Price);

            merchProduct = product.ToProduct(merchProduct);
            _productService.Save(merchProduct);
            return(merchProduct.ToProductDisplay(DetachedValuesConversionType.Editor));
        }
示例#4
0
        public ProductDisplay PutProduct(ProductDisplay product)
        {
            var merchProduct = _productService.GetByKey(product.Key);

            merchProduct = product.ToProduct(merchProduct);

            _productService.Save(merchProduct);

            return(merchProduct.ToProductDisplay());
        }
示例#5
0
        public ProductDisplay AddProduct(ProductDisplay product)
        {
            var merchProduct = _productService.CreateProduct(product.Name, product.Sku, product.Price);

            merchProduct = product.ToProduct(merchProduct);
            _productService.Save(merchProduct);


            _productService.Save(merchProduct);

            return(merchProduct.ToProductDisplay());
        }
        public ProductDisplay CreateProduct(ProductDisplay product)
        {
            // we need to remove the detached content to generate the product to begin with due to db foreign keys
            var detachedContents = product.DetachedContents.ToArray();

            product.DetachedContents = Enumerable.Empty <ProductVariantDetachedContentDisplay>();

            // First create the product record and save it
            var merchProduct = _productService.CreateProduct(product.Name, product.Sku, product.Price);

            merchProduct = product.ToProduct(merchProduct);

            // we don't want to raise events here since we will be saving again and there is no sense
            // in having examine index it twice. Use the detached contents to determine whether we need to fire event
            _productService.Save(merchProduct, !detachedContents.Any());

            if (!detachedContents.Any())
            {
                return(merchProduct.ToProductDisplay(DetachedValuesConversionType.Editor));
            }

            // convert the product back so we can reassociate the detached content.
            product = merchProduct.ToProductDisplay();

            // asscociate the product variant key (master variant) with the detached content
            foreach (var pvdc in detachedContents)
            {
                pvdc.ProductVariantKey = merchProduct.ProductVariantKey;
            }

            // add the detached contents back
            product.DetachedContents = detachedContents;

            // this adds the detached content to the product
            merchProduct = product.ToProduct(merchProduct);
            _productService.Save(merchProduct);

            return(merchProduct.ToProductDisplay(DetachedValuesConversionType.Editor));
        }
        public ProductDisplay PutProduct(ProductDisplay product)
        {
            var merchProduct = _productService.GetByKey(product.Key);

            merchProduct = product.ToProduct(merchProduct);
            _productService.Save(merchProduct);

            //if (!merchProduct.ProductOptions.Any()) return merchProduct.ToProductDisplay();

            //// verify that all attributes have been created
            //var attributeLists = merchProduct.GetPossibleProductAttributeCombinations().ToArray();
            //foreach (var list in from list in attributeLists let variant = merchProduct.GetProductVariantForPurchase(list) where variant == null select list)
            //{
            //    _productVariantService.CreateProductVariantWithKey(merchProduct, list.ToProductAttributeCollection());
            //}

            return(merchProduct.ToProductDisplay());
        }
        public HttpResponseMessage PutProduct(ProductDisplay product)
        {
            var response = Request.CreateResponse(HttpStatusCode.OK);

            try
            {
                IProduct merchProduct = _productService.GetByKey(product.Key);
                merchProduct = product.ToProduct(merchProduct);

                _productService.Save(merchProduct);
            }
            catch (Exception ex)
            {
                response = Request.CreateResponse(HttpStatusCode.NotFound, String.Format("{0}", ex.Message));
            }

            return(response);
        }
示例#9
0
        private IProduct AddProduct(ProductDisplay product)
        {
            var p = _productService.CreateProduct(product.Name, product.Sku, product.Price);

            p = product.ToProduct(p);
            _productService.Save(p);

            if (!p.ProductOptions.Any())
            {
                return(p);
            }

            var attributeLists = p.GetPossibleProductAttributeCombinations();

            foreach (var list  in attributeLists)
            {
                _productVariantService.CreateProductVariantWithKey(p, list.ToProductAttributeCollection());
            }

            return(p);
        }
        public ProductDisplay PutProduct(ProductDisplay product)
        {
            var merchProduct = _productService.GetByKey(product.Key);

            if (product.DetachedContents.Any())
            {
                foreach (var c in product.DetachedContents.Select(x => x.CultureName))
                {
                    var pcs = new ProductContentSave {
                        CultureName = c, Display = product
                    };
                    ProductVariantDetachedContentHelper <ProductContentSave, ProductDisplay> .MapDetachedProperties(pcs);
                }
            }

            merchProduct = product.ToProduct(merchProduct);

            _productService.Save(merchProduct);

            return(merchProduct.ToProductDisplay(DetachedValuesConversionType.Editor));
        }
        public ProductDisplay NewProductFromProduct(ProductDisplay product)
        {
            IProduct newProduct = null;

            try
            {
                newProduct = _productService.CreateProduct(product.Name, product.Sku, product.Price);
                _productService.Save(newProduct);

                newProduct.AddToCatalogInventory(_warehouseService.GetDefaultWarehouse().DefaultCatalog());

                newProduct = product.ToProduct(newProduct);
                _productService.Save(newProduct);
            }
            catch (Exception ex)
            {
                throw new HttpResponseException(Request.CreateResponse(HttpStatusCode.InternalServerError));
            }

            return(newProduct.ToProductDisplay());
        }