public IActionResult Configure()
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManagePlugins))
            {
                return(AccessDeniedView());
            }

            var model = new FeedGoogleShoppingModel();

            model.ProductPictureSize         = _googleShoppingSettings.ProductPictureSize;
            model.PassShippingInfoWeight     = _googleShoppingSettings.PassShippingInfoWeight;
            model.PassShippingInfoDimensions = _googleShoppingSettings.PassShippingInfoDimensions;
            model.PricesConsiderPromotions   = _googleShoppingSettings.PricesConsiderPromotions;
            //stores
            model.StoreId = _googleShoppingSettings.StoreId;
            model.AvailableStores.Add(new SelectListItem {
                Text = _localizationService.GetResource("Admin.Common.All"), Value = "0"
            });
            foreach (var s in _storeService.GetAllStores())
            {
                model.AvailableStores.Add(new SelectListItem {
                    Text = s.Name, Value = s.Id.ToString()
                });
            }
            //currencies
            model.CurrencyId = _googleShoppingSettings.CurrencyId;
            foreach (var c in _currencyService.GetAllCurrencies())
            {
                model.AvailableCurrencies.Add(new SelectListItem {
                    Text = c.Name, Value = c.Id.ToString()
                });
            }
            //Google categories
            model.DefaultGoogleCategory = _googleShoppingSettings.DefaultGoogleCategory;
            model.AvailableGoogleCategories.Add(new SelectListItem {
                Text = "Select a category", Value = ""
            });
            foreach (var gc in _googleService.GetTaxonomyList())
            {
                model.AvailableGoogleCategories.Add(new SelectListItem {
                    Text = gc, Value = gc
                });
            }

            //file paths
            foreach (var store in _storeService.GetAllStores())
            {
                var localFilePath = System.IO.Path.Combine(_hostingEnvironment.WebRootPath, "files\\exportimport", store.Id + "-" + _googleShoppingSettings.StaticFileName);
                if (System.IO.File.Exists(localFilePath))
                {
                    model.GeneratedFiles.Add(new FeedGoogleShoppingModel.GeneratedFileModel
                    {
                        StoreName = store.Name,
                        FileUrl   = $"{_webHelper.GetStoreLocation(false)}files/exportimport/{store.Id}-{_googleShoppingSettings.StaticFileName}"
                    });
                }
            }

            return(View("~/Plugins/Feed.GoogleShopping/Views/Configure.cshtml", model));
        }
        public IActionResult Configure(FeedGoogleShoppingModel model)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManagePlugins))
            {
                return(AccessDeniedView());
            }

            if (!ModelState.IsValid)
            {
                return(Configure());
            }

            //save settings
            _googleShoppingSettings.ProductPictureSize         = model.ProductPictureSize;
            _googleShoppingSettings.PassShippingInfoWeight     = model.PassShippingInfoWeight;
            _googleShoppingSettings.PassShippingInfoDimensions = model.PassShippingInfoDimensions;
            _googleShoppingSettings.PricesConsiderPromotions   = model.PricesConsiderPromotions;
            _googleShoppingSettings.CurrencyId            = model.CurrencyId;
            _googleShoppingSettings.StoreId               = model.StoreId;
            _googleShoppingSettings.DefaultGoogleCategory = model.DefaultGoogleCategory;
            _settingService.SaveSetting(_googleShoppingSettings);

            SuccessNotification(_localizationService.GetResource("Admin.Plugins.Saved"));

            //redisplay the form
            return(Configure());
        }
コード例 #3
0
        public IActionResult Configure()
        {
            var model = new FeedGoogleShoppingModel();

            PrepareModel(model);

            return(View("~/Plugins/Feed.GoogleShopping/Views/Configure.cshtml", model));
        }
