PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Tuesday, August 23, 2022

[FIXED] How to add MassAction on Order Grid in Magento2?

 August 23, 2022     magento, magento2, php     No comments   

Issue

I want to add a MassAction in Order Grid in Magento2.

I add xml in view/adminhtml/ui_component/sales_order_grid.xml.By adding this XML MassAction is show in dropdown.But when I select the MassAction I did not get the order ids in post request.

<?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>

I got when I print the POST request :-

Array
(
    [key] => 2c7824dfa98ff4e9f550d2f4d07e696c650fbb48448ac3f8a8377f1c793e9294
    [excluded] => false
    [filters] => Array
        (
            [placeholder] => true
        )

    [search] => 
    [namespace] => sales_order_grid
    [form_key] => hvUs2LDFHbjJN3zY
)

Mass Action Controller

<?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");
        }
    }
?>

Please help me in to find out how to get order ids via custom MassAction in MassAction controller in Magento2 ?


Solution

Mass Action Controller

Update code by this:

<?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
    }
}

Reference code: /var/www/html/mage2/vendor/magento/module-sales/Controller/Adminhtml/Order/MassCancel.php



Answered By - Sarfaraz bheda
Answer Checked By - Pedro (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing