Пример #1
0
        private static void AddSimpleProduct(GOshopAPISoapClient service, ProductProducer[] producers)
        {
            var resultId = service.ProductAdd(new ProductAddStruct
            {
                Active              = true,
                BaseEAN             = Guid.NewGuid().ToString().Substring(0, 13),
                BaseSKU             = Guid.NewGuid().ToString().Substring(0, 13),
                ProducerName        = producers.OrderBy(n => Guid.NewGuid()).First().ProducerName,
                TaxRate             = 23,
                Name                = $"Test Product {Utilities.GetRandomString(5)}",
                Weight              = 0.05m,
                FullHtmlDescription = "Full description <b>with html</b>",
                ShortDescription    = "test short descriptions",
                CategoryId          = new[] { 26, 18 }
            });
            var catalogPrice = new Random(new Random().Next()).NextDecimal(1000, 5000);
            var grossPrice   = new Random(new Random().Next()).NextDecimal(1000, 5000);

            service.AddBasicOption(new OptionAddRequest
            {
                CatalogPriceGross = catalogPrice,
                PriceGross        = grossPrice,
                EAN       = Utilities.GetRandomString(13),
                SKU       = Utilities.GetRandomString(8),
                ProductId = resultId,
                Stock     = new Random().Next(0, 100)
            });

            Console.WriteLine($"Product added: #{resultId}");

            AddImagesToProduct(service, resultId);
        }
Пример #2
0
        private static void AddProductWithVariants(GOshopAPISoapClient service, ProductProducer[] producers)
        {
            var resultId = service.ProductAdd(new ProductAddStruct
            {
                Active              = true,
                BaseEAN             = Guid.NewGuid().ToString().Substring(0, 13),
                BaseSKU             = Guid.NewGuid().ToString().Substring(0, 13),
                ProducerName        = producers.OrderBy(n => Guid.NewGuid()).First().ProducerName,
                TaxRate             = 23,
                Name                = $"Test Product {Utilities.GetRandomString(5)}",
                Weight              = 0.05m,
                FullHtmlDescription = "Full description <b>with html</b>"
            });


            service.AddVariantOption(new OptionAddRequest
            {
                CatalogPriceGross = new Random().NextDecimal(1000, 5000),
                PriceGross        = new Random().NextDecimal(1000, 5000),
                EAN          = Utilities.GetRandomString(13),
                SKU          = Utilities.GetRandomString(8),
                ProductId    = resultId,
                Stock        = new Random().Next(0, 100),
                Dictionaries = new[]
                {
                    new OptionDictionaryDefinition
                    {
                        FeatureName    = "Kolor",
                        DictionaryName = "Biały"
                    },
                    new OptionDictionaryDefinition
                    {
                        FeatureName    = "Rozmiar",
                        DictionaryName = "xxl"
                    }
                }
            });
            service.AddVariantOption(new OptionAddRequest
            {
                CatalogPriceGross = new Random().NextDecimal(1000, 5000),
                PriceGross        = new Random().NextDecimal(1000, 5000),
                EAN          = Utilities.GetRandomString(13),
                SKU          = Utilities.GetRandomString(8),
                ProductId    = resultId,
                Stock        = new Random().Next(0, 100),
                Dictionaries = new[]
                {
                    new OptionDictionaryDefinition()
                    {
                        FeatureName    = "Kolor",
                        DictionaryName = "Biały"
                    },
                    new OptionDictionaryDefinition()
                    {
                        FeatureName    = "Rozmiar",
                        DictionaryName = "S"
                    }
                }
            });
            try
            {
                //this product has different definitions of features than already added products
                service.AddVariantOption(new OptionAddRequest
                {
                    CatalogPriceGross = new Random().NextDecimal(1000, 5000),
                    PriceGross        = new Random().NextDecimal(1000, 5000),
                    EAN          = Utilities.GetRandomString(13),
                    SKU          = Utilities.GetRandomString(8),
                    ProductId    = resultId,
                    Stock        = new Random().Next(0, 100),
                    Dictionaries = new[]
                    {
                        new OptionDictionaryDefinition()
                        {
                            FeatureName    = "Kolory inne",
                            DictionaryName = "Biały"
                        },
                        new OptionDictionaryDefinition()
                        {
                            FeatureName    = "Rozmiar",
                            DictionaryName = "S"
                        }
                    }
                });
            }
            catch (Exception exception)
            {
                Console.WriteLine(exception.Message);
            }

            try
            {
                //this product already have options from dictionaries, basic option cannot be added
                service.AddBasicOption(new OptionAddRequest
                {
                    CatalogPriceGross = new Random().NextDecimal(1000, 5000),
                    PriceGross        = new Random().NextDecimal(1000, 5000),
                    EAN       = Utilities.GetRandomString(13),
                    SKU       = Utilities.GetRandomString(8),
                    ProductId = resultId,
                    Stock     = new Random().Next(0, 100)
                });
            }
            catch (Exception exception)
            {
                Console.WriteLine(exception.Message);
            }

            AddImagesToProduct(service, resultId);
        }