I have the following code snippet in my _prepareCollection function. In this collection, I am missing an attribute that I need to have in order to display to a grid(style number). I am able to access the attribute using the entity_id from the collection, but I have no idea how to go about joining this attribute to my collection.
protected function _prepareCollection() {
$collection = $this->getOrder()->getProducts();
foreach ($collection as $item){
$styleNumber = Mage::getModel('Catalog/Product')->load($item->entity_id)->manufacturersstylenumber;
//Join this style number to $collection
}
$this->setCollection($collection);
return parent::_prepareCollection();
}
Edit: Output of $collection->getSelect()->toString();
SELECT `main_table`.*, `catalog/product`.*, `Purchase/CatalogProductDecimal`.`value` AS `sale_price`, `catalog_product_entity_varchar`.`value` AS `small_image` FROM `purchase_order_product` AS `main_table`
INNER JOIN `catalog_product_entity` AS `catalog/product` ON entity_id=pop_product_id
INNER JOIN `catalog_product_entity_decimal` AS `Purchase/CatalogProductDecimal` ON `catalog/product`.entity_id=`Purchase/CatalogProductDecimal`.entity_id and `Purchase/CatalogProductDecimal`.store_id = 0 and `Purchase/CatalogProductDecimal`.attribute_id = 64
LEFT JOIN `catalog_product_entity_varchar` ON `catalog/product`.entity_id=`catalog_product_entity_varchar`.entity_id and `catalog_product_entity_varchar`.store_id = 0 and `catalog_product_entity_varchar`.attribute_id = 75 WHERE (pop_order_num = '3')
Edit: I suppose my question is how would I create a join using entity_id to my catalog/product and adding the styleNumber attribute for my addColumn later.
$this->getOrder()->getProducts()
do? – Marius♦ Sep 2 '15 at 18:26$this->getOrder()->getProducts()
return an instance ofMage_Catalog_Model_Resource_Product_Collection
? – Marius♦ Sep 2 '15 at 18:31$this -> order = mage::getModel('Ppurchase/Order')->load($value); return $this
– nguyminh Sep 2 '15 at 18:35getProducts
looks like. Add the code to the question. – Marius♦ Sep 2 '15 at 18:39