Example #1
0
        private void CreateOrUpdateCatalogProduct(bsi_posts post)
        {
            CatalogProductFactory catalogProductFactory = _catalogProductFactories.SingleOrDefault(p => p.IsMatch(post));

            if (catalogProductFactory == null)
            {
                throw new NotImplementedException("This type of product is currently not supported");
            }

            List <string> childSkus = new List <string>();

            foreach (bsi_quantities postItem in post.bsi_quantities)
            {
                string sku = postItem.itemLookupCode;
                catalogProductCreateEntity simpleProductData = catalogProductFactory.CreateProductData(post, postItem);
                try
                {
                    int ID = _proxy.catalogProductCreate(_sessionID, "simple", catalogProductFactory.GetAttributeSet(), sku, simpleProductData, null);
                    childSkus.Add(sku);
                }
                catch (Exception ex)
                {
                    childSkus.Add(sku);
                    if (!_proxy.catalogProductUpdate(_sessionID, sku, simpleProductData, null, "sku"))
                    {
                        this.Log(sku + ": " + ex.Message);
                    }
                }
            }

            catalogProductCreateEntity configurableProductData = catalogProductFactory.CreateParentProductData(post, childSkus);

            try
            {
                int parentID = _proxy.catalogProductCreate(_sessionID, "configurable", catalogProductFactory.GetAttributeSet(), post.sku, configurableProductData, null);

                AssignImages(post, parentID.ToString());
            }
            catch (Exception ex)
            {
                if (!_proxy.catalogProductUpdate(_sessionID, post.sku, configurableProductData, null, "sku"))
                {
                    this.Log(post.sku + ": " + ex.Message);
                }
            }
        }