Example #1
0
        public WooCommerceNET.WooCommerce.v3.Product GetProdWeb(ArticoloBase artDb, out bool newProd)
        {
            var artWeb = new WooCommerceNET.WooCommerce.v3.Product();

            newProd = false;
            if (!string.IsNullOrEmpty(artDb.Aggiornamento.CodiceArticoloEcommerce))
            {
                var tsk = _wc.Product.Get(int.Parse(artDb.Aggiornamento.CodiceArticoloEcommerce), null);
                tsk.Wait();
                artWeb = tsk.Result;
            }
            else
            {
                var parms = new Dictionary <string, string>();
                parms.Add("sku", artDb.ArticoloID.ToString());

                var tsk = _wc.Product.GetAll(parms);
                tsk.Wait();
                artWeb = tsk.Result.FirstOrDefault();
                if (artWeb == null)
                {
                    artWeb  = new WooCommerceNET.WooCommerce.v3.Product();
                    newProd = true;
                }
            }
            return(artWeb);
        }
Example #2
0
        private void UpdateImage(ArticoloBase artDb, WooCommerceNET.WooCommerce.v3.Product artWeb, UnitOfWork uof)
        {
            //DateTime date = DateTime.Now;
            /*cancello le immagini e le sovrascrivo*/
            artWeb.images.Clear();
            foreach (var item in artWeb.images)
            {
            }
            var settingSito = SettingSitoValidator.ReadSetting();

            var imageList = uof.FotoArticoloRepository.Find(a => a.ArticoloID == artDb.ArticoloID).OrderBy(a => a.Ordine).ToList();

            var listFotoArticolo = imageList.Select(a => new ImmaginiFile <FotoArticolo>(Path.Combine(
                                                                                             settingSito.CartellaLocaleImmagini, a.UrlFoto)
                                                                                         , a.UrlFoto, a)).ToList();

            int ord = 0;

            foreach (var item in listFotoArticolo)
            {
                ///provaale.atwebpages.com/wp-content/uploads/2021/03
                artWeb.images.Add(new ProductImage()
                {
                    src = item.File, position = ord, name = item.Name, alt = artDb.ArticoloDb.Titolo
                });
                ord++;
            }
            //var aggiornamento = artDb.Aggiornamento;

            //aggiornamento.DataUltimoAggFoto = date;
            //aggiornamento.DataUltimoAggFotoWeb = date;
            //SalvaAggiornamento(uof, aggiornamento);
        }
Example #3
0
        private void SetDataItemWeb(ArticoloBase artDb, UnitOfWork uof, WooCommerceNET.WooCommerce.v3.Product artWeb, bool newProd)
        {
            artWeb.regular_price = Math.Round(artDb.ArticoloDb.ArticoloWeb.PrezzoWeb * 100 / (100 + artDb.ArticoloDb.Iva), 6, MidpointRounding.ToEven);
            //artWeb.sale_price = Math.Round(artDb.ArticoloDb.ArticoloWeb.PrezzoWeb * 100 / (100 + artDb.ArticoloDb.ArticoloWeb.Iva), 6, MidpointRounding.ToEven);
            artWeb.name = artDb.ArticoloDb.Titolo;


            //*iva al 22%*//
            artWeb.tax_class = artDb.ArticoloDb.Iva.ToString();

            ImpostaCategoria(artDb, uof, artWeb);

            if (string.IsNullOrEmpty(artDb.ArticoloDb.ArticoloWeb.DescrizioneHtml))
            {
                artWeb.description             = "";
                artWeb.enable_html_description = false;
            }
            else
            {
                artWeb.description             = artDb.ArticoloDb.ArticoloWeb.DescrizioneHtml;
                artWeb.enable_html_description = true;
            }
            artWeb.short_description =
                artDb.ArticoloDb.ArticoloWeb.DescrizioneBreveHtml;
            artWeb.enable_html_short_description = "true";


            if (artDb.ArticoloDb.Condizione != enCondizioneArticolo.Nuovo)
            {
                artWeb.name        = "USATO " + artWeb.name;
                artWeb.description = "USATO " + artWeb.description;
            }

            artWeb.manage_stock = true;

            if (newProd)
            {
                artWeb.stock_quantity = StockProductsBase.CalcolaStock(new ArticoloBase()
                {
                    ArticoloID = artDb.ArticoloID
                });
            }


            artWeb.sku = artDb.ArticoloID.ToString();

            UpdateImage(artDb, artWeb, uof);
        }
Example #4
0
 public static WooCommerceProduct ToSvProduct(this WooCommerceNET.WooCommerce.v3.Product productV3)
 {
     return(new WooCommerceProduct()
     {
         Id = productV3.id,
         Sku = productV3.sku,
         Name = productV3.name,
         Description = productV3.description,
         ShortDescription = productV3.short_description,
         Price = productV3.price,
         Quantity = productV3.stock_quantity,
         Categories = productV3.categories?.Select(c => c.name),
         Images = productV3.images?.Select(i => i.src),
         Weight = productV3.weight,
         SalePrice = productV3.sale_price,
         RegularPrice = productV3.regular_price,
         Attributes = productV3.attributes?.ToAttributeDictionary(),
         HasVariations = productV3.variations != null && productV3.variations.Any(),
         CreatedDateUtc = productV3.date_created_gmt,
         UpdatedDateUtc = productV3.date_modified_gmt,
         ManagingStock = productV3.manage_stock
     });
 }
