I want to add default products of certain ids(example- 1,5,7,3) to be added to the list of related products always with all the products at the end for the product page and need not store in database, how to add these with related product collection in magento
Magento 1.9 – How to Add Default Products to Related Products List
magento-1.9product-collectionrelated-products
Best Answer
You can write an observer for
catalog_product_collection_load_after
, then add products to the loaded collection if the collection is the related products collection:Some parts that I'd like to highlight:
This loads the products
[1,5,7,3]
but excludes the product itself and the products that are already manually defined as related products. Otherwise we would get an error due to duplicates in the collection. You probably want to move these hard coded ids to a configuration.This prepares the product collection to load the necessary data to display prices, the product link and any attributes configured as "used in product listing", but not more.
This is a very similar solution as in my AutoUpsell module described in Get product list by category id in view.phtml, I copied most of the code from there with slight modifications.