【问题标题】:Magento join two collectionsMagento 加入两个系列
【发布时间】:2014-12-30 08:51:22
【问题描述】:

我需要从以下位置获取数据:

$collection =  Mage::getResourceModel('sales/order_grid_collection')

我还需要从sales_flat_order 表中获取state 列值。

如何将这两者加入并获取数据?

【问题讨论】:

    标签: magento


    【解决方案1】:

    您需要为集合的选择对象添加一个连接。在这种情况下,这很简单,因为所涉及的 2 个表(sales_flat_order_gridsales_flat_order)很容易通过两个表共有的 entity_id 列链接:

    $collection = Mage::getResourceModel('sales/order_grid_collection');
    $select = $collection->getSelect();
    $resource = Mage::getSingleton('core/resource');
    
    $select->join(
        array('order' => $resource->getTableName('sales/order')),
        'main_table.entity_id = order.entity_id',
        array('state')
    );
    

    【讨论】:

    • 如何使用 order created_at date 过滤?
    猜你喜欢
    • 1970-01-01
    • 2015-04-18
    • 1970-01-01
    • 2016-04-23
    • 1970-01-01
    • 2019-08-11
    • 2018-10-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多