NVision-Commerce-Solutions / module-customer-price

Commerce 365 for Magento - Magento 2 Extension - Customer Price Module
https://n.vision/products/commerce-365-for-magento-b2b/
2 stars 4 forks source link

Clone product collection when getting Ids for request #43

Closed gerrits-ecommerce closed 5 months ago

gerrits-ecommerce commented 6 months ago

Looping through a product collection caches the results into the collection. When other processes later change this collection without clearing it those changes can be ignored. Resulting in hard-to-debug bugs.

By cloning the collection before looping over it these bugs can be prevented with relative low overhead.

This problem doesn't generally happen on a clean install, but in combination with other code this can happen. In our case the culprit was the Anowave Google Analytic module that calls getLoadedProductCollection before pagination and sorting is applied.

It is good to mention that there is still an issue with compatibility between these two modules after this fix has been done. Because as it stands right now the Anowave module will force every product in a category to be cached instead of only the products shown on the page at that time.

There might be a possibility to fix this by re-implementing the logic Anowave uses to re-build the sorted collection after they get it. But I'm not sure you guys want to invest time into that level of compatibility.