The problem
I have joined the category product list collection (getLoadedProductCollection
from Mage_Catalog_Block_Product_List
) with a custom table. Because this collection is loaded from _beforeToHtml
we have to update it via observer event:
<frontend>
<events>
<catalog_block_product_list_collection>
<observers>
<promotion_list_collection>
<class>promotion/observer</class>
<method>catalogBlockProductListCollection</method>
</promotion_list_collection>
</observers>
</catalog_block_product_list_collection>
I am using this as my join:
public function catalogBlockProductListCollection($observer)
{
$collection = $observer->getEvent()->getCollection();
$collection->addAttributeToSelect('sku');
$collection->joinTable(
array('promotion'=>'custom_promotion'),
'sku=sku',
array('up_coupon_upc'=>'up_coupon_upc')
);
}
But it turns out that that after it is loaded the column up_coupon_upc
is not added to the collection. It is, however, available if you $collection->getData()
to dump the contents of the loaded collection.
Things I've tried
I assumed that perhaps it wasn't actually adding to the MCMP model in the collection, so I have tried adding the attribute to the select:
$collection->addAttributeToSelect('up_coupon_upc');
Doesn't work. I tried using various aliases. I tried using $collection->getSelect()->join()
instead with the same result.
I also have tried to define other columns - none of which show up either. Doing array('*')
adds all columns to my SQL query, but none of the attributes actually show up, though
the SQL output from $collection->getSelect()
outputs exactly the correct query.
Guesses
I'm guessing that the modification of the collection is actually taking place either only within the scope of the Observer, or the product collection is somehow being load
-ed prior to my observer being called.
Or, perhaps I'm just having a monumental fail and I've missed something obvious .