给后台order view页面顶部添加一个button按钮

4.22K 浏览开发笔记

给后台order view页面顶部添加一个button按钮

在开发中,经常会用到这个功能。

在后台订单详情页面加个自定义按钮,来处理一些业务逻辑。

如何添加自定义按钮呢?

需要先创建一个插件。

假设你已经有一个插件 名为: Zou_Test

分3步:

一,在di.xml里定义plugin类

vim etc/di.xml

             

二, 编写创建button类的代码

vim PluginBlockAdminhtmlOrderView

getOrder();         if($order->getId()){             $message = __('Are you sure you want to do this?');             $url = $subject->getUrl('testadmin/index/markAllPaid',['id'=>$subject->getOrderId()]);             $subject->addButton(                 'mybutton',                 [                     'label' => __('Mark As All Paid'),                      'onclick' => "confirmSetLocation('{$message}', '{$url}')",                     'class' => 'reset'                 ],                 100             );         }              } } ?>

三,编写控制器代码

vim ControllerAdminhtmlIndexMarkAllPaid.php

resultRedirectFactory->create();         $order = $this->_initOrder();         if ($order) {             try {                 $order->setIsHalfPaid(1);                 $order->setDueAmount(0);                 $order->save();                 //$this->orderManagement->hold($order->getEntityId());                 $this->messageManager->addSuccess(__('You order has mark as all paid.'));             } catch (MagentoFrameworkExceptionLocalizedException $e) {                 $this->messageManager->addError($e->getMessage());             } catch (Exception $e) {                 $this->messageManager->addError(__('You have not mark as all paid.'));             }             $resultRedirect->setPath('sales/order/view', ['order_id' => $order->getId()]);             return $resultRedirect;         }         $resultRedirect->setPath('sales/order/view');         return $resultRedirect;     } }

在这个控制器里对订单进行处理,完成后再跳转到订单详情页面去。

最后于 6月前 被admin编辑 ,原因:
0