Magento 2:通过付款方式获取订单

我在代码块中使用以下代码来提取所有订单,

public function getOrders()
    {
        if (!($customerId = ObjectManager::getInstance()
                ->create('Magento\Customer\Model\SessionFactory')->create()
                ->getCustomer()->getId())) {
            return false;
        }
        if (!$this->orders) {
            $this->orders = $this->getOrderCollectionFactory()->create($customerId)->addFieldToSelect(
                '*'
            )->addFieldToFilter(
                'status',
                ['in' => $this->_orderConfig->getVisibleOnFrontStatuses()]
            )->setOrder(
                'created_at',
                'desc'
            );
        }
        return $this->orders;
    }

如何添加过滤器以通过付款方式提取所有订单?

我尝试使用

addFieldToFilter('method','ccsave');

但这似乎不起作用。

回答:

您不能直接通过付款方式过滤订单收集。

为此,您应该使用订单集合对数据库表进行mysql连接sales_order_payment

if (!$this->orders) {
    $pMethod = 'ccsave';

    $this->orders = $this->getOrderCollectionFactory()->create($customerId)->addFieldToSelect(
        '*'
    )->addFieldToFilter(
        'status',
        ['in' => $this->_orderConfig->getVisibleOnFrontStatuses()]
    );
    /* join with payment table */
    $this->orders->getSelect()
    ->join(
        ["sop" => "sales_order_payment"],
        'main_table.entity_id = sop.parent_id',
        array('method')
    )
    ->where('sop.method = ?',$pMethod );

    $this->orders->setOrder(
        'created_at',
        'desc'
    );

}
赞(0)
微信
支付宝
微信二维码图片

微信扫描二维码打赏

支付宝二维码图片

支付宝扫描二维码打赏

相关文章

0 0 投票数
文章评分
订阅评论
提醒
0 评论
内联反馈
查看所有评论