0

I added a custom button on the adminhtml order view page but I do not manage to link it to the associated php function.

Here is the code I used in my module :

EDIT

config.xml

   <?xml version="1.0"?>
<config>
    <modules>  
        <Mine_Sitreatmodule>  
            <version>0.0.1</version>  
        </Mine_Sitreatmodule>  
    </modules>

    <frontend>
        <routers>
            <sitreatmodule>
                <use>standard</use>
                <args>
                    <module>Mine_Sitreatmodule</module>
                    <frontName>sitreatmodule</frontName>
                </args>
            </sitreatmodule>
        </routers>    
        <layout>
            <updates>
                <sitreatmodule>
                    <file>sitreatmodule.xml</file>
                </sitreatmodule>
            </updates>
        </layout>  

        <events>
        <checkout_onepage_controller_success_action>
                <observers>
                    <Mine_Sitreatmodule_Model_Observer>
                        <type>singleton</type>
                        <class>Mine_Sitreatmodule_Model_Observer</class>
                        <method>sitreatmth</method> 
                    </Mine_Sitreatmodule_Model_Observer> 
                </observers> 
            </checkout_onepage_controller_success_action> 
        </events>

         <translate>
            <modules>
                <sitreatmodule>
                    <files>
                        <default>Mine_Sitreatmodule.csv</default>
                    </files>
                </sitreatmodule>
            </modules>
        </translate>

    </frontend>


    <adminhtml>

    <events>
        <controller_action_layout_render_before_adminhtml_sales_order_view>
            <observers>
                <sitreatmodule>
                    <class>sitreatmodule/adminhtml_observer</class>
                    <method>addPaidButton</method>
                </sitreatmodule>
            </observers>
        </controller_action_layout_render_before_adminhtml_sales_order_view>
    </events>

        <routers>
            <sitreatmodule>
                <use>admin</use>
                <args>
                    <module>Mine_Sitreatmodule</module>
                    <frontName>sitreatmodule</frontName>
                </args>
            </sitreatmodule>
        </routers>

    </adminhtml>


    <global>
        <blocks>
            <sitreatmodule>
                <class>Mine_Sitreatmodule_Block</class>
            </sitreatmodule>

        </blocks>
        <models>
            <sitreatmodule>
                <class>Mine_Sitreatmodule_Model</class>
            </sitreatmodule>
        </models>
        <helpers>
            <sitreatmodule>
                <class>Mine_Sitreatmodule_Helper</class>
            </sitreatmodule>
        </helpers>


    </global>

</config>

The Observer

<?php 
class Mine_Sitreatmodule_Model_Adminhtml_Observer 
{
    public function addPaidButton($observer) {
        $block = Mage::app()->getLayout()->getBlock('sales_order_edit');
        if (!$block){
            return $this;
        }
        $order = Mage::registry('current_order');


        $block->addButton('cygtest_resubmit', array(
          'label'     => Mage::helper('sales')->__('Paid'),
          'onclick'   => "location.href='".$block->getUrl('Sitreatmodule/Paid/gotopaid',array('order_id'=>$order->getId()))."'", 
          'class'     => ''
         ));
        return $this;
    }
}

The Controller

    <?php
class Mine_Sitreatmodule_Adminhtml_PaidController extends Mage_Adminhtml_Controller_Action
{

   public function indexAction()
   {
        //$this->loadLayout();
        //$this->renderLayout();
   }

   public function gotopaidAction()
    {
        echo("it works");

    }

}
?>

But when I click the button I get a page not found.

Thank you for your help,

0

Try this way

Create admin Controller file (PaidorderController.php) at location : \app\code\local\Mine\Sitreatmodule\Paidorder\controllers\Adminhtml\

public function gotoPaidAction()
{
    $orderId = $this->getRequest()->getParam('order_id',false);
    $order = Mage::getModel('sales/order')->load($orderId);


}

The Observer

<?php 
class Mine_Sitreatmodule_Model_Adminhtml_Observer 
{
    public function addPaidButton($observer) {
        $block = Mage::app()->getLayout()->getBlock('sales_order_edit');
        if (!$block){
            return $this;
        }
        $order = Mage::registry('current_order');

        $block->addButton('cygtest_resubmit', array(
          'label'     => Mage::helper('sales')->__('Paid'),
          'onclick'   => "location.href='".$block->getUrl('Sitreatmodule/Paidorder/Gotopaid',array('order_id'=>$order->getId()))."'", 
          'class'     => ''
         ));
        return $this;
    }
}
  • thank you for your answer. I do not manage to call the controller action. I have tried several xml declaration in config.xml without success... – Alexglvr Nov 22 '15 at 8:34
  • can you share your config.xml? – Abdul Nov 23 '15 at 4:26
  • Sorry for the delay. I editted the original post with the new code. – Alexglvr Nov 25 '15 at 12:44
  • any idea ? I still haven't found... – Alexglvr Nov 28 '15 at 9:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.