yireo-magento1 / Yireo_GoogleTagManager

Implement Google Tag Manager in Magento 1 (deprecated)
Open Software License 3.0
56 stars 46 forks source link

Broken product sort on categories #20

Closed Selven99 closed 8 years ago

Selven99 commented 8 years ago

Hi,

In the layout, there is : <reference name="after_body_start">

So, this block will be rendered before product_list block.

My problem is : Yireo_GoogleTagManager_Block_Category::getProductCollection() $collection = $productListBlock->getLoadedProductCollection();

It will load product collection and when product_list block will be rendered, this block won't fetch product collection because it has already loaded.

Cf : Mage_Catalog_Block_Product_List::_getProductCollection()

$this->prepareSortableFieldsByCategory($layer->getCurrentCategory());

This method isn't called because collection is already loaded by Yireo_GoogleTagManager_Block_Category class.

So.... Sort & Direction are broken.

In fact, the only method to apply sort and direction is : Mage_Catalog_Block_Product_List::_beforeToHtml() And this method requires a value from a magic setter in Mage_Catalog_Block_Product_List::_getProductCollection()........


My "solution" is to replace <reference name="after_body_start"> By <reference name="before_body_end">

In this case, your Category class will get a product collection, already loaded by product_list block and all its logic ! Any problem with that ?

Thanks :) And sorry for my bad english :<

yireo commented 8 years ago

I think your solution is fine. However, we can't replicate this issue on our own. The issue could arise when you apply block caching specifically to your catalog blocks, which would reorder the loading of blocks, and which indeed would require the GTM block to be loaded after the catalog block. However, that would be part of a cache customization process anyway, so this kind of modifications would be custom as well ... Glad you found it anyway.