Closed benmccormick closed 5 years ago
@sperand-io any time to review this?
thanks @benmccormick! i'll need to pull this down and poke around with a local magento install, and pending no issues, will get this merged and released ASAP. really sorry for the slow feedback loop here
Hi, we recently had a client install this extension who encountered an error that crashed their site. Fortunately they were able to debug and fix the error. Their description of the problem and solution is below, and this pull request makes the update that ultimately solved the problem for them.
Note that they're currently using version 1.1 of the plugin, so some of the line numbers may not match up exactly.
Issue description
Module Segment_Analytics has observer:
In Segment_Analytics_Model_Observer::Segment_Analytics_Model_Observer on line 32 we have
One of blocks is block for viewed products(segment_analytics/viewedproduct.phtml). It calls Segment_Analytics_Model_Controller_Viewedproduct::getBlock($block)
On line 9 it calls
In Segment_Analytics_Helper_Data::getNormalizedProductInformation($product) we load product using API model(line 90):
At this point we do not have store set. When store is not set, then Magento tries to get if from session or if value not set - it will set admin store ID:
So, here product loaded with store ID=0. Which is admin store. Also there is core observer Mage_CatalogInventory_Model_Observer::addInventoryData($observer) that adds this product with store ID=0 to inventory model.
Later when page rendered, Magento displays block "product_type_data_extra"(in template catalog/product/view/type/grouped.phtml):
One of child blocks is a block with type Mage_CatalogInventory_Block_Stockqty_Default
Later this block calls Mage_Catalog_Model_Product_Type_Grouped::getProductsToPurchaseByReqGroups($product = null)
In this function Magento tries to take all associated products for our Grouped products. Also it tries to load attributes. When attributes loaded, there is check if enabled flat catalog for products. Since the product has store ID = 0, this check returns wrong result and we receive following error:
Proposed Fix
issue can be solved if we add param store in method that loads product by API model in the helper:
Change line 90 in app/code/community/Segment/Analytics/Helper/Data.php:
FROM:
$product = Mage::getModel('catalog/product_api')->info($product);
TO:
$product = Mage::getModel('catalog/product_api')->info($product, Mage::app()->getStore());