我正在尝试自定义管理销售订单网格集合。我已经创建了一个定制的sale_order属性store_manager。这些商店经理是管理员用户,例如:“manager1 1”,“manager1 2”。
( 1)命令手动分配给“manager1”或“manager2”-- --这一部分是
2)现在我尝试在销售订单网格集合上设置过滤器,所以当管理员登录到那里的系统时,他们只能看到那里的订单。
在Magento 1中,我们为这一需求提供了sales_order_grid_collection_load_before、sales_order_grid_collection_load_after。
他试图为Magento 2举办这样的活动,但没有取得任何成功。
My查询:
在magento 1中是否有这样的事件(sales_order_grid_collection_load_after)完全满足了我的要求?
还有其他方法可以将筛选设置为销售订单网格集合吗?
注意:我已经在google上搜索过了,但是没有得到任何完美的解决方案。
发布于 2017-10-11 12:15:51
我正在搜索events sales_order_grid_collection_load_after和sales_order_grid_collection_load_before,以定制销售订单网格。
我的发现是,在Magento2中没有这样的事件。一个普通事件core_collection_abstract_load_after或core_collection_abstract_load_before调度来呈现Magento2Admin中的所有网格。
我们可以重写_renderFiltersBefore()函数,在sales网格中添加一个列,或者用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>步骤2:在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();
}
}步骤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>引用是这里
发布于 2018-06-22 14:37:15
我们通常需要在任何di.xml更改之后执行这些命令:
php -dmemory_limit=6G /[MAGENTO2_ROOT]/bin/magento setup:di:compile
php -f /[MAGENTO2_ROOT]/bin/magento setup:upgrade
rm -rf /[MAGENTO2_ROOT]/var/view_preprocessed/ /[MAGENTO2_ROOT]/var/cache/ /[MAGENTO2_ROOT]/var/page_cache/ /[MAGENTO2_ROOT]/var/generation/
rm -rf /[MAGENTO2_ROOT]/pub/static/frontend/
php -dmemory_limit=6G /[MAGENTO2_ROOT]/bin/magento setup:static-content:deploy
php -f /[MAGENTO2_ROOT]/bin/magento cache:flush
php -f /[MAGENTO2_ROOT]/bin/magento cache:clean
sudo chmod -R 777 /[MAGENTO2_ROOT]/var /[MAGENTO2_ROOT]/pub根据您的要求使用这些。
发布于 2018-09-11 06:10:19
对于定制的Grid,我们将使用自己的数据源更改默认数据源。它的父类是网格集合的标准类,它允许第三方扩展使用观察者和插件轻松地处理修改(如果需要的话)。
为了实现这一点,在我们模块的di.xml文件中,指定应该为sales_order_grid数据源使用另一个类。
app/code/Vendor/ExtendGrid/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\ExtendGrid\Model\ResourceModel\Order\Grid\Collection</item>
</argument>
</arguments>
</type>
</config>如您所见,我们将需要一个扩展类来处理集合。让我们在这里创建它:
app/code/Vendor/ExtendGrid/Model/ResourceModel/Order/Grid/Collection.php
<?php
namespace Vendor\ExtendGrid\Model\ResourceModel\Order\Grid;
use Magento\Sales\Model\ResourceModel\Order\Grid\Collection as OriginalCollection;
use Vendor\ExtendGrid\Helper\Data as Helper;
/**
* Order grid extended collection
*/
class Collection extends OriginalCollection
{
}我们修改方法_renderFiltersBefore,以便它能够连接到我们的表并在那里选择必要的列。
为了做到这一点,
<?php
namespace Vendor\ExtendGrid\Model\ResourceModel\Order\Grid;
use Magento\Sales\Model\ResourceModel\Order\Grid\Collection as OriginalCollection;
use Vendor\ExtendGrid\Helper\Data as Helper;
/**
* Order grid extended collection
*/
class Collection extends OriginalCollection
{
protected function _renderFiltersBefore()
{
$joinTable = $this->getTable('sales_order');
$this->getSelect()->joinLeft($joinTable, 'main_table.entity_id = sales_order.entity_id', ['coupon_code']);
//or filter in sale_order_grid collection then use like that
$this->getSelect()->where("main_table.your_attribute is NULL");
parent::_renderFiltersBefore();
}
}https://stackoverflow.com/questions/44001897
复制相似问题