예제 #1
0
        private string Size(GoogleProductRecord googleProduct)
        {
            if (googleProduct != null && googleProduct.Size.HasValue())
            {
                return(googleProduct.Size);
            }

            return(Settings.Size);
        }
예제 #2
0
        private string Material(GoogleProductRecord googleProduct)
        {
            if (googleProduct != null && googleProduct.Material.HasValue())
            {
                return(googleProduct.Material);
            }

            return(Settings.Material);
        }
예제 #3
0
        public virtual void InsertGoogleProductRecord(GoogleProductRecord googleProductRecord)
        {
            if (googleProductRecord == null)
            {
                throw new ArgumentNullException(nameof(googleProductRecord));
            }

            _gpRepository.Insert(googleProductRecord);
        }
예제 #4
0
        private string Color(GoogleProductRecord googleProduct)
        {
            if (googleProduct != null && googleProduct.Color.HasValue())
            {
                return(googleProduct.Color);
            }

            return(Settings.Color);
        }
예제 #5
0
        public virtual void DeleteGoogleProduct(GoogleProductRecord googleProductRecord)
        {
            if (googleProductRecord == null)
            {
                throw new ArgumentNullException(nameof(googleProductRecord));
            }

            _gpRepository.Delete(googleProductRecord);
        }
예제 #6
0
        public virtual async Task UpdateGoogleProductRecord(GoogleProductRecord googleProductRecord)
        {
            if (googleProductRecord == null)
            {
                throw new ArgumentNullException("googleProductRecord");
            }

            await _gpRepository.UpdateAsync(googleProductRecord);
        }
예제 #7
0
 public static bool IsTouched(this GoogleProductRecord product)
 {
     if (product != null)
     {
         return(product.Taxonomy.HasValue() || product.Gender.HasValue() || product.AgeGroup.HasValue() || product.Color.HasValue() ||
                product.Size.HasValue() || product.Material.HasValue() || product.Pattern.HasValue() || product.ItemGroupId.HasValue());
     }
     return(false);
 }
예제 #8
0
        private string Pattern(GoogleProductRecord googleProduct)
        {
            if (googleProduct != null && googleProduct.Pattern.HasValue())
            {
                return(googleProduct.Pattern);
            }

            return(Settings.Pattern);
        }
예제 #9
0
        private string ItemGroupId(GoogleProductRecord googleProduct)
        {
            if (googleProduct != null && googleProduct.ItemGroupId.HasValue())
            {
                return(googleProduct.ItemGroupId);
            }

            return("");
        }
예제 #10
0
        public virtual void UpdateGoogleProductRecord(GoogleProductRecord googleProductRecord)
        {
            if (googleProductRecord == null)
            {
                throw new ArgumentNullException("googleProductRecord");
            }

            _gpRepository.Update(googleProductRecord);
        }
예제 #11
0
        public void DeleteGoogleProductRecord(GoogleProductRecord record)
        {
            if (record == null)
            {
                throw new ArgumentNullException("record");
            }

            _gpRepository.Delete(record);
        }
예제 #12
0
        public void InsertGoogleProductRecord(GoogleProductRecord record)
        {
            if (record == null)
            {
                throw new ArgumentNullException("googleProductRecord");
            }

            _gpRepository.Insert(record);
        }
