Monday , December 11 2017
Home >> All tutorial >> Join custom table to product collection in magento

Join custom table to product collection in magento

For your custom module if you want to join your custom table data with Magento default product collection then you need to join tables with the entiry_id of the product and your product_id stored in your custom table. Here I have just used the resource model collection to join the table. I tried with getmodel feature of Magento don’t know why it doesn’t able to create the Product grid in the backend. So I used resource model and it worked. If you are only joining the table, not to generate the Product grid, then you can use getmodel instead of resource model.

  1. $collection = Mage::getResourceModel(‘catalog/product_collection’)
  2.                 ->addAttributeToSelect(‘name’)
  3.                 ->addAttributeToSelect(‘sku’)
  4.                 ->addAttributeToSelect(‘price’)
  5.                 ->addAttributeToSelect(‘status’)
  6.                 ->addAttributeToSelect(‘visibility’)
  7.                 ->addAttributeToFilter(‘type_id’, array(‘eq’ => ‘simple’))
  8.                 ->addFieldToFilter(‘status’, Mage_Catalog_Model_Product_Status::STATUS_ENABLED)
  9.                 ->addAttributeToFilter(‘visibility’, array(‘neq’ => 1));
  10.  
  11. $collection->getSelect()->join(array(‘mep’ => “mage_brand_product”), “e.entity_id = mep.product_id”, array(‘mep.*’));

We also contribute great content of Magento Download for FREE (all versions)

DON'T MISS THE CHANCE!

magento download

About Champ

Leave a Reply

Your email address will not be published. Required fields are marked *

Heap | Mobile and Web Analytics