我想在Magento2的Order Grid中添加一个MassAction。
我在view / adminhtml / ui_component / sales_order_grid.xml中添加了xml。添加此XML MassAction是在dropdown中显示的。但是当我选择MassAction时,我没有在post请求中获得订单ID。
<?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">
<listingToolbar name="listing_top">
<massaction name="listing_massaction">
<action name="mass_order_assigntrackingnumber">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="type" xsi:type="string">order_assigntrackingnumber</item>
<item name="label" xsi:type="string" translate="true">Assign Tracking Number</item>
<item name="url" xsi:type="url" path="helloworld/orderprocessing/"/>
</item>
</argument>
</action>
</massaction>
</listingToolbar>
</listing>
我在打印POST请求时收到了: -
Array
(
[key] => 2c7824dfa98ff4e9f550d2f4d07e696c650fbb48448ac3f8a8377f1c793e9294
[excluded] => false
[filters] => Array
(
[placeholder] => true
)
[search] =>
[namespace] => sales_order_grid
[form_key] => hvUs2LDFHbjJN3zY
)
群众行动控制器
<?php
namespace Inchoo\Helloworld\Controller\Adminhtml\Orderprocessing;
class Index extends \Magento\Backend\App\Action{
public function execute(){
$data = $this->getRequest()->getParams();
echo "<pre>";print_r($data); die;
die("Hello");
}
}
?>
请帮助我了解如何通过 Magento2 中的MassAction控制器中的自定义MassAction获取订单ID?
答案 0 :(得分:2)
群众行动控制器
通过以下方式更新代码:
<?php
namespace Inchoo\Helloworld\Controller\Adminhtml\Orderprocessing;
class Index extends \Magento\Sales\Controller\Adminhtml\Order\AbstractMassAction {
protected function massAction(AbstractCollection $collection){
//your code here
//Here you will get collection
}
}
参考代码:/var/www/html/mage2/vendor/magento/module-sales/Controller/Adminhtml/Order/MassCancel.php