0

I got 2 attributes which are not in the flat product table. So I am trying to join the 2 attributes into my collection. I got it working for one of the 2 attributes, like this:

$collection = Mage::getModel('catalog/product')->getCollection()
->addAttributeToSelect(Mage::getSingleton('catalog/config')->getProductAttributes());

$table = Mage::getSingleton('eav/config')->getAttribute('catalog_product', 'my_custom_attribute')->getBackend()->getTable();
$attributeId = Mage::getSingleton('eav/config')->getAttribute('catalog_product', 'my_custom_attribute')->getAttributeId();
$collection->getSelect()->join(array('attributeTable' => $table), 'e.entity_id = attributeTable.entity_id', array('order_color_code' => 'attributeTable.value'))
                        ->where("attributeTable.attribute_id = ?", $attributeId);

var_dump((string)$collection->getSelect()); // --> SQL looks ok and works

Now this works fine for my first attribute my_custom_attribute, but how would I get my other attribute my_custom_attribute2 into the collection as well?

Magento 1.7.0.2

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.