コード例 #4
0
        public async Task <IActionResult> Configure()
        {
            var model = new FeedGoogleShoppingModel();

            model.ProductPictureSize         = _GoogleShoppingSettings.ProductPictureSize;
            model.PassShippingInfoWeight     = _GoogleShoppingSettings.PassShippingInfoWeight;
            model.PassShippingInfoDimensions = _GoogleShoppingSettings.PassShippingInfoDimensions;
            model.PricesConsiderPromotions   = _GoogleShoppingSettings.PricesConsiderPromotions;
            //stores
            model.StoreId = _GoogleShoppingSettings.StoreId;
            model.AvailableStores.Add(new SelectListItem {
                Text = _localizationService.GetResource("Admin.Common.All"), Value = ""
            });
            foreach (var s in await _storeService.GetAllStores())
            {
                model.AvailableStores.Add(new SelectListItem {
                    Text = s.Name, Value = s.Id.ToString()
                });
            }
            //currencies
            model.CurrencyId = _GoogleShoppingSettings.CurrencyId;
            foreach (var c in await _currencyService.GetAllCurrencies())
            {
                model.AvailableCurrencies.Add(new SelectListItem {
                    Text = c.Name, Value = c.Id.ToString()
                });
            }
            //Google categories
            model.DefaultGoogleCategory = _GoogleShoppingSettings.DefaultGoogleCategory;
            model.AvailableGoogleCategories.Add(new SelectListItem {
                Text = "Select a category", Value = ""
            });
            foreach (var gc in await _googleService.GetTaxonomyList())
            {
                model.AvailableGoogleCategories.Add(new SelectListItem {
                    Text = gc, Value = gc
                });
            }

            //file paths
            foreach (var store in await _storeService.GetAllStores())
            {
                var appPath       = CommonHelper.MapPath("wwwroot/content/files/exportimport");
                var localFilePath = System.IO.Path.Combine(appPath, store.Id + "-" + _GoogleShoppingSettings.StaticFileName);
                if (System.IO.File.Exists(localFilePath))
                {
                    model.GeneratedFiles.Add(new FeedGoogleShoppingModel.GeneratedFileModel
                    {
                        StoreName = store.Name,
                        FileUrl   = string.Format("{0}content/files/exportimport/{1}-{2}", _webHelper.GetStoreLocation(false), store.Id, _GoogleShoppingSettings.StaticFileName)
                    });
                }
            }

            return(View("~/Plugins/Feed.GoogleShopping/Views/FeedGoogleShopping/Configure.cshtml", model));
        }
コード例 #5
0
        public IActionResult GenerateFeed(FeedGoogleShoppingModel model)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManagePlugins))
            {
                return(AccessDeniedView());
            }

            //load settings for a chosen store scope
            var storeScope = _storeContext.ActiveStoreScopeConfiguration;

            try
            {
                var pluginDescriptor = _pluginFinder.GetPluginDescriptorBySystemName("PromotionFeed.Froogle");
                if (pluginDescriptor == null)
                {
                    throw new Exception("Cannot load the plugin");
                }

                //plugin
                var plugin = pluginDescriptor.Instance() as GoogleShoppingService;
                if (plugin == null)
                {
                    throw new Exception("Cannot load the plugin");
                }

                var stores    = new List <Store>();
                var storeById = _storeService.GetStoreById(storeScope);
                if (storeScope > 0)
                {
                    stores.Add(storeById);
                }
                else
                {
                    stores.AddRange(_storeService.GetAllStores());
                }

                foreach (var store in stores)
                {
                    plugin.GenerateStaticFile(store);
                }

                SuccessNotification(_localizationService.GetResource("Plugins.Feed.GoogleShopping.SuccessResult"));
            }
            catch (Exception exc)
            {
                ErrorNotification(exc.Message);
                _logger.Error(exc.Message, exc);
            }

            return(Configure());
        }
