我正在尝试自定义管理销售订单网格集合。我创建了一个自定义sale_order属性store_manager。这些商店经理是管理员用户,例如:'manager1'、'manager2'。
1)订单手动分配给'manager1'或'manager2'——这部分完成
2)现在我正在尝试对销售订单网格集合设置过滤器,因此当经理登录到那里的系统时,他们只能看到那里的订单。
在Magento 1,我们有sales_order_grid_collection_load_before,sales_order_grid_collection_load_after这一要求。
试图为 Magento 2 举办这样的活动,但没有取得任何成功。
我的查询:
sales_order_grid_collection_load_aftermagento 1 中是否有像 ( )这样的事件完全满足我的要求?
有没有其他方法可以将过滤器设置为销售订单网格集合?
注意:我已经在谷歌上搜索过这个,但没有得到任何完美的解决方案。
小智 5
我正在搜索事件sales_order_grid_collection_load_after并sales_order_grid_collection_load_before自定义销售订单网格。
我的发现是,Magento 2 中没有这样的事件。在 Magento 2 Admin 中呈现所有网格的一般事件core_collection_abstract_load_after或core_collection_abstract_load_before调度。
我们可以覆盖_renderFiltersBefore()函数以在销售订单网格中添加一列或将表与sales_order_grid. 以下是步骤:
步骤 1:为销售订单网格数据源指定类app/code/Vendor/Module/etc/di.xml
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<type name="Magento\Framework\View\Element\UiComponent\DataProvider\CollectionFactory">
<arguments>
<argument name="collections" xsi:type="array">
<item name="sales_order_grid_data_source" xsi:type="string">Vendor\Module\Model\ResourceModel\Order\Grid\Collection</item>
</argument>
</arguments>
</type>
</config>
Run Code Online (Sandbox Code Playgroud)
第 2 步:添加一个 Collection 类app/code/Vendor/Module/Model/ResourceModel/Order/Grid.php来覆盖_renderFiltersBefore()
<?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('your_table');
$this->getSelect()->joinLeft($joinTable, 'main_table.entity_id = your_table.order_id', ['user_id']);
parent::_renderFiltersBefore();
}
}
Run Code Online (Sandbox Code Playgroud)
第 3 步 - 可选:要在销售订单网格中显示新的用户 ID 列,请修改中的标准网格组件app/code/Vendor/Module/view/adminhtml/ui_component/sales_order_grid.xml
<?xml version="1.0" encoding="UTF-8"?>
<listing xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Ui:etc/ui_configuration.xsd">
<columns name="sales_order_columns">
<column name="user_id">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="filter" xsi:type="string">text</item>
<item name="label" xsi:type="string" translate="true">User ID</item>
</item>
</argument>
</column>
</columns>
</listing>
Run Code Online (Sandbox Code Playgroud)
参考在这里
| 归档时间: |
|
| 查看次数: |
11440 次 |
| 最近记录: |