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

Attribute filtering with “addExpressionAttributeToSelect”
 
Rool
Member
 
Total Posts:  36
Joined:  2008-09-03
 

I have added my own Attribute to the sales_order table, via the “addAttribute” method of the Mage_Sales_Model_Mysql4_Setup.
Everything works fine, I get the attribute values for each order without any trouble.

My attributes are of the type “text” and contain strings like “att1,att2,att3”

Now I want to filter my orders, and I think I have to use the “addExpressionAttributeToSelect"-method. But which sql command do i need and how to pass it into the function to get a result, whos new attribute is like “att1,att2,att3” and my filter is like “att2” ?

Sorry for the bad english, thanks for any hints!

 
Magento Community Magento Community
Magento Community
Magento Community
 
ws1984
Jr. Member
 
Total Posts:  8
Joined:  2009-03-04
 

Hi

first, sorry for my worst english wink

I think you should use same code than addCategoryFilter method (app/code/core/Mage/Core/Model/Mysql4/Store/Collection.php) :

public function addCategoryFilter($category)
    
{
        
if (is_array($category)) {
            $condition 
$this->getConnection()->quoteInto("root_category_id IN (?)"$category);
        
}
        
else {
            $condition 
$this->getConnection()->quoteInto("root_category_id=?",$category);
        
}

        $this
->addFilter('category'$condition'string');
        return 
$this;
    
}

Just split your text attribute before and pass it in quoteInto.

 
Magento Community Magento Community
Magento Community
Magento Community
 
ws1984
Jr. Member
 
Total Posts:  8
Joined:  2009-03-04
 

Something like this should be better in your case (app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql/Category/Collection.php) :

public function addIdFilter($categoryIds)
    
{
        
if (is_array($categoryIds)) {
            
if (empty($categoryIds)) {
                $condition 
'';
            
else {
                $condition 
= array('in' => $categoryIds);
            
}
        } 
elseif (is_numeric($categoryIds)) {
            $condition 
$categoryIds;
        
elseif (is_string($categoryIds)) {
            $ids 
explode(','$categoryIds);
            if (empty(
$ids)) {
                $condition 
$categoryIds;
            
else {
                $condition 
= array('in' => $ids);
            
}
        }
        $this
->addFieldToFilter('entity_id'$condition); // <= like this
        
return $this;
    
}

just make your choice :D

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