Developer forum

Forum » Ecommerce - Standard features » Query products based on matrix price and products

Query products based on matrix price and products

Ivan Marijanović
Ivan Marijanović
Reply

Hi guys!

I am having following issue and would appricate any help.

We have multiple shops and multiple stock locations so we do not enter price of product or stock level on product page but we create matrix of prices and stock levels.

On products page we would like to show only products that have price defined and that ar in stock but it has to be calculated based on different stock locations and price matrix. If I set Price greater then 0 in query I allways get no products found since there is no price on product itself. 

Also I would like to prevent the products without image to be displayed but we do not enter image in product card but use product id as name of images and use file name pattern to display image of product. Can we filter products lusing this way of displaying images of products?

Ivan

 

 


Replies

 
Nicolai Pedersen
Reply
This post has been marked as an answer

Hi Ivan

Depending on where you have setup the image pattern, images are detected and index with the rest of the product information. You have to setup the image pattern on the shop in order for that to work - not on the paragraph settings.

Price and stock from the matrixes are another problem though and is currently not possible. The index is not in anyways "context" aware as it is a snapshot at a given time with no user.
The only option i see, is that you create an extender and add a bit of logic and a couple of fields to the index that can give you what you want.

What you can do is to create 2 new fields, i.e:  "ProductHasPricesInShops" and "ProductHasStockInShops" both as string arrays.

For each shop in your solution, find the price, if any, for a given product, and add it to the ProductHasPricesInShops field on the document, i.e. "shop1, shop2".

Do the same for stock locations.

Then on the search, you can create 2 expressions that look into these fields - ProductHasPricesInShops IN Context.Shop.

I hope this makes sense!

Here is an example of creating a IndexBuilderExtender.

class IndexBuilderExtenderExample : IndexBuilderExtenderBase<ProductIndexBuilder>
    {
        public override void ExtendDocument(IndexDocument document)
        {
            if (document.ContainsKey("ID"))
            {
                string productid = (string)document["ID"];
            }

            if (document.ContainsKey("ProductNumber"))
            {
                string productNumber = (string)document["ProductNumber"];
                document.Add("ProductNumberCleaned", productNumber.Replace(".", string.Empty));
            }

            document.Add("CustomField", DateTime.Now);
        }
    }

Votes for this answer: 1
 
Ivan Marijanović
Ivan Marijanović
Reply

Hi Nicolai,

Thank your for your answer.

Do you think, as workaround, it is possible to introduce a bit of logic in template during the rendering proccess that it do not render product if the price and/or stock level is 0?

Ivan

 
Nicolai Pedersen
Reply

It could be possible, but would make your page counts, result counts and facet counts be wrong...

 

You must be logged in to post in the forum