Magento 捆绑项目按父 ID 过滤

发布于 2024-12-27 23:20:42 字数 506 浏览 2 评论 0原文

我正在尝试获取选择的集合,但根据父产品的 ID 进行过滤。该集合包含一个属性 parent_product_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。

I'm trying to get a collection of selections but filtered on the parent product's id. The collection contains an attribute parent_product_id but apparently this isn't working... The filter is not taken into account.

This is what I have so far:

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

It returns a collection of all selections, so without filter. Is there some way to get only the selections of one specific bundled product? Please note I am using this method for a reason... It should be only based on the parent id.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

千鲤 2025-01-03 23:20:42

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

$sql = Mage::getResourceModel('bundle/selection_collection')->getSelect()->__toString(); 
Mage::log($sql);`

检查您的过滤器是否确实存在(在 WHERE 子句中)并针对您的数据库运行提取的 SQL 查询(如果您有 shell 访问权限,则在 PhpMyAdmin 或 mysql-client 中)。您应该看到问题的根源。

您还可以尝试一种方法,并弄乱集合的Zend_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());

I would suggest to check how the query is constructed by the collection:

$sql = Mage::getResourceModel('bundle/selection_collection')->getSelect()->__toString(); 
Mage::log($sql);`

Check if your filter is really there (in the WHERE clause) and run the extracted SQL Query against your database (in PhpMyAdmin or mysql-client if you have shell access). You should see the source of the problem.

You could also try a dirty method, and mess whit the Zend_Select object of the collection:

$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());
各自安好 2025-01-03 23:20:42

尝试以下操作:

->addAttributeToSelect('*') //select all possible fields    
->addFieldToFilter('parent_product_id',array('eq' => $item->getProductId()));

某些字段是属性,其他字段只是该表中的字段。

查看此文件中的一些示例:
/app/code/core/Mage/Bundle/Model/Product/Type.php

Try the following:

->addAttributeToSelect('*') //select all possible fields    
->addFieldToFilter('parent_product_id',array('eq' => $item->getProductId()));

Some fields are attributes, others are just fields within that table.

Look at this file for some samples:
/app/code/core/Mage/Bundle/Model/Product/Type.php

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文