Beispiel #1
0
        public ActionResult UpdateProduct(YandexMarketProductRecord model, GridCommand command)
        {
            var product = _yandexMarketProductService.GetById(model.Id);

            product.Name = model.Name;

            _yandexMarketProductService.Update(product);

            return(ListProduct(model.YandexMarketCategoryRecordId, command));
        }
Beispiel #2
0
        /// <summary>
        /// Deletes a tax rate
        /// </summary>
        /// <param name="product">Tax rate</param>
        public virtual void Delete(YandexMarketProductRecord product)
        {
            if (product == null)
            {
                throw new ArgumentNullException("YandexMarketProductRecord");
            }

            this._productRepository.Delete(product);

            this._cacheManager.RemoveByPattern(YANDEXMARKETProduct_PATTERN_KEY);
        }
Beispiel #3
0
        private void SaveImages(YandexMarketProductRecord product)
        {
            try
            {
                // Get main image
                var imageUrl = this.mDriver.FindElement(By.CssSelector(this.CssSelectorForProductPictureInProductPage)).GetAttribute("src");
                //Thread.Sleep(3000);
                // do it twice because of some bag
                imageUrl = this.mDriver.FindElement(By.CssSelector(this.CssSelectorForProductPictureInProductPage)).GetAttribute("src");

                if (imageUrl.ToLower().Contains(".jpg") || imageUrl.ToLower().Contains(".gif"))
                {
                    product.ImageUrl_1 = this.SaveImage(imageUrl, product.Name);
                }

                // Get other images
                if (CssSelectorForProductPicturesInProductPage != string.Empty)
                {
                    //driver.manage().timeouts().implicitlyWait(0, TimeUnit.MILLISECONDS)
                    mDriver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(1));
                    var imagesLinks  = this.mDriver.FindElements(By.CssSelector(this.CssSelectorForProductPicturesInProductPage));
                    int imageCounter = 2;
                    foreach (var curImagesLink in imagesLinks)
                    {
                        var curImageUrl = curImagesLink.GetAttribute("href");
                        if (curImageUrl.ToLower().Contains(".jpg") || curImageUrl.ToLower().Contains(".gif"))
                        {
                            if (product.ImageUrl_1 != "")
                            {
                                product.ImageUrl_1 += ";";
                            }

                            product.ImageUrl_1 += this.SaveImage(curImageUrl, product.Name + "_" + imageCounter);
                            imageCounter++;
                        }
                    }
                }
            }
            catch
            {
                this.mLogger.Debug("Error while images saving.");
                throw;
            }
        }
Beispiel #4
0
        private void GetSpecs(YandexMarketProductRecord product)
        {
            var specificationElements = this.mDriver.FindElements(By.CssSelector(this.CssSelectorForProductSpecsRowsInProductPage));

            this.mLogger.Debug("Have product " + product.Name + ". Start getting " + specificationElements.Count + " specs...");

            foreach (var currentSpecificationElement in specificationElements)
            {
                // Key
                IWebElement currentKeyElement;
                try
                {
                    currentKeyElement = currentSpecificationElement.FindElement(
                        By.CssSelector(this.CssSelectorForProductSpecKeyInProductPage));
                    while (currentKeyElement.Text == "")
                    {
                        var x = ((OpenQA.Selenium.Remote.RemoteWebElement)(currentKeyElement)).LocationOnScreenOnceScrolledIntoView.X;
                        if (x == 9999998)
                        {
                            continue;
                        }
                        //Thread.Sleep(1000);
                        currentKeyElement =
                            currentSpecificationElement.FindElement(By.CssSelector(this.CssSelectorForProductSpecKeyInProductPage));
                    }
                }
                catch (NoSuchElementException)
                {
                    this.mLogger.Debug("not key");
                    continue;
                }

                // Value
                var currentValueElement =
                    currentSpecificationElement.FindElement(By.CssSelector(this.CssSelectorForProductSpecValInProductPage));
                var currentValueHtml = ParserHelper.GetInnerHtml(currentValueElement);

                product.Specifications.Add(new YandexMarketSpecRecord(currentKeyElement.Text.Trim(), currentValueHtml.Trim()));
            }

            this.mLogger.Debug("Finished getting specs.");
        }
Beispiel #5
0
        private YandexMarketProductRecord ProcessProductLink(string productLink)
        {
            // Переходим на страницу спецификации товара
            mDriver.Navigate().GoToUrl(productLink.Replace("model.xml", "model-spec.xml"));
            Thread.Sleep(3000);

            var product = new YandexMarketProductRecord();

            // Найти имя товара
            product.Name = mDriver.FindElement(By.CssSelector("h1.b-page-title")).Text;

            // Скачиваем картинку
            var imageUrl = mDriver.FindElement(By.CssSelector("div.b-model-microcard__img img")).GetAttribute("src");

            Thread.Sleep(3000);
            imageUrl           = mDriver.FindElement(By.CssSelector("div.b-model-microcard__img img")).GetAttribute("src");
            product.ImageUrl_1 = SaveImage(imageUrl, product.Name);

            // Найти спецификации товара	table.b-properties tr
            var specificationElements = mDriver.FindElements(By.CssSelector("table.b-properties tr"));

            foreach (var currentSpecificationElement in specificationElements)
            {
                // Key
                IWebElement currentKeyElement;
                try
                {
                    currentKeyElement = currentSpecificationElement.FindElement(By.CssSelector("th.b-properties__label span"));
                }
                catch (NoSuchElementException)
                {
                    continue;
                }

                // Value
                var currentValueElement = currentSpecificationElement.FindElement(By.CssSelector("td.b-properties__value"));

                product.Specifications.Add(new YandexMarketSpecRecord(currentKeyElement.Text, currentValueElement.Text));
            }

            return(product);
        }
