使用自定义表中的 item_id 获取 Sku

发布于 2024-10-21 06:05:26 字数 1122 浏览 2 评论 0原文

我正在创建一个自定义模块。有两张新桌子。

表1:t1_id(PK),order_id(FK)
表2:t2_id(PK)、t1_id(FK)、item_id(FK)。

Table2.item_id 相当于 sales_flat_order_item.item_id。我正在创建自定义报告,并且需要在集合中显示 SKU。首先,我尝试了以下操作:

$collection = Mage::getModel('custom/two')->getCollection();

$tbl_product_collection = Mage::getSingleton('core/resource')->getTableName('catalog/product');
$tbl_one = Mage::getSingleton('core/resource')->getTableName('custom/one');
$tbl_two = Mage::getSingleton('core/resource')->getTableName('custom/two');

$collection->getSelect()  
->from(array('tbl_one' => $tbl_one))  
->join(array('tbl_two' => $tbl_two),  
 'tbl_two.t1_id = tbl_one.t1_id')  
// Join with Item ID on Simple Product  
// Showing wrong SKU   
->join(array('product' => $tbl_product_collection),  
     'tbl_two.item_id = product.entity_id');

但是,product.entity_id实际上是sales_flat_order_item.item_id的product_id。如何通过关联 table2 中的 item_id 来获取集合中的 SKU?

感谢您的任何帮助或建议!

I am creating a custom module. There are two new tables.

Table1: t1_id(PK), order_id(FK)
Table2: t2_id(PK), t1_id(FK), item_id(FK).

Table2.item_id is equivalent to sales_flat_order_item.item_id. I am creating a custom report and in the collection need to show the SKU. At first I tried the following:

$collection = Mage::getModel('custom/two')->getCollection();

$tbl_product_collection = Mage::getSingleton('core/resource')->getTableName('catalog/product');
$tbl_one = Mage::getSingleton('core/resource')->getTableName('custom/one');
$tbl_two = Mage::getSingleton('core/resource')->getTableName('custom/two');

$collection->getSelect()  
->from(array('tbl_one' => $tbl_one))  
->join(array('tbl_two' => $tbl_two),  
 'tbl_two.t1_id = tbl_one.t1_id')  
// Join with Item ID on Simple Product  
// Showing wrong SKU   
->join(array('product' => $tbl_product_collection),  
     'tbl_two.item_id = product.entity_id');

However, the product.entity_id is actually the product_id of sales_flat_order_item.item_id. How can I get the SKU in the collection, by relating to the item_id in table2?

Thanks for any help or suggestions!

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

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

发布评论

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

评论(1

神也荒唐 2024-10-28 06:05:26

需要一点点挖掘。转到您正在查看的核心模型的 config.xml 会有所帮助。这样您就知道 getTableName 转到数据库中的哪个表。

$tbl_product_collection = Mage::getSingleton('core/resource')->getTableName('sales/order_item');
$tbl_one = Mage::getSingleton('core/resource')->getTableName('custom/one');
$tbl_two = Mage::getSingleton('core/resource')->getTableName('custom/two');

$collection->getSelect()
->from(array('tbl_one' => $tbl_one))
->join(array('tbl_two' => $tbl_two),
'tbl_two.t1_id = tbl_one.t1_id')
// 加入项目 ID
->join(array('order_item' => $tbl_order_item),
'tbl_two.item_id = order_item.item_id');

It took a little bit of digging. It helps to go to the config.xml for the core model you are looking at. This way you know which table in the database getTableName goes to.

$tbl_product_collection = Mage::getSingleton('core/resource')->getTableName('sales/order_item');
$tbl_one = Mage::getSingleton('core/resource')->getTableName('custom/one');
$tbl_two = Mage::getSingleton('core/resource')->getTableName('custom/two');

$collection->getSelect()
->from(array('tbl_one' => $tbl_one))
->join(array('tbl_two' => $tbl_two),
'tbl_two.t1_id = tbl_one.t1_id')
// Join Item ID
->join(array('order_item' => $tbl_order_item),
'tbl_two.item_id = order_item.item_id');

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