Pages

Sunday, October 25, 2015

Filtering products

Filtering products Another useful way to allow customers to better find the products they are looking for is with filtering.  Customers can filter down lists of products based on attributes, such as price ranges, manufacturer, weight, brands, and so on. Price range filtering should be simple enough. However, with attributes such as manufacturer or brands, we would need to extend the database and models representation of a product to maintain this additional information, and allow  us to filter down based on these attributes. There are a few different ways in which we can store filtered results: In the user's session: This will be lost when the user closes their browser. In a cookie: This information will stay when the user closes their browser. In the URL: This would allow the customer to filter results and send the link of those results to a friend. In POST data: The information will only be stored for the one instance the filter is used. Let's try using the URL to store filter data. If we format filter data within the URL as filter/attribute-type/attribute-value-ID, then we can simply iterate through the bits of the URL, find bits containing filter, and then take the next two parts of the URL to help build the filter. This way we can filter down products based on a number of attributes, for example filter/price/5/filter/weight/6. Of course, there is a limit to this, and that is the maximum length of a URL. 

No comments:

Post a Comment