コード例 #6
0
        public IActionResult Configure(FeedGoogleShoppingModel model)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManagePlugins))
            {
                return(AccessDeniedView());
            }

            if (!ModelState.IsValid)
            {
                return(Configure());
            }

            //load settings for a chosen store scope
            var storeScope             = _storeContext.ActiveStoreScopeConfiguration;
            var googleShoppingSettings = _settingService.LoadSetting <GoogleShoppingSettings>(storeScope);

            //save settings
            googleShoppingSettings.ProductPictureSize         = model.ProductPictureSize;
            googleShoppingSettings.PassShippingInfoWeight     = model.PassShippingInfoWeight;
            googleShoppingSettings.PassShippingInfoDimensions = model.PassShippingInfoDimensions;
            googleShoppingSettings.PricesConsiderPromotions   = model.PricesConsiderPromotions;
            googleShoppingSettings.CurrencyId            = model.CurrencyId;
            googleShoppingSettings.DefaultGoogleCategory = model.DefaultGoogleCategory;
            googleShoppingSettings.StoreId = model.StoreId;

            //_settingService.SaveSetting(_googleShoppingSettings);

            /* We do not clear cache after each setting update.
             * This behavior can increase performance because cached settings will not be cleared
             * and loaded from database after each update */
            _settingService.SaveSettingOverridablePerStore(googleShoppingSettings, x => x.CurrencyId, model.CurrencyId_OverrideForStore, storeScope, false);
            _settingService.SaveSettingOverridablePerStore(googleShoppingSettings, x => x.DefaultGoogleCategory, model.DefaultGoogleCategory_OverrideForStore, storeScope, false);
            _settingService.SaveSettingOverridablePerStore(googleShoppingSettings, x => x.PassShippingInfoDimensions, model.PassShippingInfoDimensions_OverrideForStore, storeScope, false);
            _settingService.SaveSettingOverridablePerStore(googleShoppingSettings, x => x.PassShippingInfoWeight, model.PassShippingInfoWeight_OverrideForStore, storeScope, false);
            _settingService.SaveSettingOverridablePerStore(googleShoppingSettings, x => x.PricesConsiderPromotions, model.PricesConsiderPromotions_OverrideForStore, storeScope, false);
            _settingService.SaveSettingOverridablePerStore(googleShoppingSettings, x => x.ProductPictureSize, model.ProductPictureSize_OverrideForStore, storeScope, false);
            _settingService.SaveSettingOverridablePerStore(googleShoppingSettings, x => x.StoreId, model.StoreId_OvverideForStore, storeScope, false);

            //now clear settings cache
            _settingService.ClearCache();

            SuccessNotification(_localizationService.GetResource("Admin.Plugins.Saved"));

            //redisplay the form
            return(Configure());
        }
コード例 #7
0
        public async Task <IActionResult> GenerateFeed(FeedGoogleShoppingModel model)
        {
            try
            {
                var pluginDescriptor = _pluginFinder.GetPluginDescriptorBySystemName("PromotionFeed.GoogleShopping");
                if (pluginDescriptor == null)
                {
                    throw new Exception("Cannot load the plugin");
                }

                //plugin
                var plugin = pluginDescriptor.Instance(_serviceProvider) as GoogleShoppingService;
                if (plugin == null)
                {
                    throw new Exception("Cannot load the plugin");
                }

                var stores    = new List <Store>();
                var storeById = await _storeService.GetStoreById(_GoogleShoppingSettings.StoreId);

                if (storeById != null)
                {
                    stores.Add(storeById);
                }
                else
                {
                    stores.AddRange(await _storeService.GetAllStores());
                }

                foreach (var store in stores)
                {
                    await plugin.GenerateStaticFile(store);
                }

                SuccessNotification(_localizationService.GetResource("Plugins.Feed.GoogleShopping.SuccessResult"));
            }
            catch (Exception exc)
            {
                ErrorNotification(exc.Message);
                _logger.Error(exc.Message, exc);
            }

            return(await Configure());
        }
コード例 #8
0
        public IActionResult GoogleProductListe(DataSourceRequest command, FeedGoogleShoppingModel model)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManagePlugins))
            {
                return(AccessDeniedKendoGridJson());
            }
            if (_workContext.CurrentVendor != null)
            {
                model.SearchVendorId = _workContext.CurrentVendor.Id;
            }
            var products = _productService.SearchProducts(pageIndex: command.Page - 1,
                                                          pageSize: command.PageSize, showHidden: true, vendorId: model.SearchVendorId,
                                                          keywords: model.SearchProductName);
            var productsModel = products
                                .Select(x =>
            {
                var gModel = new FeedGoogleShoppingModel.FeedGoogleProductModel
                {
                    ProductId   = x.Id,
                    ProductName = x.Name,
                    VendorName  = _vendorService.GetVendorById(x.VendorId).Name,
                    Price       = x.Price
                };
                var googleProduct = _googleService.GetByProductId(x.Id);
                if (googleProduct != null)
                {
                    gModel.Cimri      = googleProduct.Cimri;
                    gModel.GoogleShop = googleProduct.GoogleShop;
                }

                return(gModel);
            })
                                .ToList();

            var gridModel = new DataSourceResult
            {
                Data  = productsModel,
                Total = products.TotalCount
            };

            return(Json(gridModel));
        }