Beispiel #6
0
        private YandexMarketProductRecord CreateProduct(string productLink)
        {
            var product = new YandexMarketProductRecord();

            product.Url = productLink;

            // Переходим на страницу спецификации товара
            var pageSpecsUrl = GetLinkToSpecsTabOfProduct(productLink);

            this.mDriver.Navigate().GoToUrl(pageSpecsUrl);
            //Thread.Sleep(3000);

            this.mLogger.Debug("Have specs page " + pageSpecsUrl);

            product.YandexMarketCategoryRecordId = ParserCategoryId;

            // Artikul
            if (CssSelectorForProductArticulInProductPage != string.Empty)
            {
                product.Articul = ParserHelper.FindElement(mDriver, CssSelectorForProductArticulInProductPage).Text.Replace("Код: ", "");
            }

            // Если продукта в прайсе нет, то создаем полупустой продукт с url и артикулом, что бы не заходить в него следующий раз
            product.IsNotInPriceList = !ProductsArtikulsInPiceList.Contains(product.Articul);

            if (!product.IsNotInPriceList)
            {
                // Найти имя товара
                product.Name = this.mDriver.FindElement(By.CssSelector(CssSelectorForProductNameInProductPage)).Text;

                // Скачиваем картинки
                this.SaveImages(product);

                // Найти спецификации товара
                this.GetSpecs(product);

                // Переходим на страницу описания товара
                // this.mDriver.Navigate().GoToUrl(productLink);
                //Thread.Sleep(3000);

                // this.mLogger.Debug("Have main product page " + productLink);

                if (CssSelectorForProductFullDescriptionInProductPage != string.Empty)
                {
                    try
                    {
                        product.FullDescription =
                            ParserHelper.GetInnerHtml(this.mDriver.FindElement(By.CssSelector(CssSelectorForProductFullDescriptionInProductPage)));
                    }
                    catch (Exception ex)
                    {
                        product.FullDescription = "Нет описания";

                        if (!ex.Message.Contains("Unable to find element"))
                        {
                            throw;
                        }
                    }
                }

                product = ProductPostProcessing(product);
            }
            else
            {
                this.mLogger.Debug("Create NotInPriceList fantom product");
            }

            mLogger.Debug("Saving product...");
            _yandexMarketProductService.Insert(product);
            mLogger.Debug("Saving product Done.");

            if (!product.IsNotInPriceList)
            {
                return(product);
            }
            else
            {
                return(null);
            }
        }
Beispiel #7
0
 protected virtual YandexMarketProductRecord ProductPostProcessing(YandexMarketProductRecord product)
 {
     return(product);
 }
        private bool ImportYaProduct(YandexMarketProductRecord yaProduct, int shopCategoryId, IEnumerable <SpecificationAttribute> allSpecAttrList)
        {
            Product product;
            var     variant = _productService.GetProductVariantBySku(yaProduct.Articul);

            bool isUpdating = variant != null;

            // create or update item
            if (isUpdating)
            {
                // product = variant.Product;
                return(false);                // Не обновляем существующие товары
            }
            else
            {
                product = new Product
                {
                    CreatedOnUtc = DateTime.UtcNow,
                    Published    = true,
                };

                variant = new ProductVariant
                {
                    ProductId                = product.Id,
                    Published                = true,
                    DisplayOrder             = 1,
                    CreatedOnUtc             = DateTime.UtcNow,
                    OrderMinimumQuantity     = 1,
                    OrderMaximumQuantity     = 10,
                    ManageInventoryMethodId  = 0,
                    DisplayStockAvailability = true,
                    DisplayStockQuantity     = true,
                    IsFreeShipping           = false,
                    IsShipEnabled            = true,
                    AdditionalShippingCharge = 20,
                    IsTaxExempt              = true,
                    Price = 0,
                    AvailableForPreOrder = true,
                };
            }

            //product
            product.UpdatedOnUtc     = DateTime.UtcNow;
            product.Name             = yaProduct.Name;
            product.FullDescription  = yaProduct.FullDescription;
            product.ShortDescription = CreateShortDescription(yaProduct.Specifications);

            //variant
            variant.UpdatedOnUtc = DateTime.UtcNow;
            variant.Sku          = yaProduct.Articul;
            variant.Name         = yaProduct.Name;

            // Insert or Updating
            if (isUpdating)
            {
                _productService.UpdateProduct(product);
                _productService.UpdateProductVariant(variant);
            }
            else
            {
                try
                {
                    _productService.InsertProduct(product);
                    variant.ProductId = product.Id;
                    _productService.InsertProductVariant(variant);

                    SaveCategory(shopCategoryId, product.Id);
                    SaveSpecList(product, yaProduct.Specifications, shopCategoryId, allSpecAttrList);


                    SavePictures(product, yaProduct.ImageUrl_1);

                    //search engine name
                    var seName = product.ValidateSeName("", product.Name, true);
                    _urlRecordService.SaveSlug(product, seName, 0);
                }
                catch
                {
                    if (product.Id > 0)
                    {
                        _productService.DeleteProduct(product);
                    }
                    throw;
                }
            }

            return(true);
        }