Developer forum

Forum » CMS - Standard features » Promotion products

Promotion products

Claus Ørum-Petersen
Reply

Hey DW,

Are the promotion product paragraph able to keep the sorting as added ? I know the query can do sorting though it doesn'y seem to affect manually added products - I would expect the order it's added to be respected by the standard template :)
 

2019-05-20_1207.png 2019-05-20_1208.png

Replies

 
Morten Snedker Dynamicweb Employee
Morten Snedker
Reply
This post has been marked as an answer

Hi Claus,

If the products are retrieved from index and no sorting is applied, then you can't exepect any order you can depend on. This also means that the order of which they have been added, not necessarily will be reflected in the frontend. You need an explicit sort order either in your query, or by applying it to the URL using SortBy, ie http://mysite.dk/?sortby=ProductNumber.

Best regards
Morten Snedker

Votes for this answer: 1
 
Claus Ørum-Petersen
Reply

Hey Morten,

Thanks for the answer - Our issue is with "What you se is what you get" on the content paragraph, but I agree the sorting is handled by index and query and will try that. Would be nice with that dynamic sorting on those manually added products to the paragraph.

/Claus

 
Morten Snedker Dynamicweb Employee
Morten Snedker
Reply

Hi Claus,

That would be nice, and it has been requested more than once. However, the problem is that any product sorting on a paragraph is paragraph related rather than ecommerce related. And as such the sorting information is not a part of the index.

I will mention it for the developer team - then we'll see if they can pull any rabbits out of the hat.

BR
Morten

 
Nuno Aguiar Dynamicweb Employee
Nuno Aguiar
Reply

Hi,

 

That would be very nice to have. We also have issues with related stuff where our customers perceive that controller to have sorting, and they get dissappointed when they find out it does not. And changing it becomes intensive from the UI and template POV.

 

Nuno Aguiar

 
Vivi Hedegaard Vroue
Reply

Morten, can you at least tell what sortorder the item use as default? Where must be some kind of logic even though its not optimal?
It doesn't make sense for us to make a query or sort by in the URL. 
Our customer finds it unsatifying that they con't control the order and is starting to get creative by placing 8 x 1 bestseller items with 1 product in each item, displaying 1/4 - just in order to get in control of the order. This means 8 promotion items on one page = very bad performance.   

 
Nicolai Pedersen
Reply

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
 
Vivi Hedegaard Vroue
Reply

Thanks Nicolai! 

 

You must be logged in to post in the forum