예제 #13
0
        public void HandleEvent(ModelBoundEvent eventMessage)
        {
            if (!eventMessage.BoundModel.CustomProperties.ContainsKey("GMC"))
            {
                return;
            }

            var model = eventMessage.BoundModel.CustomProperties["GMC"] as GoogleProductModel;

            if (model == null)
            {
                return;
            }

            var utcNow = DateTime.UtcNow;
            var entity = _googleService.GetGoogleProductRecord(model.ProductId);
            var insert = (entity == null);

            if (entity == null)
            {
                entity = new GoogleProductRecord
                {
                    ProductId    = model.ProductId,
                    CreatedOnUtc = utcNow
                };
            }

            // map objects
            entity.AgeGroup     = model.AgeGroup;
            entity.Color        = model.Color;
            entity.Gender       = model.Gender;
            entity.Size         = model.Size;
            entity.Taxonomy     = model.Taxonomy;
            entity.Material     = model.Material;
            entity.Pattern      = model.Pattern;
            entity.Export       = model.Exporting;
            entity.UpdatedOnUtc = utcNow;

            entity.IsTouched = entity.IsTouched();

            if (!insert && !entity.IsTouched)
            {
                _googleService.DeleteGoogleProductRecord(entity);
                return;
            }

            if (insert)
            {
                _googleService.InsertGoogleProductRecord(entity);
            }
            else
            {
                _googleService.UpdateGoogleProductRecord(entity);
            }
        }
예제 #14
0
 public static bool IsTouched(this GoogleProductRecord p)
 {
     if (p != null)
     {
         return
             (p.Taxonomy.HasValue() || p.Gender.HasValue() || p.AgeGroup.HasValue() || p.Color.HasValue() ||
              p.Size.HasValue() || p.Material.HasValue() || p.Pattern.HasValue() || p.ItemGroupId.HasValue() ||
              !p.Export || p.Multipack != 0 || p.IsBundle.HasValue || p.IsAdult.HasValue || p.EnergyEfficiencyClass.HasValue() ||
              p.CustomLabel0.HasValue() || p.CustomLabel1.HasValue() || p.CustomLabel2.HasValue() || p.CustomLabel3.HasValue() || p.CustomLabel4.HasValue());
     }
     return(false);
 }
예제 #15
0
        private string AgeGroup(GoogleProductRecord googleProduct)
        {
            if (Settings.AgeGroup.IsCaseInsensitiveEqual(PluginHelperBase.NotSpecified))
            {
                return("");
            }

            if (googleProduct != null && googleProduct.AgeGroup.HasValue())
            {
                return(googleProduct.AgeGroup);
            }

            return(Settings.AgeGroup);
        }
예제 #16
0
        private string Gender(GoogleProductRecord googleProduct)
        {
            if (Settings.Gender.IsCaseInsensitiveEqual(PluginHelper.NotSpecified))
            {
                return("");
            }

            if (googleProduct != null && googleProduct.Gender.HasValue())
            {
                return(googleProduct.Gender);
            }

            return(Settings.Gender);
        }
예제 #17
0
        public virtual void UpdateInsert(int pk, string name, string value)
        {
            if (pk == 0 || name.IsNullOrEmpty())
            {
                return;
            }

            var  product = GetByProductId(pk);
            bool insert  = (product == null);

            if (insert)
            {
                product = new GoogleProductRecord()
                {
                    ProductId = pk
                };
            }

            switch (name)
            {
            case "GoogleCategory":
                product.Taxonomy = value;
                break;

            case "Gender":
                product.Gender = value;
                break;

            case "AgeGroup":
                product.AgeGroup = value;
                break;

            case "Color":
                product.Color = value;
                break;

            case "GoogleSize":
                product.Size = value;
                break;
            }

            if (insert)
            {
                InsertGoogleProductRecord(product);
            }
            else
            {
                UpdateGoogleProductRecord(product);
            }
        }
예제 #18
0
        private string ProductCategory(GoogleProductRecord googleProduct)
        {
            string productCategory = "";

            if (googleProduct != null)
            {
                productCategory = googleProduct.Taxonomy;
            }

            if (productCategory.IsNullOrEmpty())
            {
                productCategory = Settings.DefaultGoogleCategory;
            }

            return(productCategory);
        }
