Cert++
Close

Building and executing a ProductSearchModel query

Key Takeaway

Create a ProductSearchModel, set criteria such as setCategoryID(), call search(), and read the results with getProductSearchHits(). getProductSearchHits() is faster than the deprecated getProducts(), which loads a Product for every result.

ProductSearchModel (dw.catalog.ProductSearchModel) is the B2C Commerce script class for searching the product catalog from server-side code. You set criteria such as a search phrase, category, price range or attribute refinement, and then run the search. After that, you read back the hits, refinements and sorting. The same model also builds storefront URLs that refine, relax or re-sort the current query.

What ProductSearchModel is

ProductSearchModel is the central interface to a product search result and its refinements. It extends dw.catalog.SearchModel. ContentSearchModel extends the same base class.

Methods such as setSearchPhrase(), setRefinementValues() and getCount() are inherited from SearchModel. Product criteria such as setCategoryID() and setPriceMin() belong to ProductSearchModel itself.

B2C Commerce Developer Study Guide

Checklist progress

0/237Learned

Prepare for the Exam

Play Today's Certle

Study Community

Ask questions and get the latest info from other B2C Commerce Developer studiers. 796 members and growing.