Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ruby-on-rails-3/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
按父id筛选Magento捆绑项目_Magento_Collections_Bundle_Product - Fatal编程技术网

按父id筛选Magento捆绑项目

按父id筛选Magento捆绑项目,magento,collections,bundle,product,Magento,Collections,Bundle,Product,我正在尝试获取一个选择集合,但根据父产品的id进行筛选。该集合包含一个属性parent\u product\u id,但显然这不起作用。。。不考虑过滤器 这就是我到目前为止所做的: $children = Mage::getResourceModel('bundle/selection_collection') ->addAttributeToSelect(array('product_id', 'selection_price_value')) ->setStore

我正在尝试获取一个选择集合,但根据父产品的id进行筛选。该集合包含一个属性
parent\u product\u id
,但显然这不起作用。。。不考虑过滤器

这就是我到目前为止所做的:

$children = Mage::getResourceModel('bundle/selection_collection')
    ->addAttributeToSelect(array('product_id', 'selection_price_value'))
    ->setStoreId(Mage::app()->getStore()->getId())
    ->addAttributeToFilter('parent_product_id',$item->getProductId());

它返回所有选择的集合,因此不带过滤器。有没有办法只获得一种特定捆绑产品的选择?请注意,我使用这种方法是有原因的。。。它应该只基于父id。

我建议检查集合如何构造查询:

$sql = Mage::getResourceModel('bundle/selection_collection')->getSelect()->__toString(); 
Mage::log($sql);`
检查您的过滤器是否确实存在(在WHERE子句中),并对您的数据库运行提取的SQL查询(如果您有shell访问权限,则在PhpMyAdmin或mysql客户端中)。你应该看到问题的根源

您还可以尝试一种方法,并将集合的
Zend\u Select
对象弄乱:

$collection = Mage::getResourceModel('bundle/selection_collection')
    ->addAttributeToSelect(array('product_id', 'selection_price_value'))
    ->setStoreId(Mage::app()->getStore()->getId());
$collection->getSelect()->where('`selection`.`parent_product_id` = '.$item->getProductId());
请尝试以下操作:

->addAttributeToSelect('*') //select all possible fields    
->addFieldToFilter('parent_product_id',array('eq' => $item->getProductId()));
一些字段是属性,其他字段只是该表中的字段

查看此文件中的一些示例:
/app/code/core/Mage/Bundle/Model/Product/Type.php是的,我知道我可以用它,但我真的更喜欢用正确的方式做事情。。。当magento失败时,这更像是一种黑客行为,但在我看来,常规属性过滤器必须工作。查询字符串当然已经过测试,父产品id的where子句从未被添加。如果您使用EAV模型,或者乱用连接,这实际上只是一种攻击。在平面表格上使用->where()可能是筛选平面集合的最佳方法。看起来您还没有得到答案?还没有。。。虽然“黑客”可能会奏效,但我仍然希望有一个优雅的解决方案。