1

I'm writing an extension that dynamically change related products, eg decide which related products to show during page load.

Basically I listen to the catalog_product_collection_load_after event, temper with the collection, and let Magento cerry on. this works great for products that have related products to show and I just override them.

Unfortunately, someone at Magento though it was real smart to NOT emit the "catalog_product_collection_load_after" for whatever reason, so I can't do this with products that have no related products at all.

Also, I don't like this method because it load useless products which I override anyway.

Looking at the related products code (Mage_Catalog_Block_Product_List_Related) it will be quite challenging to edit the collection from outside. Even if I change the collection the block will just overwrite it in _prepareData. So I need to somehow catch it right after the lines:

$this->_itemCollection = $product->getRelatedProductCollection()
            ->addAttributeToSelect('required_options')
            ->setPositionOrder()
            ->addStoreFilter()
        ;

And before its actually rendered.

I also tried to listen to core_layout_block_create_after event and dynamically push a single related product just so the event will be emitted and I can override it, but it didn't work. I tried to push it like this:

$data=array("560"=>array('position'=>1));
$product->setRelatedLinkData($data);

Any tips or ideas how can I manage to push my own related products from extension even when product have no related products?

Note: I don't want to actually edit the DB. It must be pushed dynamically from some observer.

Thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.