Developer forum

Forum » Ecommerce - Standard features » Implement
Imar Spaanjaars Dynamicweb Employee
Imar Spaanjaars
Reply

How do I implement a filter that only shows products that are in stock and hides the ones that aren't? With pseudo code I like to implement something like this:

(Stock >= 0 OR (Stock > 0 And Parameter[ShowOnlyInStock"] = true))

I can do the first parts, but I can't choose a parameter as the source for an expression.

Any ideas?

Thanks!


Replies

 
Nicolai Pedersen
Reply

Maybe just "stock > Parameter['ShowOnlyInStock']" and let the parameter be -1 or 0

BR Nicolai

 
Imar Spaanjaars Dynamicweb Employee
Imar Spaanjaars
Reply

Can you elaborate on that? How would I set up the parameter / filter in the UI? I can't use a facet for this, can I?

 
Nicolai Pedersen
Reply

Hm, maybe I have misunderstood the original question.

I thought you where talking about a query in the index for products. Sometimes you need the result with all products regardles if they are in stock or you only need the products that are instock.

But where does Parameter come from?

BR Nicolai

 
Imar Spaanjaars Dynamicweb Employee
Imar Spaanjaars
Reply

I would like show to all products regardless if they are in stock or not initially and then have a filter on the products page that lets a user hide products that are not in stock. Does that explain it?

 
Nicolai Pedersen
Reply

Yes, and that is where I would use the feature like this

stock > Parameter[MiniMumStocklevel]

MiniMumStocklevel is a parameter - if I do ?MiniMumStocklevel=-1000000 all products are shown. If I do ?MiniMumStocklevel=0 all products that has a stocklevel of 1 or more is shown.

Makes sense?

 
Imar Spaanjaars Dynamicweb Employee
Imar Spaanjaars
Reply

That makes sense, thanks. But how would I add that to the UI in Rapido? Is there a place to implement a filter for it using that parameter in the UI or would I code it in a template?

 
Nicolai Pedersen
Reply

You can make a list facet: https://doc.dynamicweb.com/documentation-9/platform/indexing-search/facets#4796

With a list facet you can define your own value/label sets - so create one list facet named "Stock" and use the above parameter that you specify first, and give it 2 options - "In stock" with a value of 0 and "All products" with a value of -1000000

That should work.

 
Imar Spaanjaars Dynamicweb Employee
Imar Spaanjaars
Reply

Hmmm, I still can't get it to work. I run into the following two problems:

1. Off by one. I set up the filter using Stock GreaterThan [StockParam]. When I call  it like this: MiniMumStocklevel=0 I still get items that have exactly zero stock, but not items that have negative stock (despite the GreaterThan). Could this because it's a double in DW rather than an int?

2. I set up the list facet as you described and bound it to the Stock field but it doesn't render at the frontend at all.

Any more suggestions? I could send you a link?

Thanks!

 
Nicolai Pedersen
Reply

Ah, yes - numbers and Lucene. Almost forgot! Lucene is only text when you do greater than and less than queries.

There are 2 options

  1. Left pad all numbers with leading 0 til fixed lenght, i.e. 00003 and 00521. DW does not support that out of the box
  2. Use range queries, see https://doc.dynamicweb.com/documentation-9/how-tos/general/implementing-a-pricerange-query

Using a range query, you can do less than or equal to by using * as lower bound and i.e. 0 as upper bound. I.e. ?MiniMumStocklevel=*,0 and the opposite ?MiniMumStocklevel=1,* to get all with 1 or above.

BR Nicolai

 

You must be logged in to post in the forum