2014-07-19 56 views
0

我試圖在Magento View Order頁面上創建一個按鈕,當我點擊它時,它會使用訂單中包含的信息和訂單中的項目向某個供應商發送電子郵件。Magento Admin查看訂單上的自定義按鈕

我已成功創建模塊和按鈕,我可以單擊該按鈕並顯示警告類型消息。但我無法弄清楚如何使按鈕執行操作。目前該按鈕只是轉到網址。

以下是我有:

MG_Dropship.xml

<?xml version="1.0" encoding="UTF-8"?> 
<config> 
    <modules> 
     <MG_Dropship> 

      <!-- Whether our module is active: true or false --> 
      <active>true</active> 

      <!-- Which code pool to use: core, community or local --> 
      <codePool>local</codePool> 

     </MG_Dropship> 
    </modules> 
</config> 

config.xml中

<?xml version="1.0" encoding="UTF-8"?> 
<config> 
    <modules> 
     <MG_Dropship> 
      <version>0.0.1</version> 
     </MG_Dropship> 
    </modules> 

    <!-- Configure our module's behavior in the global scope --> 
    <global> 

    <blocks> 
     <adminhtml> 
      <rewrite> 
       <sales_order_view>MG_Dropship_Block_Adminhtml_Sales_Order_View</sales_order_view> 
      </rewrite> 
     </adminhtml> 
    </blocks> 

    </global> 

</config> 

View.php

<?php 

class MG_Dropship_Block_Adminhtml_Sales_Order_View extends Mage_Adminhtml_Block_Sales_Order_View { 
    public function __construct() { 

     parent::__construct(); 

     $this->_addButton('dropship', array(
      $message = "Are you sure you want to dropship?", 
      'label'  => Mage::helper('Sales')->__('Dropship'), 
      'onclick' => "confirmSetLocation('{$message}','{$this->getUrl('MG_Dropship')}')" 
     )); 
    } 
} 

任何幫助將不勝感激。

回答

1

模塊中的一切看起來不錯。要獲得所需的附加功能,您需要添加下面的代碼來覆蓋Sales Order控制器來處理url。

在你​​3210設置管理員路由器這樣的:

<config> 

... 

    <admin> 
     <routers> 
      <adminhtml> 
       <use>admin</use> 
       <args> 
        <modules> 
         <dropship before="Mage_Adminhtml_Sales">MG_Dropship_Adminhtml</dropship> 
        </modules> 
       </args> 
      </adminhtml> 
     </routers> 
    </admin> 

... 

</config> 

接下來,你需要設置你的Adminhtml控制器。這將回答您在按鈕的onclick部分中定義的getUrl()。

創建一個名爲OrderController.php的文件,並將其放入app/code/local/MG/Dropship/controllers/Adminhtml/Sales/。把下面的代碼文件中:

include_once Mage::getModuleDir('controllers', 'Mage_Adminhtml') . DS . 'Sales' . DS . 'OrderController.php'; // Some people use the full path but this is the most Magento-friendly way to do it. 

class MG_Dropship_Adminhtml_Sales_OrderController extends Mage_Adminhtml_Sales_OrderController { 

    public function dropshipAction() { 

     // Put all of your code for exporting and e-mailing your order here. 
     // You can use Mage::app()->getRequest()->getParam('order_id') to pull the order_id here. 

     echo 'Your button works!';exit(); // This is just to test that your button actually works. You should see a screen with this message and nothing else when you click the button. 

    } 

} 

現在,您需要更改按鍵的getUrl()一部分。它應該是:

$this->_addButton('dropship', array(
     $message = "Are you sure you want to dropship?", 
     'label'  => Mage::helper('Sales')->__('Dropship'), 
     'onclick' => "confirmSetLocation('{$message}','{$this->getUrl('*/*/dropship')}')" 
    )); 
相關問題