0

I am trying to create a button on the Magento View Order page that when I click it, it will email a certain vendor using information that is contained on the order and items in the order.

I have successfully created the module, and the button, I can click the button and it displays a warning type message. But I cannot figure out how to make the button perform the action. Currently the button is just going to a URL.

Here is what I have:

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

Any help would be greatly appreciated.

1
  • i found a bug into it, your extension not make a correct url please check once . Commented Jul 19, 2014 at 6:58

2 Answers 2

1

One note there, you could do it easily without a rewrite:

Observe core_block_abstract_to_html_before (add the event in your adminhtml node) and in your observer add:

 public function core_block_abstract_to_html_before($observer)
    {
        $block = $observer->getBlock();
        if ($block instanceof Mage_Adminhtml_Block_Sales_Order_View && $block->getRequest()->getControllerName() == 'sales_order') {
            $orderId = Mage::app()->getRequest()->getParam('order_id');
            $block->addButton('dropship', array(
                'label' => Mage::helper('sales')->__('Dropship'),
                'onclick' => "confirmSetLocation('" . $message . "','" . Mage::helper("adminhtml")->getUrl('adminhtml/sales_order_dropship/dropship', array('id'=>$order_id)) . "')",
                'class' => 'go'
            ));

        }
    }

Following this, if you need functionality from sales block create your own block, extend the sales block and create your own controller.

Concerning your url (if you want to keep your way of working), you should use:

'onclick' => "confirmSetLocation('" . $message . "','" . Mage::helper("adminhtml")->getUrl('adminhtml/sales_order_dropship/dropship', array('id'=>$order_id)) . "')"

This should work as you have overriden the block that controller calls.

Sorry for the large amount of edits, seems it's not my day today :)

0

you make sure that your url is correct, to make your url as you like or workable for you

public function getDripshipUrl()
    {
        return $this->getUrl('*/sales_order_dropship/dropship');
    }

add this code into View.php file and use $this->getDripshipUrl('Dropship') to get the url, for for email or shipment action need to make a controller please inheritance the sales order controller Mage_Adminhtml_Sales_OrderController and put the desired action over here, hope this will help you. if you want to redirect to another page on admin add some phtml files in adminhtml block also.

1
  • I am still working on getting the link to work. Now when I click the button it takes me here: /index.php/admin/sales_order_dropship/dropship/order_id/752/ but thats a 404 page. Can you tell me how the folder structure should be setup? Commented Jul 19, 2014 at 14:49

Your Answer

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

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