Example #5
0
        public void MapApiV3ProductToSvProduct()
        {
            var product = new Product
            {
                id                = 1,
                sku               = "testsku",
                name              = "asdf",
                description       = "alsdfkj",
                short_description = "flaskdfjsdlakfj",
                price             = 12.30M,
                stock_quantity    = 23,
                categories        = new List <ProductCategoryLine>
                {
                    new ProductCategoryLine
                    {
                        name = "bob"
                    }
                },
                images = new List <ProductImage>
                {
                    new ProductImage
                    {
                        src = "some Url"
                    },
                    new ProductImage
                    {
                        src = "another Url"
                    }
                },
                weight        = 2.1M,
                sale_price    = 1.2M,
                regular_price = 2.1M,
                attributes    = new List <ProductAttributeLine>
                {
                    new ProductAttributeLine
                    {
                        name    = "color",
                        options = new List <string>
                        {
                            "red"
                        }
                    },
                    new ProductAttributeLine
                    {
                        name    = "size",
                        options = new List <string>
                        {
                            "small",
                            "large"
                        }
                    }
                },
                variations = new List <int>
                {
                    1,
                    2
                },
                date_created_gmt  = new DateTime(2099, 1, 1),
                date_modified_gmt = new DateTime(2099, 11, 11)
            };

            var svProduct = product.ToSvProduct();

            Assert.AreEqual(product.id, svProduct.Id);
            Assert.AreEqual(product.sku, svProduct.Sku);
            Assert.AreEqual(product.name, svProduct.Name);
            Assert.AreEqual(product.description, svProduct.Description);
            Assert.AreEqual(product.short_description, svProduct.ShortDescription);
            Assert.AreEqual(product.price, svProduct.Price);
            Assert.AreEqual(product.stock_quantity, svProduct.Quantity);
            Assert.AreEqual(product.categories[0].name, svProduct.Categories.First());
            Assert.AreEqual(product.images.Count, svProduct.Images.Count());
            Assert.AreEqual(product.images[0].src, svProduct.Images.First());
            Assert.AreEqual(product.weight, svProduct.Weight);
            Assert.AreEqual(product.sale_price, svProduct.SalePrice);
            Assert.AreEqual(product.regular_price, svProduct.RegularPrice);
            Assert.AreEqual(1, svProduct.Attributes.Count);
            Assert.AreEqual(product.attributes[0].name, svProduct.Attributes.First().Key);
            Assert.AreEqual(product.attributes[0].options.First(), svProduct.Attributes.First().Value);
            Assert.AreEqual(product.variations.Any(), svProduct.HasVariations);
            Assert.AreEqual(product.date_created_gmt, svProduct.CreatedDateUtc);
            Assert.AreEqual(product.date_modified_gmt, svProduct.UpdatedDateUtc);
        }
Example #6
0
        private bool GetFixedPriceProperty(Product product)
        {
            var value = (string)product.meta_data.FirstOrDefault(meta => meta.key == _fixedPriceMetaKey)?.value;

            return(bool.TryParse(value, out var result) ? result : false);
        }
Example #7
0
        public async void createPost(LProduct lProduct)
        {
            //Get all products
            //var products = await wc.Product.GetAll();

            List <ProductImage> productImages = new List <ProductImage>();
            int i = 0;

            foreach (var image in lProduct.Images)
            {
                ProductImage pi = new ProductImage();
                pi.date_created = DateTime.Now;
                pi.src          = image.Large;
                pi.alt          = lProduct.Title;
                pi.date_created = DateTime.Now.AddMinutes(-10);
                pi.name         = lProduct.TitleEn + "_" + lProduct.Title + "_" + i++;

                productImages.Add(pi);
            }

            List <ProductTagLine> productTags = new List <ProductTagLine>();

            foreach (var tag in lProduct.Keywords)
            {
                var tagResult = wc.Tag.Get(tag);
                var t         = new ProductTagLine();
                if (tagResult != null)
                {
                    t.id = tagResult.Id;
                }
                else
                {
                    ProductTag newTag = new ProductTag();
                    newTag.name = tag;
                    t.id        = (wc.Tag.Add(newTag)).Id;
                }
                productTags.Add(t);
            }

            var             vacCatId = wc.Category.Get("vacuumpump").Id;
            ProductCategory pc       = new ProductCategory()
            {
                name = lProduct.Category, parent = vacCatId
            };
            var getddd = wc.Category.Add(pc);


            //Add new product
            var p = new WooCommerceNET.WooCommerce.v3.Product()
            {
                name              = lProduct.Title,
                images            = productImages,
                description       = string.IsNullOrWhiteSpace(lProduct.Html) ? string.Empty : $"<div>{lProduct.Html}</div><br /><div style='direction:ltr !important;text-align: left;'><h2>Description</h2>{lProduct.HtmlEn}</div>",
                price             = 0,
                tags              = productTags,
                date_created      = DateTime.Now.AddHours(-5),
                date_on_sale_from = DateTime.Now.AddHours(-3),
                categories        = new List <ProductCategoryLine>()
                {
                    new ProductCategoryLine {
                        name = lProduct.Category
                    }
                }
            };
            await wc.Product.Add(p);
        }