0

I have an custom attribute on each product called 'sidebar' which is a yes/no option. All the products that are set to 'yes' I would like to appear inside a div I have in 3columns.phtml. All I want to display is:

  • title
  • image (hyperlinked)
  • price

I tried the answer in https://stackoverflow.com/questions/1332742/magento-retrieve-products-with-a-specific-attribute-value just to get a basic idea of the query but this didn't work for me. I tried:

$collection = Mage::getModel('catalog/product')->getCollection();
$collection->addAttributeToSelect('sidebar');  
$collection->addAttributeToSelect('orig_price');    


$collection->addFieldToFilter(array(
    array('sidebar'=>'orig_price','eq'=>'yes'),  
));

foreach ($collection as $product) {
    //var_dump($product);
    var_dump($product->getData());
}

Any help is appreciated

2

Try using attribute option id rather than option label value.

Example:

$collection = Mage::getResourceModel('catalog/product_collection')
    ->addUrlRewrite()
    ->addPriceData()
    ->addAttributeToSelect('image')
    ->addAttributeToFilter('sidebar', array('eq' => 1));

foreach ($collection as $product) {
    Zend_Debug::dump($product->getData());
}

Since you mentioned that sidebar is a drop down attribute I'm assuming No => 0 and Yes => 1

0

use also this

foreach ($collection as $product) {
    Zend_Debug::dump($product->toArray())
}

exit;

now check your needed attribute//

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.