예제 #19
0
        public IActionResult Edit(GoogleProductModel model)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManagePlugins))
            {
                return(AccessDeniedView());
            }

            var googleProduct = _googleService.GetByProductId(model.ProductId);

            if (googleProduct != null)
            {
                googleProduct.Taxonomy    = model.GoogleCategory;
                googleProduct.Gender      = model.Gender;
                googleProduct.AgeGroup    = model.AgeGroup;
                googleProduct.Color       = model.Color;
                googleProduct.Size        = model.GoogleSize;
                googleProduct.CustomGoods = model.CustomGoods;
                _googleService.UpdateGoogleProductRecord(googleProduct);
            }
            else
            {
                //insert
                googleProduct = new GoogleProductRecord
                {
                    ProductId   = model.ProductId,
                    Taxonomy    = model.GoogleCategory,
                    Gender      = model.Gender,
                    AgeGroup    = model.AgeGroup,
                    Color       = model.Color,
                    Size        = model.GoogleSize,
                    CustomGoods = model.CustomGoods
                };
                _googleService.InsertGoogleProductRecord(googleProduct);
            }

            ViewBag.RefreshPage = true;

            return(View("~/Plugins/Feed.GoogleShopping/Views/Edit.cshtml", model));
        }
        public ActionResult GoogleProductUpdate(GridCommand command, FeedFroogleModel.GoogleProductModel model)
        {
            var googleProduct = _googleService.GetByProductVariantId(model.ProductVariantId);

            if (googleProduct != null)
            {
                //update
                googleProduct.Taxonomy = model.GoogleCategory;
                _googleService.UpdateGoogleProductRecord(googleProduct);
            }
            else
            {
                //insert
                googleProduct = new GoogleProductRecord()
                {
                    ProductVariantId = model.ProductVariantId,
                    Taxonomy         = model.GoogleCategory
                };
                _googleService.InsertGoogleProductRecord(googleProduct);
            }

            return(GoogleProductList(command));
        }
예제 #21
0
        public ActionResult GoogleProductUpdate(FeedGoogleShoppingModel.GoogleProductModel model)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManagePlugins))
            {
                return(Content("Access denied"));
            }

            var googleProduct = _googleService.GetByProductId(model.ProductId);

            if (googleProduct != null)
            {
                googleProduct.Taxonomy    = model.GoogleCategory;
                googleProduct.Gender      = model.Gender;
                googleProduct.AgeGroup    = model.AgeGroup;
                googleProduct.Color       = model.Color;
                googleProduct.Size        = model.GoogleSize;
                googleProduct.CustomGoods = model.CustomGoods;
                _googleService.UpdateGoogleProductRecord(googleProduct);
            }
            else
            {
                //insert
                googleProduct = new GoogleProductRecord
                {
                    ProductId   = model.ProductId,
                    Taxonomy    = model.GoogleCategory,
                    Gender      = model.Gender,
                    AgeGroup    = model.AgeGroup,
                    Color       = model.Color,
                    Size        = model.GoogleSize,
                    CustomGoods = model.CustomGoods
                };
                _googleService.InsertGoogleProductRecord(googleProduct);
            }

            return(new NullJsonResult());
        }
예제 #22
0
        public void HandleEvent(ModelBoundEvent eventMessage)
        {
            if (!eventMessage.BoundModel.CustomProperties.ContainsKey("GMC"))
            {
                return;
            }

            var model = eventMessage.BoundModel.CustomProperties["GMC"] as GoogleProductModel;

            if (model == null)
            {
                return;
            }

            var utcNow = DateTime.UtcNow;
            var entity = _googleService.GetGoogleProductRecord(model.ProductId);
            var insert = (entity == null);

            if (entity == null)
            {
                entity = new GoogleProductRecord
                {
                    ProductId    = model.ProductId,
                    CreatedOnUtc = utcNow
                };
            }

            entity.AgeGroup              = model.AgeGroup;
            entity.Color                 = model.Color;
            entity.Gender                = model.Gender;
            entity.Size                  = model.Size;
            entity.Taxonomy              = model.Taxonomy;
            entity.Material              = model.Material;
            entity.Pattern               = model.Pattern;
            entity.Export                = model.Export2;
            entity.UpdatedOnUtc          = utcNow;
            entity.Multipack             = model.Multipack2 ?? 0;
            entity.IsBundle              = model.IsBundle;
            entity.IsAdult               = model.IsAdult;
            entity.EnergyEfficiencyClass = model.EnergyEfficiencyClass;
            entity.CustomLabel0          = model.CustomLabel0;
            entity.CustomLabel1          = model.CustomLabel1;
            entity.CustomLabel2          = model.CustomLabel2;
            entity.CustomLabel3          = model.CustomLabel3;
            entity.CustomLabel4          = model.CustomLabel4;

            entity.IsTouched = entity.IsTouched();

            if (!insert && !entity.IsTouched)
            {
                _googleService.DeleteGoogleProductRecord(entity);
                return;
            }

            if (insert)
            {
                _googleService.InsertGoogleProductRecord(entity);
            }
            else
            {
                _googleService.UpdateGoogleProductRecord(entity);
            }
        }
