Question

If i have a product collection in a multi store environment and i wish to also retrieve a specific attributes value from another store with my collection result, how is the best way to do this?

For example, i have english, french and german store.

Each product has a custom attribute, called company_description. I want to be able to be able to get the collection from one store but also retrieve the company_description as it is set in the other 2 store views also.

It needs a join but i dont how best to do the manual eav joining.

So -

// In english store context
$productCollection = Mage::getModel('catalog/product')->getCollection()->addAttributeToSelect('company_description');

I then need to do something with a join so i can get all 3 descriptions as:

company_description
company_description_fr
company_description_de
Was it helpful?

Solution

According to Mage_Eav_Model_Entity_Collection_Abstract::joinAttribute ($alias, $attribute, $bind, $filter, $joinType, $storeId) you can specify a store. Once joined the attribute is in place and any future uses refer to that new table, useful if you want to filter it too. joinAttribute() adds to select anyway so there is no need to use addAttributeToSelect() afterwards.

$productCollection = Mage::getModel('catalog/product')->getCollection()
    ->setStoreId(0)    // To ensure all other attributes are default
    ->addAttributeToSelect('company_description')

    // French store is 3
    ->joinAttribute('company_description_fr', 'catalog_product/company_description',
                    'entity_id', null, 'inner', 3)

    // German store is 2
    ->joinAttribute('company_description_de', 'catalog_product/company_description',
                    'entity_id', null, 'inner', 2);
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top