コード例 #9
0
        public async Task <IActionResult> Configure(FeedGoogleShoppingModel model)
        {
            if (!ModelState.IsValid)
            {
                return(await Configure());
            }

            //save settings
            _GoogleShoppingSettings.ProductPictureSize         = model.ProductPictureSize;
            _GoogleShoppingSettings.PassShippingInfoWeight     = model.PassShippingInfoWeight;
            _GoogleShoppingSettings.PassShippingInfoDimensions = model.PassShippingInfoDimensions;
            _GoogleShoppingSettings.PricesConsiderPromotions   = model.PricesConsiderPromotions;
            _GoogleShoppingSettings.CurrencyId            = model.CurrencyId;
            _GoogleShoppingSettings.StoreId               = model.StoreId;
            _GoogleShoppingSettings.DefaultGoogleCategory = model.DefaultGoogleCategory;
            await _settingService.SaveSetting(_GoogleShoppingSettings);

            SuccessNotification(_localizationService.GetResource("Admin.Plugins.Saved"));

            //redisplay the form
            return(await Configure());
        }
コード例 #10
0
        public IActionResult Configure()
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManagePlugins))
            {
                return(AccessDeniedView());
            }

            //load settings for a chosen store scope
            var storeScope             = _storeContext.ActiveStoreScopeConfiguration;
            var googleShoppingSettings = _settingService.LoadSetting <GoogleShoppingSettings>(storeScope);

            var model = new FeedGoogleShoppingModel();

            model.ProductPictureSize         = googleShoppingSettings.ProductPictureSize;
            model.PassShippingInfoWeight     = googleShoppingSettings.PassShippingInfoWeight;
            model.PassShippingInfoDimensions = googleShoppingSettings.PassShippingInfoDimensions;
            model.PricesConsiderPromotions   = googleShoppingSettings.PricesConsiderPromotions;

            //currencies
            model.CurrencyId = googleShoppingSettings.CurrencyId;
            foreach (var c in _currencyService.GetAllCurrencies())
            {
                model.AvailableCurrencies.Add(new SelectListItem {
                    Text = c.Name, Value = c.Id.ToString()
                });
            }
            //Google categories
            model.DefaultGoogleCategory = googleShoppingSettings.DefaultGoogleCategory;
            model.AvailableGoogleCategories.Add(new SelectListItem {
                Text = "Select a category", Value = ""
            });
            foreach (var gc in _googleService.GetTaxonomyList())
            {
                model.AvailableGoogleCategories.Add(new SelectListItem {
                    Text = gc, Value = gc
                });
            }

            //file paths
            foreach (var store in _storeService.GetAllStores())
            {
                var localFilePath = System.IO.Path.Combine(_hostingEnvironment.WebRootPath, "files\\exportimport", store.Id + "-" + googleShoppingSettings.StaticFileName);
                if (System.IO.File.Exists(localFilePath))
                {
                    model.GeneratedFiles.Add(new FeedGoogleShoppingModel.GeneratedFileModel
                    {
                        StoreName = store.Name,
                        FileUrl   = $"{_webHelper.GetStoreLocation(false)}files/exportimport/{store.Id}-{googleShoppingSettings.StaticFileName}"
                    });
                }
            }

            model.ActiveStoreScopeConfiguration = storeScope;
            if (storeScope > 0)
            {
                model.CurrencyId_OverrideForStore                 = _settingService.SettingExists(googleShoppingSettings, x => x.CurrencyId, storeScope);
                model.DefaultGoogleCategory_OverrideForStore      = _settingService.SettingExists(googleShoppingSettings, x => x.DefaultGoogleCategory, storeScope);
                model.PassShippingInfoDimensions_OverrideForStore = _settingService.SettingExists(googleShoppingSettings, x => x.PassShippingInfoDimensions, storeScope);
                model.PassShippingInfoWeight_OverrideForStore     = _settingService.SettingExists(googleShoppingSettings, x => x.PassShippingInfoWeight, storeScope);
                model.PricesConsiderPromotions_OverrideForStore   = _settingService.SettingExists(googleShoppingSettings, x => x.PricesConsiderPromotions, storeScope);
                model.ProductPictureSize_OverrideForStore         = _settingService.SettingExists(googleShoppingSettings, x => x.ProductPictureSize, storeScope);
            }

            return(View("~/Plugins/Feed.GoogleShopping/Views/Configure.cshtml", model));
        }