예제 #23
0
        public void UpdateInsert(int pk, string name, string value)
        {
            if (pk == 0 || name.IsNullOrEmpty())
            {
                return;
            }

            var  product = GetGoogleProductRecord(pk);
            bool insert  = (product == null);
            var  utcNow  = DateTime.UtcNow;

            if (product == null)
            {
                product = new GoogleProductRecord()
                {
                    ProductId    = pk,
                    CreatedOnUtc = utcNow
                };
            }

            switch (name)
            {
            case "Taxonomy":
                product.Taxonomy = value;
                break;

            case "Gender":
                product.Gender = value;
                break;

            case "AgeGroup":
                product.AgeGroup = value;
                break;

            case "Color":
                product.Color = value;
                break;

            case "Size":
                product.Size = value;
                break;

            case "Material":
                product.Material = value;
                break;

            case "Pattern":
                product.Pattern = value;
                break;
            }

            product.UpdatedOnUtc = utcNow;
            product.IsTouched    = product.IsTouched();

            if (!insert && !product.IsTouched)
            {
                _gpRepository.Delete(product);
                return;
            }

            if (insert)
            {
                _gpRepository.Insert(product);
            }
            else
            {
                _gpRepository.Update(product);
            }
        }
예제 #24
0
        private void WriteItem(FeedFileCreationContext fileCreation, XmlWriter writer, Product product, Currency currency, string measureWeightSystemKey)
        {
            GoogleProductRecord googleProduct = null;

            try
            {
                googleProduct = GetGoogleProductRecord(product.Id);

                if (googleProduct != null && !googleProduct.Export)
                {
                    return;
                }
            }
            catch (Exception exc)
            {
                fileCreation.Logger.Error(exc.Message, exc);
            }

            writer.WriteStartElement("item");

            try
            {
                var manu         = _manufacturerService.GetProductManufacturersByProductId(product.Id).FirstOrDefault();
                var mainImageUrl = Helper.GetMainProductImageUrl(fileCreation.Store, product);
                var category     = ProductCategory(googleProduct);

                if (category.IsEmpty())
                {
                    fileCreation.ErrorMessage = Helper.GetResource("MissingDefaultCategory");
                }

                string manuName         = (manu != null ? manu.Manufacturer.GetLocalized(x => x.Name, Settings.LanguageId, true, false) : null);
                string productName      = product.GetLocalized(x => x.Name, Settings.LanguageId, true, false);
                string shortDescription = product.GetLocalized(x => x.ShortDescription, Settings.LanguageId, true, false);
                string fullDescription  = product.GetLocalized(x => x.FullDescription, Settings.LanguageId, true, false);

                var brand = (manuName ?? Settings.Brand);
                var mpn   = Helper.GetManufacturerPartNumber(product);

                bool identifierExists = product.Gtin.HasValue() || brand.HasValue() || mpn.HasValue();

                writer.WriteElementString("g", "id", _googleNamespace, product.Id.ToString());

                writer.WriteStartElement("title");
                writer.WriteCData(productName.Truncate(70));
                writer.WriteEndElement();

                var description = Helper.BuildProductDescription(productName, shortDescription, fullDescription, manuName, d =>
                {
                    if (fullDescription.IsEmpty() && shortDescription.IsEmpty())
                    {
                        var rnd = new Random();

                        switch (rnd.Next(1, 5))
                        {
                        case 1: return(d.Grow(Settings.AppendDescriptionText1, " "));

                        case 2: return(d.Grow(Settings.AppendDescriptionText2, " "));

                        case 3: return(d.Grow(Settings.AppendDescriptionText3, " "));

                        case 4: return(d.Grow(Settings.AppendDescriptionText4, " "));

                        case 5: return(d.Grow(Settings.AppendDescriptionText5, " "));
                        }
                    }
                    return(d);
                });

                writer.WriteStartElement("description");
                writer.WriteCData(description.RemoveInvalidXmlChars());
                writer.WriteEndElement();

                writer.WriteStartElement("g", "google_product_category", _googleNamespace);
                writer.WriteCData(category);
                writer.WriteFullEndElement();

                string productType = Helper.GetCategoryPath(product);
                if (productType.HasValue())
                {
                    writer.WriteStartElement("g", "product_type", _googleNamespace);
                    writer.WriteCData(productType);
                    writer.WriteFullEndElement();
                }

                writer.WriteElementString("link", Helper.GetProductDetailUrl(fileCreation.Store, product));
                writer.WriteElementString("g", "image_link", _googleNamespace, mainImageUrl);

                foreach (string additionalImageUrl in Helper.GetAdditionalProductImages(fileCreation.Store, product, mainImageUrl))
                {
                    writer.WriteElementString("g", "additional_image_link", _googleNamespace, additionalImageUrl);
                }

                writer.WriteElementString("g", "condition", _googleNamespace, Condition());
                writer.WriteElementString("g", "availability", _googleNamespace, Availability(product));

                decimal price = Helper.GetProductPrice(product, currency);
                string  specialPriceDate;

                if (SpecialPrice(product, out specialPriceDate))
                {
                    writer.WriteElementString("g", "sale_price", _googleNamespace, price.FormatInvariant() + " " + currency.CurrencyCode);
                    writer.WriteElementString("g", "sale_price_effective_date", _googleNamespace, specialPriceDate);

                    // get regular price ignoring any special price
                    decimal specialPrice = product.SpecialPrice.Value;
                    product.SpecialPrice = null;
                    price = Helper.GetProductPrice(product, currency);
                    product.SpecialPrice = specialPrice;

                    _dbContext.SetToUnchanged <Product>(product);
                }

                writer.WriteElementString("g", "price", _googleNamespace, price.FormatInvariant() + " " + currency.CurrencyCode);

                writer.WriteCData("gtin", product.Gtin, "g", _googleNamespace);
                writer.WriteCData("brand", brand, "g", _googleNamespace);
                writer.WriteCData("mpn", mpn, "g", _googleNamespace);

                writer.WriteCData("gender", Gender(googleProduct), "g", _googleNamespace);
                writer.WriteCData("age_group", AgeGroup(googleProduct), "g", _googleNamespace);
                writer.WriteCData("color", Color(googleProduct), "g", _googleNamespace);
                writer.WriteCData("size", Size(googleProduct), "g", _googleNamespace);
                writer.WriteCData("material", Material(googleProduct), "g", _googleNamespace);
                writer.WriteCData("pattern", Pattern(googleProduct), "g", _googleNamespace);
                writer.WriteCData("item_group_id", ItemGroupId(googleProduct), "g", _googleNamespace);

                writer.WriteElementString("g", "online_only", _googleNamespace, Settings.OnlineOnly ? "y" : "n");
                writer.WriteElementString("g", "identifier_exists", _googleNamespace, identifierExists ? "TRUE" : "FALSE");

                if (Settings.ExpirationDays > 0)
                {
                    writer.WriteElementString("g", "expiration_date", _googleNamespace, DateTime.UtcNow.AddDays(Settings.ExpirationDays).ToString("yyyy-MM-dd"));
                }

                if (Settings.ExportShipping)
                {
                    string weightInfo, weight = product.Weight.FormatInvariant();

                    if (measureWeightSystemKey.IsCaseInsensitiveEqual("gram"))
                    {
                        weightInfo = weight + " g";
                    }
                    else if (measureWeightSystemKey.IsCaseInsensitiveEqual("lb"))
                    {
                        weightInfo = weight + " lb";
                    }
                    else if (measureWeightSystemKey.IsCaseInsensitiveEqual("ounce"))
                    {
                        weightInfo = weight + " oz";
                    }
                    else
                    {
                        weightInfo = weight + " kg";
                    }

                    writer.WriteElementString("g", "shipping_weight", _googleNamespace, weightInfo);
                }

                if (Settings.ExportBasePrice && product.BasePriceHasValue)
                {
                    string measureUnit = BasePriceUnits(product.BasePriceMeasureUnit);

                    if (BasePriceSupported(product.BasePriceBaseAmount ?? 0, measureUnit))
                    {
                        string basePriceMeasure     = "{0} {1}".FormatWith((product.BasePriceAmount ?? decimal.Zero).FormatInvariant(), measureUnit);
                        string basePriceBaseMeasure = "{0} {1}".FormatWith(product.BasePriceBaseAmount, measureUnit);

                        writer.WriteElementString("g", "unit_pricing_measure", _googleNamespace, basePriceMeasure);
                        writer.WriteElementString("g", "unit_pricing_base_measure", _googleNamespace, basePriceBaseMeasure);
                    }
                }
            }
            catch (Exception exc)
            {
                fileCreation.Logger.Error(exc.Message, exc);
            }

            writer.WriteEndElement();             // item
        }
