Question

I'm listening to the catalog_product_collection_load_after event to add some code when the category products grid / list is loaded, and from the observer code I want to get the following data:

  1. is it list view or grid view?
  2. if grid view, how many products per row?

looks like I need to access the products toolbar block, but I'm not sure how to do it. or maybe there's a better way?

Edit: forgot to mention, when screen is resized products per row change (for example reduced on smaller screens). can I know that ahead inside the php?

thanks!

Was it helpful?

Solution

You are correct with the assumption that you need the toolbar block to access that information. But the event you are currently listening, catalog_product_collection_load_after will only contain the information obtained regarding the product data, not it's representational logic.

An alternative approach might be to listen to the event core_block_abstract_prepare_layout_after and applying the filter for only toolbar block(make it first filter as that event is triggered on generating every single block in Magento). This way you can obtain all the information from toolbar block right after it is initialized.

Also, if you are seeing the reduced number of products per column, then it is responsive design in action and you can't know that in advance via PHP. It is very possible that on different screen sizes, your column-count remains same, it's just CSS is adjusting it to display properly.

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top