Developer forum

Forum » Ecommerce - Standard features » What about these products loop

What about these products loop

Søren Mastrup
Reply

I have a customer who wants a "Other customers also got a quote on"-area.
I know that I can use the eCom:Related.WhatAboutTheseProducts loop for regular orders, but what about quotes?

Is this possible in DW?

 


Replies

 
Nicolai Høeg Pedersen
Reply
This post has been marked as an answer

Hi Søren

That does not exist. But it is easy to add one of these loops your self.

This is the code for the "CustomersWhoBoughtThisItemAlsoBought" loop on products - create your own extender with code that looks at quotes instead.

using Dynamicweb.eCommerce.Products;
using Dynamicweb.Extensibility.Provider;

namespace Dynamicweb.eCommerce.Specialized.RelatedProductListProviders
{
    [RelatedProductList("eCom:Related.CustomersWhoBoughtThisItemAlsoBought")]
    public class CustomersWhoBoughtThisAlsoBought : RelatedProductListProvider
    {
        public override ProductCollection GetCollection(RelatedProductListProviderEventArgs eventArgs)
        {
            System.Text.StringBuilder sql = new System.Text.StringBuilder();

            if (eventArgs.Product == null) return null;

            sql.Append("SELECT DISTINCT TOP 10 * ");
            sql.Append("FROM EcomProducts ");
            sql.Append("INNER JOIN ");
            sql.Append("(");
            sql.Append("    SELECT DISTINCT(E2.OrderLineProductID), ");
            sql.Append("    (");
            sql.Append("        SELECT COUNT(*) ");
            sql.Append("        FROM EcomOrderLines E3 ");
            sql.Append("        WHERE E3.OrderLineProductID = E2.OrderLineProductID ");
            sql.Append("        AND E3.OrderLineOrderID IN ");
            sql.Append("        (");
            sql.Append("            SELECT DISTINCT(OrderLineOrderID) ");
            sql.Append("            FROM EcomOrderLines E4 ");
            sql.Append("            WHERE E4.OrderLineProductID = '{0}'");
            sql.Append("        )");
            sql.Append("    ) AS Frequency ");
            sql.Append("    FROM EcomOrderLines AS E1 ");
            sql.Append("    INNER JOIN EcomOrderLines AS E2 ");
            sql.Append("    ON E1.OrderLineOrderID = E2.OrderLineOrderID ");
            sql.Append("    INNER JOIN EcomOrders AS O ");
            sql.Append("    ON E1.OrderLineOrderID = O.OrderID ");
            sql.Append("    WHERE E1.OrderLineProductID = '{0}' ");
            sql.Append("    AND E2.OrderLineProductID <> '{0}' ");
            sql.Append("    AND O.OrderComplete = {1} ");
            sql.Append(") AS SelectorTable ");
            sql.Append("ON EcomProducts.ProductID = SelectorTable.OrderLineProductID ");
            sql.Append("WHERE EcomProducts.ProductVariantID IS NULL OR EcomProducts.ProductVariantID = '' ");

            if (!string.IsNullOrEmpty(eCommerce.Common.Context.LanguageID))
                sql.AppendFormat("AND EcomProducts.ProductLanguageID = '{0}' ", Database.SqlEscapeInjection(eCommerce.Common.Context.LanguageID));

            sql.Append("ORDER BY Frequency DESC");

            return Product.GetProductBySql(string.Format(sql.ToString(), eventArgs.Product.ID, Database.SqlBool(true)));
        }
    }
}

 

Votes for this answer: 1
 
Søren Mastrup
Reply

Thanks!

 
Mikkel Toustrup Olsen
Reply

Hi Nicolai,

As an additional question regardin the related product list provider.

Isn't it possible to get related products to products found in the collection?.

I have a provider which returns a colleciton of products based on specific parameters. This works nicely. However, I would like to show the related products for the products found in this collection as well.

On my template I can actually see     if(i.GetString("Ecom:Product.RelatedCount") != "0") gives me a count of 3 on my test product, which is correct. Though, I am not able to traverse the GetLoop("ProductRelatedGroups") and GetLoop("ProductRelatedProducts") afterwards - which I'm doing on my other productlists :-)

BR

Mikkel

 
Nicolai Høeg Pedersen
Reply

Hi Mikkel

No, that is not possible - because that would possibly give you all the products in the product catalog in one products page (going recursive). And that would perform really bad :-).

Nicolai

 
Mikkel Toustrup Olsen
Reply

Hi Nicolai,

That makes good sense actually. However, do I need to make a new custom product list provider for that specific case then? :-)

BR

Mikkel

 
Nicolai Høeg Pedersen
Reply
This post has been marked as an answer

Yes, that would be the only way. Or a product template extender.

Be aware of performance when you do this.

BR Nicolai

Votes for this answer: 1
 
Mikkel Toustrup Olsen
Reply

Thanks!

BR

Mikkel

 

You must be logged in to post in the forum