예제 #25
0
        public void Upsert(int pk, string name, string value)
        {
            if (pk == 0 || name.IsEmpty())
            {
                return;
            }

            var product = GetGoogleProductRecord(pk);
            var insert  = (product == null);
            var utcNow  = DateTime.UtcNow;

            if (product == null)
            {
                product = new GoogleProductRecord
                {
                    ProductId    = pk,
                    CreatedOnUtc = utcNow
                };
            }

            switch (name)
            {
            case "Taxonomy":
                product.Taxonomy = value;
                break;

            case "Gender":
                product.Gender = value;
                break;

            case "AgeGroup":
                product.AgeGroup = value;
                break;

            case "Color":
                product.Color = value;
                break;

            case "Size":
                product.Size = value;
                break;

            case "Material":
                product.Material = value;
                break;

            case "Pattern":
                product.Pattern = value;
                break;

            case "Export2":
                product.Export = value.ToBool(true);
                break;

            case "Multipack2":
                product.Multipack = value.ToInt();
                break;

            case "IsBundle":
                product.IsBundle = (value.IsEmpty() ? (bool?)null : value.ToBool());
                break;

            case "IsAdult":
                product.IsAdult = (value.IsEmpty() ? (bool?)null : value.ToBool());
                break;

            case "EnergyEfficiencyClass":
                product.EnergyEfficiencyClass = value;
                break;

            case "CustomLabel0":
                product.CustomLabel0 = value;
                break;

            case "CustomLabel1":
                product.CustomLabel1 = value;
                break;

            case "CustomLabel2":
                product.CustomLabel2 = value;
                break;

            case "CustomLabel3":
                product.CustomLabel3 = value;
                break;

            case "CustomLabel4":
                product.CustomLabel4 = value;
                break;
            }

            product.UpdatedOnUtc = utcNow;
            product.IsTouched    = product.IsTouched();

            if (!insert && !product.IsTouched)
            {
                _gpRepository.Delete(product);
                return;
            }

            if (insert)
            {
                _gpRepository.Insert(product);
            }
            else
            {
                _gpRepository.Update(product);
            }
        }