4

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
  • 1
    No these are separate - im asking here how the join should be constructed manually for an eav type join i.e. join to get the attribute id, value id etc – Marty Wallace Oct 11 '13 at 19:08
  • I would think about having three attributes. Obviously the attribute is not store view specific. Help yourself, create two more attributes and you don't have any problem. – Fabian Blechschmidt Oct 13 '13 at 20:20
2

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);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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