2

I am currently creating a button for a single order in Magento(next to invoice, ship, reorder etc.). I would like the button to be inside a template to allow for php variables from that order and external js files to be added.

I am currently trying to override the sales order view page and add code from their, this seems to be the best/simplest way. It's reading the new template, but everything else is getting messed up. How do i fix this?

app\code\local\MyApp\OrderButton\etc\config.xml

<config>
<modules>
    <MyApp_OrderButton>
        <version>0.0.1</version>
    </MyApp_OrderButton>
</modules>
<global>
    <models>
        <myapp_orderbutton>
            <class>MyApp_OrderButton_Model</class>
        </myapp_orderbutton>
    </models>
    <blocks>
        <adminhtml>
            <rewrite>
                <sales_order_view_info>ShipRush_OrderButton_Block_Sales_Order_View_Info</sales_order_view_info>
            </rewrite>
        </adminhtml>
    </blocks>
</global>
</config>

app\code\local\MyApp\OrderButton\Block\Sales\Order\View\info.php:

class MyApp_OrderButton_Block_Sales_Order_View_Info extends Mage_Adminhtml_Block_Sales_Order_View_Info
{
    protected function _construct()
    {
       $this->setTemplate('myapp/sales/order/view/myinfo.phtml');
    }
}

Potential template, php, and js:

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script language="javascript" type="text/javascript">
function connect() {
    var allsongs = '<?php echo $x ?>';
    lib = {
        songs: allsongs,
        albums: 20
    };
    alert(lib);
}
</script>

This is read by magento, but it messes up the whole page: enter image description here

  • Could you add the JS function and explain what you are trying to accomplish? – Renon Stewart Jul 15 '15 at 23:19
  • @R.S The javascript function has added scripts from www.example.com/api/myapp/myjs.js and a popup window from example.com comes up. I would like the clicking of the button to trigger this function, but have the button, php, and js all connected, so it must be in a template. – qwerty123 Jul 15 '15 at 23:26
  • @R.S code added – qwerty123 Jul 15 '15 at 23:49
  • What type is $x? Unless it is a int or object then it should be var allsongs = '<?php echo $x ?>' (you are missing the echo) Also what error are you getting? – Renon Stewart Jul 16 '15 at 0:02
  • @R.S question updated – qwerty123 Jul 16 '15 at 18:02
2

I believe your first question is you are not able to override info.phtml file. If that's the case then

Change your layout this way:

<?xml version="1.0"?>
<layout>
    <adminhtml_sales_order_view>
        <reference name="order_tab_info">
            <action method="setTemplate>
                <template>myapp/sales/order/view/info.phtml</template>
            </action>
        </reference>
    </adminhtml_sales_order_view>
</layout>

IMP

Remember if you using layout file to override template then you don't need to rewrite block in config.xml, unless you are also overriding some function or adding new function to it.

       <adminhtml>
            <rewrite>
                <sales_order_view_info>MyApp_OrderButton_Block_Sales_Order_View_Info</sales_order_view_info>
            </rewrite>
        </adminhtml>

Magento layout setTemplate is so powerful that it will handle the work for you.

0

Instead of rewriting the Info block just to make changes to the template file, you may want to consider creating an admin theme. See Magento - Override adminhtml template file

Assuming that your rewrite is working correctly (by view page source or use magento template hint)

Change

var allsongs = <?php $x ?>;

to

var allsongs = <?php echo $x ?>;
//or
var allsongs = '<?php echo $x ?>';

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.