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

Bug report (couldn’t post into normal bug report)
 
Bornemix
Jr. Member
 
Total Posts:  8
Joined:  2007-11-13
 

Hi,

We found a warning upon creating a product with our own attribute set. We are not sure EXACTLY why this happened to us, but I’ve managed to make a fix for it.

The stacktrace is following:

NoticeUndefined variableconditionSql in /www/www.lensesonly.com/magento/app/code/core/Mage/Eav/Model/Entity/Collection/Abstract.php on line 339
[0] in Mage_Eav_Model_Entity_Collection_Abstract
->addAttributeToFilter(534Array[1]in /www/www.lensesonly.com/magento/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tab/Super/Config/Grid.php on line 78
[1] in Mage_Adminhtml_Block_Catalog_Product_Edit_Tab_Super_Config_Grid
->_prepareCollection() in /www/www.lensesonly.com/magento/app/code/core/Mage/Adminhtml/Block/Widget/Grid.php on line 358
[2] in Mage_Adminhtml_Block_Widget_Grid
->_prepareGrid() in /www/www.lensesonly.com/magento/app/code/core/Mage/Adminhtml/Block/Widget/Grid.php on line 364
[3] in Mage_Adminhtml_Block_Widget_Grid
->_beforeToHtml() in /www/www.lensesonly.com/magento/app/code/core/Mage/Core/Block/Template.php on line 180
[4] in Mage_Core_Block_Template
->toHtml() in /www/www.lensesonly.com/magento/app/code/core/Mage/Core/Block/Abstract.php on line 439
[5] in Mage_Core_Block_Abstract
->_getChildHtml("grid"1in /www/www.lensesonly.com/magento/app/code/core/Mage/Core/Block/Abstract.php on line 417
[6] in Mage_Core_Block_Abstract
->getChildHtml("grid"in /www/www.lensesonly.com/magento/app/code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tab/Super/Config.php on line 65
[7] in Mage_Adminhtml_Block_Catalog_Product_Edit_Tab_Super_Config
->getGridHtml() in /www/www.lensesonly.com/magento/app/design/adminhtml/default/default/template/catalog/product/edit/super/config.phtml on line 59
[8] in 
include("/www/www.lensesonly.com/magento/app/design/adminhtml/default/default/template/catalog/product/edit/s"in /www/www.lensesonly.com/magento/app/code/core/Mage/Core/Block/Template.php on line 116
[9] in Mage_Core_Block_Template
->fetchView("adminhtml/default/default/template/catalog/product/edit/super/config.phtml"in /www/www.lensesonly.com/magento/app/code/core/Mage/Core/Block/Template.php on line 143
[10] in Mage_Core_Block_Template
->renderView() in /www/www.lensesonly.com/magento/app/code/core/Mage/Core/Block/Template.php on line 188

...etc.

I think it has to do with our configuration in some sort, because it only appears on our production machine. Nevertheless, the warning suggests that the variable conditionSql is nonexistent, which in turn has a MYSQL syntax error (some empty AND () is generated). Anyhow, the code who needed the fix is the following:

Around line 308 in app/code/core/Mage/Eav/Model/Entity/Collection/Abstract.php:

/**
     * Add attribute filter to collection
     *
     * If $attribute is an array will add OR condition with following format:
     * array(
     *     array('attribute'=>'firstname', 'like'=>'test%'),
     *     array('attribute'=>'lastname', 'like'=>'test%'),
     * )
     *
     * @see self::_getConditionSql for $condition
     * @param string|array $attribute
     * @param null|string|array $condition
     * @param string $operator
     * @return Mage_Eav_Model_Entity_Collection_Abstract
     */
    public function addAttributeToFilter($attribute$condition=null)
    
{
        
if($attribute===null{
            $this
->getSelect();
            return 
$this;
        
}
        
if (is_array($attribute)) {
            $sqlArr 
= array();
            foreach (
$attribute as $condition{
                $sqlArr[] 
$this->_getAttributeConditionSql($condition['attribute']$condition);
            
}
            $conditionSql 
'('.join(') OR ('$sqlArr).')';
        
}
        
elseif (is_string($attribute)) {
            
if (is_null($condition)) {
                
throw Mage::exception('Mage_Eav'__('Invalid condition'));
            
}
            $conditionSql 
$this->_getAttributeConditionSql($attribute$condition);
        
}
        $this
->getSelect()->where($conditionSql);
        return 
$this;
    
}

I don’t know why, but on our production machine an int, namely 552, is injected as $attribute. And since it is not NULL, an array nor is it a string, the conditionSql is never set.

Thus the line “$this->getSelect()->where($conditionSql)” generates that warning.

I inserted the following lines of code and viola it did help:

if($attribute===null
                $this
->getSelect(); 
                return 
$this
        

// Fix by W.G.P. 
elseif(!is_array($attribute) && !is_string($attribute) && is_numeric($attribute) && is_int($attribute))
$attribute 
"$attribute"

        
if (is_array($attribute)) 

...etc.

Just a simple cast which is not needed on any of our other machines ??? confused

I have not made any deeper research and since it seems to fix our error I thought I would share it. Any feedback is appreciated

 
Magento Community Magento Community
Magento Community
Magento Community
 
Moshe
Magento Team
 
Avatar
Total Posts:  1770
Joined:  2007-08-07
Los Angeles
 

Thanks for the report smile

There’s another solution posted in this thread: http://www.magentocommerce.com/boards/viewthread/1566/

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