小编Tob*_*obi的帖子

Magento 2 - 在左连接中使用 group_concat 进行选择

我目前正在尝试将订单产品中的 SKU 放入后端的订单网格和过滤器中。它已经在工作,但仅适用于一个 SKU,而不是订单的所有 SKU。我的控制器看起来像这样:

<?php
namespace Vendor\Module\Model\ResourceModel\Order\Grid;

use Magento\Sales\Model\ResourceModel\Order\Grid\Collection as OriginalCollection;
use Magento\Framework\Data\Collection\Db\FetchStrategyInterface as FetchStrategy;
use Magento\Framework\Data\Collection\EntityFactoryInterface as EntityFactory;
use Magento\Framework\Event\ManagerInterface as EventManager;
use Psr\Log\LoggerInterface as Logger;

class Collection extends OriginalCollection
{
    protected $_authSession;
    public function __construct(
       EntityFactory $entityFactory,
       Logger $logger,
       FetchStrategy $fetchStrategy,
       EventManager $eventManager,
       \Magento\Backend\Model\Auth\Session $authSession
      )
    {        
       $this->_authSession = $authSession;
       parent::__construct($entityFactory, $logger, $fetchStrategy, $eventManager);
    }

    protected function _renderFiltersBefore() {
        $user = $this->_authSession->getUser();
        $joinTable = $this->getTable('sales_order_item');
        $this->getSelect()->joinLeft($joinTable, 'main_table.entity_id = sales_order_item.order_id', ['sku'])->group('entity_id');
        parent::_renderFiltersBefore();
    }
}
Run Code Online (Sandbox Code Playgroud)

现在我的问题:是否可以将左连接中的数据选择为 group_concat?如果是这样,请给我一个关于如何做到这一点的提示。我试过这样

$this->getSelect()->joinLeft($joinTable, 'main_table.entity_id …
Run Code Online (Sandbox Code Playgroud)

mysql magento2

1
推荐指数
1
解决办法
2147
查看次数

标签 统计

magento2 ×1

mysql ×1