public IActionResult GoogleProductList(GoogleProductSearchModel searchModel) { var storeId = _storeContext.ActiveStoreScopeConfiguration; var products = _productService.SearchProducts( storeId: storeId, pageIndex: searchModel.Page - 1, pageSize: searchModel.PageSize, showHidden: true); //prepare list model var model = new GoogleProductListModel().PrepareToGrid(searchModel, products, () => { return(products.Select(product => { var gModel = new GoogleProductModel { ProductId = product.Id, ProductName = product.Name }; var googleProduct = _googleService.GetByProductId(product.Id); if (googleProduct != null) { gModel.GoogleCategory = googleProduct.Taxonomy; gModel.Gender = googleProduct.Gender; gModel.AgeGroup = googleProduct.AgeGroup; gModel.Color = googleProduct.Color; gModel.GoogleSize = googleProduct.Size; gModel.CustomGoods = googleProduct.CustomGoods; } return gModel; })); }); return(Json(model)); }
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)); }
public ActionResult GoogleProductList(GridCommand command) { if (!_permissionService.Authorize(StandardPermissionProvider.ManagePlugins)) { return(Content("Access denied")); } var products = _productService.SearchProducts(pageIndex: command.Page - 1, pageSize: command.PageSize, showHidden: true); var productsModel = products .Select(x => { var gModel = new FeedFroogleModel.GoogleProductModel() { ProductId = x.Id, ProductName = x.Name }; var googleProduct = _googleService.GetByProductId(x.Id); if (googleProduct != null) { gModel.GoogleCategory = googleProduct.Taxonomy; gModel.Gender = googleProduct.Gender; gModel.AgeGroup = googleProduct.AgeGroup; gModel.Color = googleProduct.Color; gModel.GoogleSize = googleProduct.Size; } return(gModel); }) .ToList(); var model = new GridModel <FeedFroogleModel.GoogleProductModel> { Data = productsModel, Total = products.TotalCount }; return(new JsonResult { Data = model }); }
public ActionResult GoogleProductList(DataSourceRequest command) { if (!_permissionService.Authorize(StandardPermissionProvider.ManagePlugins)) { return(ErrorForKendoGridJson("Access denied")); } var products = _productService.SearchProducts(pageIndex: command.Page - 1, pageSize: command.PageSize, showHidden: true); var productsModel = products .Select(x => { var gModel = new FeedGoogleShoppingModel.GoogleProductModel { ProductId = x.Id, ProductName = x.Name }; var googleProduct = _googleService.GetByProductId(x.Id); if (googleProduct != null) { gModel.GoogleCategory = googleProduct.Taxonomy; gModel.Gender = googleProduct.Gender; gModel.AgeGroup = googleProduct.AgeGroup; gModel.Color = googleProduct.Color; gModel.GoogleSize = googleProduct.Size; gModel.CustomGoods = googleProduct.CustomGoods; } return(gModel); }) .ToList(); var gridModel = new DataSourceResult { Data = productsModel, Total = products.TotalCount }; return(Json(gridModel)); }
public async Task <IActionResult> GoogleProductList(DataSourceRequest command) { if (!await _permissionService.Authorize(StandardPermissionProvider.ManagePlugins)) { return(Content("Access denied")); } var products = (await _productService.SearchProducts(pageIndex: command.Page - 1, pageSize: command.PageSize, showHidden: true)).products; var productsModel = new List <FeedGoogleShoppingModel.GoogleProductModel>(); foreach (var x in products) { var gModel = new FeedGoogleShoppingModel.GoogleProductModel { ProductId = x.Id, ProductName = x.Name }; var googleProduct = await _googleService.GetByProductId(x.Id); if (googleProduct != null) { gModel.GoogleCategory = googleProduct.Taxonomy; gModel.Gender = googleProduct.Gender; gModel.AgeGroup = googleProduct.AgeGroup; gModel.Color = googleProduct.Color; gModel.GoogleSize = googleProduct.Size; gModel.CustomGoods = googleProduct.CustomGoods; } productsModel.Add(gModel); } var gridModel = new DataSourceResult { Data = productsModel, Total = products.TotalCount }; return(new JsonResult(gridModel)); }
/// <summary> /// Generate a feed /// </summary> /// <param name="stream">Stream</param> /// <param name="store">Store</param> /// <returns>Generated feed</returns> public void GenerateFeed(Stream stream, Store store) { if (stream == null) { throw new ArgumentNullException("stream"); } if (store == null) { throw new ArgumentNullException("store"); } const string googleBaseNamespace = "http://base.google.com/ns/1.0"; var settings = new XmlWriterSettings { Encoding = Encoding.UTF8 }; using (var writer = XmlWriter.Create(stream, settings)) { //Generate feed according to the following specs: http://www.google.com/support/merchants/bin/answer.py?answer=188494&expand=GB writer.WriteStartDocument(); writer.WriteStartElement("rss"); writer.WriteAttributeString("version", "2.0"); writer.WriteAttributeString("xmlns", "g", null, googleBaseNamespace); writer.WriteStartElement("channel"); writer.WriteElementString("title", "Google Base feed"); writer.WriteElementString("link", "http://base.google.com/base/"); writer.WriteElementString("description", "Information about products"); var products1 = _productService.SearchProducts(storeId: store.Id, visibleIndividuallyOnly: true); foreach (var product1 in products1) { var productsToProcess = new List <Product>(); switch (product1.ProductType) { case ProductType.SimpleProduct: { //simple product doesn't have child products productsToProcess.Add(product1); } break; case ProductType.GroupedProduct: { //grouped products could have several child products var associatedProducts = _productService.SearchProducts( storeId: store.Id, visibleIndividuallyOnly: false, parentGroupedProductId: product1.Id ); productsToProcess.AddRange(associatedProducts); } break; default: continue; } foreach (var product in productsToProcess) { writer.WriteStartElement("item"); #region Basic Product Information //id [id]- An identifier of the item writer.WriteElementString("g", "id", googleBaseNamespace, product.Id.ToString()); //title [title] - Title of the item writer.WriteStartElement("title"); var title = product.Name; //title should be not longer than 70 characters if (title.Length > 70) { title = title.Substring(0, 70); } writer.WriteCData(title); writer.WriteEndElement(); // title //description [description] - Description of the item writer.WriteStartElement("description"); string description = product.FullDescription; if (String.IsNullOrEmpty(description)) { description = product.ShortDescription; } if (String.IsNullOrEmpty(description)) { description = product.Name; } if (String.IsNullOrEmpty(description)) { description = product.Name; //description is required } //resolving character encoding issues in your data feed description = StripInvalidChars(description, true); writer.WriteCData(description); writer.WriteEndElement(); // description //google product category [google_product_category] - Google's category of the item //the category of the product according to Google’s product taxonomy. http://www.google.com/support/merchants/bin/answer.py?answer=160081 string googleProductCategory = ""; var googleProduct = _googleService.GetByProductId(product.Id); if (googleProduct != null) { googleProductCategory = googleProduct.Taxonomy; } if (String.IsNullOrEmpty(googleProductCategory)) { googleProductCategory = _froogleSettings.DefaultGoogleCategory; } if (String.IsNullOrEmpty(googleProductCategory)) { throw new NopException("Default Google category is not set"); } writer.WriteStartElement("g", "google_product_category", googleBaseNamespace); writer.WriteCData(googleProductCategory); writer.WriteFullEndElement(); // g:google_product_category //product type [product_type] - Your category of the item var defaultProductCategory = _categoryService.GetProductCategoriesByProductId(product.Id).FirstOrDefault(); if (defaultProductCategory != null) { var category = defaultProductCategory.Category.GetFormattedBreadCrumb(_categoryService, separator: ">"); if (!String.IsNullOrEmpty((category))) { writer.WriteStartElement("g", "product_type", googleBaseNamespace); writer.WriteCData(category); writer.WriteFullEndElement(); // g:product_type } } //link [link] - URL directly linking to your item's page on your website var productUrl = string.Format("{0}{1}", store.Url, product.GetSeName(_workContext.WorkingLanguage.Id)); writer.WriteElementString("link", productUrl); //image link [image_link] - URL of an image of the item string imageUrl; var picture = _pictureService.GetPicturesByProductId(product.Id, 1).FirstOrDefault(); if (picture != null) { imageUrl = _pictureService.GetPictureUrl(picture, _froogleSettings.ProductPictureSize, storeLocation: store.Url); } else { imageUrl = _pictureService.GetDefaultPictureUrl(_froogleSettings.ProductPictureSize, storeLocation: store.Url); } writer.WriteElementString("g", "image_link", googleBaseNamespace, imageUrl); //condition [condition] - Condition or state of the item writer.WriteElementString("g", "condition", googleBaseNamespace, "new"); writer.WriteElementString("g", "expiration_date", googleBaseNamespace, DateTime.Now.AddDays(28).ToString("yyyy-MM-dd")); #endregion #region Availability & Price //availability [availability] - Availability status of the item string availability = "in stock"; //in stock by default if (product.ManageInventoryMethod == ManageInventoryMethod.ManageStock && product.StockQuantity <= 0) { switch (product.BackorderMode) { case BackorderMode.NoBackorders: { availability = "out of stock"; } break; case BackorderMode.AllowQtyBelow0: case BackorderMode.AllowQtyBelow0AndNotifyCustomer: { availability = "available for order"; //availability = "preorder"; } break; default: break; } } writer.WriteElementString("g", "availability", googleBaseNamespace, availability); //price [price] - Price of the item var currency = GetUsedCurrency(); decimal price = _currencyService.ConvertFromPrimaryStoreCurrency(product.Price, currency); writer.WriteElementString("g", "price", googleBaseNamespace, price.ToString(new CultureInfo("en-US", false).NumberFormat) + " " + currency.CurrencyCode); #endregion #region Unique Product Identifiers /* Unique product identifiers such as UPC, EAN, JAN or ISBN allow us to show your listing on the appropriate product page. If you don't provide the required unique product identifiers, your store may not appear on product pages, and all your items may be removed from Product Search. * We require unique product identifiers for all products - except for custom made goods. For apparel, you must submit the 'brand' attribute. For media (such as books, movies, music and video games), you must submit the 'gtin' attribute. In all cases, we recommend you submit all three attributes. * You need to submit at least two attributes of 'brand', 'gtin' and 'mpn', but we recommend that you submit all three if available. For media (such as books, movies, music and video games), you must submit the 'gtin' attribute, but we recommend that you include 'brand' and 'mpn' if available. */ //GTIN [gtin] - GTIN var gtin = product.Gtin; if (!String.IsNullOrEmpty(gtin)) { writer.WriteStartElement("g", "gtin", googleBaseNamespace); writer.WriteCData(gtin); writer.WriteFullEndElement(); // g:gtin } //brand [brand] - Brand of the item var defaultManufacturer = _manufacturerService.GetProductManufacturersByProductId((product.Id)).FirstOrDefault(); if (defaultManufacturer != null) { writer.WriteStartElement("g", "brand", googleBaseNamespace); writer.WriteCData(defaultManufacturer.Manufacturer.Name); writer.WriteFullEndElement(); // g:brand } //mpn [mpn] - Manufacturer Part Number (MPN) of the item var mpn = product.ManufacturerPartNumber; if (!String.IsNullOrEmpty(mpn)) { writer.WriteStartElement("g", "mpn", googleBaseNamespace); writer.WriteCData(mpn); writer.WriteFullEndElement(); // g:mpn } #endregion #region Apparel Products /* Apparel includes all products that fall under 'Apparel & Accessories' (including all sub-categories) * in Google’s product taxonomy. */ //gender [gender] - Gender of the item if (googleProduct != null && !String.IsNullOrEmpty(googleProduct.Gender)) { writer.WriteStartElement("g", "gender", googleBaseNamespace); writer.WriteCData(googleProduct.Gender); writer.WriteFullEndElement(); // g:gender } //age group [age_group] - Target age group of the item if (googleProduct != null && !String.IsNullOrEmpty(googleProduct.AgeGroup)) { writer.WriteStartElement("g", "age_group", googleBaseNamespace); writer.WriteCData(googleProduct.AgeGroup); writer.WriteFullEndElement(); // g:age_group } //color [color] - Color of the item if (googleProduct != null && !String.IsNullOrEmpty(googleProduct.Color)) { writer.WriteStartElement("g", "color", googleBaseNamespace); writer.WriteCData(googleProduct.Color); writer.WriteFullEndElement(); // g:color } //size [size] - Size of the item if (googleProduct != null && !String.IsNullOrEmpty(googleProduct.Size)) { writer.WriteStartElement("g", "size", googleBaseNamespace); writer.WriteCData(googleProduct.Size); writer.WriteFullEndElement(); // g:size } #endregion #region Tax & Shipping //tax [tax] //The tax attribute is an item-level override for merchant-level tax settings as defined in your Google Merchant Center account. This attribute is only accepted in the US, if your feed targets a country outside of the US, please do not use this attribute. //IMPORTANT NOTE: Set tax in your Google Merchant Center account settings //IMPORTANT NOTE: Set shipping in your Google Merchant Center account settings //shipping weight [shipping_weight] - Weight of the item for shipping //We accept only the following units of weight: lb, oz, g, kg. if (_froogleSettings.PassShippingInfo) { var weightName = "kg"; var shippingWeight = product.Weight; switch (_measureService.GetMeasureWeightById(_measureSettings.BaseWeightId).SystemKeyword) { case "ounce": weightName = "oz"; break; case "lb": weightName = "lb"; break; case "grams": weightName = "g"; break; case "kg": weightName = "kg"; break; default: //unknown weight weightName = "kg"; break; } writer.WriteElementString("g", "shipping_weight", googleBaseNamespace, string.Format(CultureInfo.InvariantCulture, "{0} {1}", shippingWeight.ToString(new CultureInfo("en-US", false).NumberFormat), weightName)); } #endregion writer.WriteEndElement(); // item } } writer.WriteEndElement(); // channel writer.WriteEndElement(); // rss writer.WriteEndDocument(); } }