3

I've followed this link to add custom button in Admin Sales Order View in Magento 2, and it works great. Now I want to replace this button with 3 dropdown options button. Something like changing store scope in Admin Panel. I want this 3 buttons to run same controller method with different parameters. How can i achieve this?
Thanks in advance.

asked Jul 15, 2020 at 11:32

3 Answers 3

2

This code works for me , try to look splitButton

class ViewPlugin
{
 public function beforeSetLayout(
 MagentoView $view,
 LayoutInterface $layout
 ) {
 
 $addButtonProps = [
 'id' => 'test',
 'label' => __('Test'),
 'class' => 'add',
 'button_class' => '',
 'class_name' => 'Magento\Backend\Block\Widget\Button\SplitButton',
 'options' => $this->getCustomActionListOptions(),
 ];
 $view->addButton('test',$addButtonProps);
 }
 protected function getCustomActionListOptions()
 {
 /*list of button which you want to add*/
 $splitButtonOptions=[
 'action_1'=>['label'=>__('Action 1'),'onclick'=>'setLocation("ACTION 1")'],
 'action_2'=>['label'=>__('Action 2'),'onclick'=>'setLocation("ACTION 2")'],
 'action_3'=>['label'=>__('Action 3'),'onclick'=>'setLocation("ACTION 3")']
 ];
 
 return $splitButtonOptions;
 }
}
 <type name="Magento\Sales\Block\Adminhtml\Order\View">
 <plugin name="addMyButton" type="My\Module\Plugin\Block\Adminhtml\Order\View"/>
 </type>
answered Jul 15, 2020 at 16:22
2
  • Thanks for your answer. Today or tomorrow i will try and let you know :) Commented Jul 16, 2020 at 7:30
  • after i wrote above comment i realized that it uses the same plugin. So i tested and it works :D thanks, and also thanks for information that this is split button :D Commented Jul 16, 2020 at 7:38
1

I have created it by calling sales_order_view.xml first create sales_order_view.xml in vendor/module/view/adminhtml/layout/sales_order_view.xml

answered Apr 5, 2023 at 10:31
1
  • <?xml version="1.0"?> <page xmlns:xsi="w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd"> <body> <referenceBlock name="sales_order_edit"> <block class="vendor\Module\Block\Adminhtml\Order\View\Buttons" name="custom_buttons" /> </referenceBlock> </body> </page> Commented Apr 5, 2023 at 10:35
-1
namespace vendor\module\Block\Adminhtml\Order\View;
class Buttons extends \Magento\Sales\Block\Adminhtml\Order\View
{ 
 protected function _construct()
 {
 parent::_construct();
 if(!$this->getOrderId()) {
 return $this;
 } 
 $addButtonProps = [
 'id' => 'stocksheet',
 'label' => __('Shocksheet'),
 'class' => 'add',
 'button_class' => '',
 'class_name' => 'Magento\Backend\Block\Widget\Button\SplitButton',
 'options' => $this->getCustomActionListOptions(),
 ];
 $this->addButton('test',$addButtonProps);
 
 return $this;
 }
 protected function getCustomActionListOptions()
 {
 $csvUrl = $this->_urlBuilder->getUrl(
 'vestocksheet/index',
 ['order_id' => $this->getOrder()->getIncrementId()]
 );
 /*list of button which you want to add*/
 $splitButtonOptions=[
 'csv'=>['label'=>__('CSV'),'onclick' => 'setLocation(\'' . $csvUrl . '\')'],
 'pdf'=>['label'=>__('PDF'),'onclick' => 'setLocation(\'' . $csvUrl . '\')']
 ];
 return $splitButtonOptions;
 }
}
Deep Shah
5737 silver badges32 bronze badges
answered Apr 5, 2023 at 10:35

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.