コード例 #11
0
        /// <summary>
        /// Prepare FeedGoogleShoppingModel
        /// </summary>
        /// <param name="model">Model</param>
        private void PrepareModel(FeedGoogleShoppingModel model)
        {
            if (!_permissionService.Authorize(StandardPermissionProvider.ManagePlugins))
            {
                return;
            }

            //load settings for a chosen store scope
            var storeScope             = _storeContext.ActiveStoreScopeConfiguration;
            var googleShoppingSettings = _settingService.LoadSetting <GoogleShoppingSettings>(storeScope);

            model.ProductPictureSize         = googleShoppingSettings.ProductPictureSize;
            model.PassShippingInfoWeight     = googleShoppingSettings.PassShippingInfoWeight;
            model.PassShippingInfoDimensions = googleShoppingSettings.PassShippingInfoDimensions;
            model.PricesConsiderPromotions   = googleShoppingSettings.PricesConsiderPromotions;

            //currencies
            model.CurrencyId = googleShoppingSettings.CurrencyId;
            foreach (var c in _currencyService.GetAllCurrencies())
            {
                model.AvailableCurrencies.Add(new SelectListItem {
                    Text = c.Name, Value = c.Id.ToString()
                });
            }
            //Google categories
            model.DefaultGoogleCategory = googleShoppingSettings.DefaultGoogleCategory;
            model.AvailableGoogleCategories.Add(new SelectListItem {
                Text = "Select a category", Value = ""
            });
            foreach (var gc in _googleService.GetTaxonomyList())
            {
                model.AvailableGoogleCategories.Add(new SelectListItem {
                    Text = gc, Value = gc
                });
            }

            model.HideGeneralBlock         = _genericAttributeService.GetAttribute <bool>(_workContext.CurrentCustomer, GoogleShoppingDefaults.HideGeneralBlock);
            model.HideProductSettingsBlock = _genericAttributeService.GetAttribute <bool>(_workContext.CurrentCustomer, GoogleShoppingDefaults.HideProductSettingsBlock);

            //prepare nested search models
            model.GoogleProductSearchModel.SetGridPageSize();

            //file paths
            foreach (var store in _storeService.GetAllStores())
            {
                var localFilePath = System.IO.Path.Combine(_hostingEnvironment.WebRootPath, "files\\exportimport", store.Id + "-" + googleShoppingSettings.StaticFileName);
                if (System.IO.File.Exists(localFilePath))
                {
                    model.GeneratedFiles.Add(new GeneratedFileModel
                    {
                        StoreName = store.Name,
                        FileUrl   = $"{_webHelper.GetStoreLocation(false)}files/exportimport/{store.Id}-{googleShoppingSettings.StaticFileName}"
                    });
                }
            }

            model.ActiveStoreScopeConfiguration = storeScope;
            if (storeScope > 0)
            {
                model.CurrencyId_OverrideForStore                 = _settingService.SettingExists(googleShoppingSettings, x => x.CurrencyId, storeScope);
                model.DefaultGoogleCategory_OverrideForStore      = _settingService.SettingExists(googleShoppingSettings, x => x.DefaultGoogleCategory, storeScope);
                model.PassShippingInfoDimensions_OverrideForStore = _settingService.SettingExists(googleShoppingSettings, x => x.PassShippingInfoDimensions, storeScope);
                model.PassShippingInfoWeight_OverrideForStore     = _settingService.SettingExists(googleShoppingSettings, x => x.PassShippingInfoWeight, storeScope);
                model.PricesConsiderPromotions_OverrideForStore   = _settingService.SettingExists(googleShoppingSettings, x => x.PricesConsiderPromotions, storeScope);
                model.ProductPictureSize_OverrideForStore         = _settingService.SettingExists(googleShoppingSettings, x => x.ProductPictureSize, storeScope);
            }
        }