Magento loadByAttribute在问号上失败

Magento loadByAttribute在问号上失败,magento,pdo,Magento,Pdo,即使产品存在,尝试按其名称加载产品(“什么是测试?”)也会失败 $product = Mage::getModel('catalog/product')->loadByAttribute('name', 'What are Tests?'); 但它适用于任何其他名称 当Magento最终通过PDO时,名称中的“?”会被解释为一个参数吗?因为我没有为它传递任何值,所以结束的查询实际上会寻找“什么是测试”。。。因此没有找到产品 如果是这样的话,我该如何逃避呢 干杯 我不确定是否有可能逃脱。当

即使产品存在,尝试按其名称加载产品(“什么是测试?”)也会失败

$product = Mage::getModel('catalog/product')->loadByAttribute('name', 'What are Tests?');
但它适用于任何其他名称

当Magento最终通过PDO时,名称中的“?”会被解释为一个参数吗?因为我没有为它传递任何值,所以结束的查询实际上会寻找“什么是测试”。。。因此没有找到产品

如果是这样的话,我该如何逃避呢


干杯

我不确定是否有可能逃脱。当您使用Magento添加属性过滤器时(这就是您在上面所做的),它将使用Zend的quoteInto方法创建where组件,然后将结果字符串添加到Zend Select对象

//create a full where clause
//In this case, $conditionSql = IF(_table_name.value_id>0, _table_name.value, _table_name_default.value) = 'What are Tests?'
$conditionSql = $this->_getAttributeConditionSql($attribute, $condition, $joinType);
...
//add that where clause to a Zend select object 
$this->getSelect()->where($conditionSql);
然后,当Zend select转换为字符串时,它显示为

IF(_table_name.value_id>0, _table_name.value, _table_name_default.value) = 'Product 7800'''
问题是一个完整的,而不是参数化的,正在被添加到select。它是安全的,因为
\u getAttributeConditionSql
使用Zend的
quoteInto
方法,但我很确定,如果where子句中有一个原始的“?”标记(很高兴在这一点上被证明是错误的),则可能通过直接修改资源模型的select来实现这一点,但我不喜欢和Magento这样做

尽管如此,以下内容应该允许您解决这一问题

$product = Mage::getModel('catalog/product')
->getCollection()
->addAttributeToSelect('*')
->addFieldToFilter('name',array('like'=>'What are Tests_'))
->getFirstItem();

上面的代码使用where子句创建一个集合,该子句使用单字符通配符“\u1”代替“?”,然后从顶部提取第一项。不理想,但这应该是一个足够的解决办法

我不确定是否有可能逃脱。当您使用Magento添加属性过滤器时(这就是您在上面所做的),它将使用Zend的quoteInto方法创建where组件,然后将结果字符串添加到Zend Select对象

//create a full where clause
//In this case, $conditionSql = IF(_table_name.value_id>0, _table_name.value, _table_name_default.value) = 'What are Tests?'
$conditionSql = $this->_getAttributeConditionSql($attribute, $condition, $joinType);
...
//add that where clause to a Zend select object 
$this->getSelect()->where($conditionSql);
然后,当Zend select转换为字符串时,它显示为

IF(_table_name.value_id>0, _table_name.value, _table_name_default.value) = 'Product 7800'''
问题是一个完整的,而不是参数化的,正在被添加到select。它是安全的,因为
\u getAttributeConditionSql
使用Zend的
quoteInto
方法,但我很确定,如果where子句中有一个原始的“?”标记(很高兴在这一点上被证明是错误的),则可能通过直接修改资源模型的select来实现这一点,但我不喜欢和Magento这样做

尽管如此,以下内容应该允许您解决这一问题

$product = Mage::getModel('catalog/product')
->getCollection()
->addAttributeToSelect('*')
->addFieldToFilter('name',array('like'=>'What are Tests_'))
->getFirstItem();

上面的代码使用where子句创建一个集合,该子句使用单字符通配符“\u1”代替“?”,然后从顶部提取第一项。不理想,但这应该是一个足够的解决办法

对我来说这听起来像个bug,我认为你应该报告它…对我来说这听起来像个bug,我认为你应该报告它…事实上,我真的很失望,没有核心的修改它是不可能的。。。我要去角落里哭,用你的方法代替…:-(事实上,我真的很沮丧,如果没有核心修改,这根本不可能……我将在角落里哭泣,并使用你的方法代替……:-(