Posted on 25/10/2019 16:29:39
Hi all
I've sent a possible solution for this issue to Morten in Support. He can try it on your solution. The code is here for reference.
Change this template:
\Templates\Designs\Rapido\Json\eCom\ProductList\AjaxProductsPromotion.cshtml
to this:
@inherits Dynamicweb.Rendering.RazorTemplateBase<Dynamicweb.Rendering.RazorTemplateModel<Dynamicweb.Rendering.Template>>
@using System.Web;
@using Dynamicweb.Configuration;
@using Dynamicweb.Core;
@using Dynamicweb.Rapido.Blocks.Components.General
@using Dynamicweb.Rapido.Services
@{
bool pointShopOnly = Pageview.AreaSettings.GetItem("Ecommerce").GetBoolean("PointShopOnly");
}
@Include("../../../eCom/Stickers.cshtml")
@Include("../../../GetProductImage.cshtml")
@functions {
public class Product
{
public string id { get; set; }
public string name { get; set; }
public string number { get; set; }
public string price { get; set; }
public string viewMoreText { get; set; }
public string stockState { get; set; }
public string stockText { get; set; }
public string deliveryText { get; set; }
public string discount { get; set; }
public string link { get; set; }
public string image { get; set; }
public string noImage { get; set; }
public string secondaryImage { get; set; }
public List<StickersCollection> StickersContainers { get; set; }
}
public static IEnumerable<TResult> SortBy<TResult, TKey>(
IEnumerable<TResult> itemsToSort,
IEnumerable<TKey> sortKeys,
Func<TResult, TKey> matchFunc)
{
return sortKeys.Join(itemsToSort,
key => key,
matchFunc,
(key, iitem) => iitem);
}
}
@{
List<Product> feedObject = new List<Product>();
var products = GetLoop("Products");
if (!String.IsNullOrEmpty(HttpContext.Current.Request.QueryString.Get("Combinations")))
{
char[] delimiterChars = { ',' };
var sortedIds = HttpContext.Current.Request.QueryString.Get("Combinations").Split(delimiterChars, StringSplitOptions.RemoveEmptyEntries);
products = SortBy(products, sortedIds, c => c.GetString("Ecom:Product.ID")).ToList();
}
foreach (LoopItem product in products)
{
Product productObject = new Product();
productObject.id = product.GetString("Ecom:Product.ID");
productObject.name = product.GetString("Ecom:Product.Name");
productObject.stockState = product.GetInteger("Ecom:Product.Stock") > 0 ? "stock-icon--in" : "stock-icon--not";
productObject.stockText = product.GetString("Ecom:Product:Stock.Text");
productObject.deliveryText = string.IsNullOrEmpty(product.GetString("Ecom:Product:Stock.DeliveryText")) ? "" : ", " + Translate("Delivery") + " " + product.GetString("Ecom:Product:Stock.DeliveryText") + " " + product.GetString("Ecom:Product:Stock.DeliveryUnit");
productObject.number = product.GetString("Ecom:Product.Number");
productObject.discount = product.GetString("Ecom:Product.Discount.Price.PriceFormatted") != product.GetString("Ecom:Product.Price.PriceFormatted") ? product.GetString("Ecom:Product.Price.PriceFormatted") : "";
productObject.price = product.GetString("Ecom:Product.Discount.Price.PriceFormatted") != product.GetString("Ecom:Product.Price.PriceFormatted") ? product.GetString("Ecom:Product.Discount.Price.PriceFormatted") : product.GetString("Ecom:Product.Price.PriceFormatted");
//productObject.onSale = product.GetString("Ecom:Product.Discount.Price.PriceFormatted") == product.GetString("Ecom:Product.Price.PriceFormatted") ? "u-hidden" : "";
productObject.link = "/" + product.GetString("Ecom:Product.LinkGroup.Clean") + (!String.IsNullOrEmpty(product.GetString("Ecom:Product.VariantID")) ? "&VariantID=" + product.GetString("Ecom:Product.VariantID") : "");
productObject.image = GetProductImage(product);
productObject.noImage = string.IsNullOrEmpty(GetProductImage(product)) ? "u-hidden" : "";
productObject.viewMoreText = Translate("View");
productObject.secondaryImage = product.GetLoop("Ecom:Product.AlternativeImages").FirstOrDefault(im => !string.IsNullOrEmpty(im.GetString("Ecom:Product.AlternativeImages.Image"))) != null ? product.GetLoop("Ecom:Product.AlternativeImages").FirstOrDefault(im => !string.IsNullOrEmpty(im.GetString("Ecom:Product.AlternativeImages.Image"))).GetString("Ecom:Product.AlternativeImages.Image") : String.Empty;
productObject.StickersContainers = GetStickersContainersList(
product.GetLoop("ProductDiscounts"),
product.GetDouble("Ecom:Product.Discount.Price.Price"),
product.GetDouble("Ecom:Product.Price.Price"),
product.GetDate("Ecom:Product.Created"),
product.GetString("Ecom:Product:Field.CustomSticker.Value")
);
feedObject.Add(productObject);
}
string jsonFeed = Newtonsoft.Json.JsonConvert.SerializeObject(feedObject);
}
@jsonFeed