Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

Magento Forum

select product from attribute
 
Flopy69
Sr. Member
 
Avatar
Total Posts:  124
Joined:  2008-06-04
Lyon
 

Hello hello,

I wish to add a product in magento by selecting products that have a valid attribute.

So I explain myself, I would like to select products that I do on the home page, I attribute thus creates a yes / no
I added in groups attribute.

Then in my book I select yes to display on the homepage.

Then I created:
app/code/core/mage/catalog/block/product/Home.php
a copy of selected product.

Code :

$products   $product->setStoreId($storeId)->getCollection() 
            ->
addStoreFilter($storeId
            ->
addAttributeToSelect('home','true'
            ->
addAttributeToSort('news_from_date','desc'
            ->
addAttributeToSelect(array('name''price''small_image'), 'inner'
            ->
addAttributeToSelect(array('special_price''special_from_date''special_to_date'), 'left'
            ->
addAttributeToSelect('status'
        ;

I attribute identifier for a ‘home’ and I want to select those that had true. I created the corresponding view as well. But when I want my select products based on the attribute it does not work! it only displays products for which I have already completed the fields once a yes or no. It is there another method of selection addAttributeToSelect? Thank you
 
Magento Community Magento Community
Magento Community
Magento Community
 
wdchoi
Jr. Member
 
Total Posts:  20
Joined:  2008-11-17
 

Hi flopy

The addAttributeToSelect method will add the attribute to the SELECT in the generated sql query. So you have to use this method to get the attribute’s data in your returned collection, but not to test the attribute value. If you want to test the attribute value, whether it’s true or false, you have to use the method ->addAttributeToFilter(’attribute_name’, ‘attribute_value’). You have also some other ways to use this method, if you want to make more complex queries, with several conditions.

That’s it !

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
Back to top