2

i made a custom template for homepage on my magento theme (working on CE 1.8.1.0) in which i get a filtered collection of products :

$selections_products = $modelCatalogProduct->getCollection()
   ->setPageSize(32)
   ->addAttributeToSelect(array('name','selection_moment','selection_rouge','selection_blanc','selection_cdc','selection_champagne','selection_exception'))
   ->addAttributeToFilter(
        array(
          array('attribute'=>'selection_moment', array('eq' => '1')),
          array('attribute'=>'selection_rouge', array('eq' => '1')),
          array('attribute'=>'selection_blanc', array('eq' => '1')),
          array('attribute'=>'selection_cdc', array('eq' => '1')),
          array('attribute'=>'selection_champagne', array('eq' => '1')),
          array('attribute'=>'selection_exception', array('eq' => '1'))
        )
    );

these are custom attributes created in back-office. I managed to get them correctly on the same page with multiple getCollection and single filter, but i'm trying to get all product in one call, because of performance issues.

Flat catalog is enabled for products and categories, and all the custom attributes are configured with "show in product page" and "show in product list" to true

EDIT :

forgot tu put the call loop :

foreach($selections_products as $product){
    $product = mage::getModel('catalog/product')->load($product->getId());
    echo '<pre>';
    var_dump($product->getName());
    var_dump($product->getData('selection_moment'));
    var_dump($product->getData('selection_rouge'));
    var_dump($product->getData('selection_blanc'));
    var_dump($product->getData('selection_cdc'));
    var_dump($product->getData('selection_champagne'));
    echo '</pre>';
}

The followings only return 0

  • 2
    You realize that the way you are doing it you get an OR filter, right? I mean where selection_moment = 1 OR selection_rouge = 1 OR ..... Is that what you need or do you need an AND filter? – Marius Jun 18 '14 at 11:57
  • Yes, i need the 'OR' filter – SupFrig Jun 18 '14 at 12:19
5

Try like this

$selections_products = $modelCatalogProduct->getCollection()
->setPageSize(32)
->addAttributeToSelect(array('name','selection_moment','selection_rouge','selection_blanc','selection_cdc','selection_champagne','selection_exception'))
->addAttributeToFilter(
    array(
        array('attribute'=>'selection_moment', 'eq' => '1'),
        array('attribute'=>'selection_rouge', 'eq' => '1'),
        array('attribute'=>'selection_blanc', 'eq' => '1'),
        array('attribute'=>'selection_cdc', 'eq' => '1'),
        array('attribute'=>'selection_champagne', 'eq' => '1'),
        array('attribute'=>'selection_exception', 'eq' => '1')
    )
);

Refer this link

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.