Im trying to join attributes in my collection on my grid view of "supply needs" from my ERP (Erp boost my shop)

The collection is loaded like this:

$collection = Mage::getModel('Purchase/SupplyNeeds')->getCollection();

And then i tried to join it with catalog/product on product_id, which works fine, but it doesnt give me the attribute "product_class" that i want, because it tries to load it from purchase/supplyneeds.

I have joined it like this:

$collection->join('catalog/product', 'product_id=entity_id');

Which gives me a collection that looks like this for each product:

[product_id] => 8728
[manufacturer_id] => 570
[sku] => 18369
[name] => NEW - Tiny Teasers Opladelig Bullet Vibrator
[waiting_for_delivery_qty] => 0
[status] => 3_prefered_stock_level
[qty_min] => 0.0000
[qty_max] => 1.0000
[entity_id] => 8728
[entity_type_id] => 4
[attribute_set_id] => 17
[type_id] => simple
[has_options] => 0
[required_options] => 0
[created_at] => 2017-08-22 14:01:37
[updated_at] => 2017-08-22 14:04:17
[exclude_from_supply_needs] => 0

But how do i get my attribute product_class in my collection? a foreach takes too much time to load for 600 products

The getSQL looks like this with join statement:

SELECT `main_table`.*, `catalog/product`.* FROM `erp_view_supplyneeds_global` AS `main_table`
 INNER JOIN `catalog_product_entity` AS `catalog/product` ON product_id=entity_id

1 Answer 1


create main collection of product and join your table with it

 $collection =  Mage::getModel('catalog/product')->getCollection();
 $collection->join('Purchase/SupplyNeeds', 'product_id=entity_id');

Or try Below code

 $connection = Mage::getSingleton('core/resource');

 $coll = Mage::getModel('catalog/product')->getCollection()
 $coll->getSelect()->join( array('supplyNeeds'=> $connection->getTableName('Purchase/SupplyNeeds')), 'supplyNeeds.product_id = e.entity_id', array('supplyNeeds.*' ) ); // here in last parameter pass all fields that you need from your table

Try above code and let me know

  • 1
    @BrittanyMoore check updated code Commented Sep 21, 2017 at 11:58
  • 1
    ahh I got it array('supplyNeeds.created_at as ocreated' ) because of this code has issue replcae with field of your table, in array put all comma separted fields that you want in select or just do array('supplyNeeds.* ') Commented Sep 21, 2017 at 12:29
  • 1
    I updated the code please check Commented Sep 21, 2017 at 12:31
  • 1
    print query and check in phpmyadmin Commented Sep 21, 2017 at 12:55
  • 1
    You can do groupby Commented Sep 22, 2017 at 9:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.