2

I want to add some custom tab in Sales order shipping page so i try to rewrite below way

config.xml

     <?xml version="1.0"?>
<config>
  <modules>
    <MPS_Delivery>
      <version>0.1.0</version>
    </MPS_Delivery>
  </modules>
  <frontend>
    <routers>
      <delivery>
        <use>standard</use>
          <args>
            <module>MPS_Delivery</module>
            <frontName>delivery</frontName>
          </args>
      </delivery>
    </routers>
        <layout>
          <updates>
            <delivery>
              <file>delivery.xml</file>
            </delivery>
          </updates>
        </layout>
  </frontend>
  <global>
    <helpers>
      <delivery>
        <class>MPS_Delivery_Helper</class>
      </delivery>
    </helpers>
    <blocks>
      <delivery>
        <class>MPS_Delivery_Block</class>
      </delivery>
    <adminhtml>
       <!--  <rewrite>
            <sales_order_view_info>MPS_Delivery_Block_Sales_Order_View_Info</sales_order_view_info>
        </rewrite>  -->
         <!-- <rewrite>
            <sales_order_shipment_create_form>MPS_Delivery_Block_Sales_Order_Shipment_Create_Form</sales_order_shipment_create_form>
        </rewrite> --> 
        <rewrite>
    <sales_order_shipment_create_form>MPS_Delivery_Block_Sales_Order_Shipment_Create_Form</sales_order_shipment_create_form>
</rewrite>

    </adminhtml>
    </blocks>
    <models>
      <delivery>
        <class>MPS_Delivery_Model</class>
        <resourceModel>delivery_mysql4</resourceModel>
      </delivery>
      <delivery_mysql4>
        <class>MPS_Delivery_Model_Mysql4</class>
        <entities>        
              <delivery>
                <table>delivery</table>
              </delivery>
        </entities>
      </delivery_mysql4>
    </models>
    <resources>
      <delivery_setup>
        <setup>
          <module>MPS_Delivery</module>
        </setup>
        <connection>
          <use>core_setup</use>
        </connection>
      </delivery_setup>
      <delivery_write>
        <connection>
          <use>core_write</use>
        </connection>
      </delivery_write>
      <delivery_read>
        <connection>
          <use>core_read</use>
        </connection>
      </delivery_read>
    </resources>
  </global>
  <admin>
    <routers>
      <delivery>
        <use>admin</use>
        <args>
          <module>MPS_Delivery</module>
          <frontName>admin_delivery</frontName>
        </args>
      </delivery>
    </routers>
  </admin>
  <adminhtml>
    <menu>
      <delivery module="delivery">
        <title>Delivery</title>
        <sort_order>100</sort_order>
        <children>
          <deliverybackend module="delivery">
            <title>Backend Page Title</title>
            <sort_order>0</sort_order>
            <action>admin_delivery/adminhtml_deliverybackend</action>
          </deliverybackend>
          <delivery module="delivery">
            <title>Manage Delivery</title>
            <sort_order>0</sort_order>
            <action>admin_delivery/adminhtml_delivery</action>
          </delivery>
        </children>
      </delivery>
    </menu>
    <acl>
      <resources>
        <all>
          <title>Allow Everything</title>
        </all>
        <admin>
          <children>
            <delivery translate="title" module="delivery">
              <title>Delivery</title>
              <sort_order>1000</sort_order>
              <children>
          <deliverybackend translate="title">
            <title>Backend Page Title</title>
          </deliverybackend>
          <delivery translate="title">
            <title>Manage Delivery</title>
            <sort_order>0</sort_order>
          </delivery>
              </children>
            </delivery>
          </children>
        </admin>
      </resources>
    </acl>
    <layout>
      <updates>
        <delivery>
          <file>delivery.xml</file>
        </delivery>
      </updates>
    </layout>
  </adminhtml>
</config> 

delivery.xml

<adminhtml_sales_order_shipment_new>
      <reference name="content">
          <action method="setTemplate"><template>delivery/sales/order/shipment/create/form.phtml</template></action>
      </reference>
    </adminhtml_sales_order_shipment_new>

Form.php

<?php
class MPS_Delivery_Block_Adminhtml_Sales_Order_Shipment_Create_Form extends Mage_Adminhtml_Block_Sales_Order_Shipment_Create_Form
{
    public function myFunction() // Your function
    {
        echo "Hello";
    }

But it's not working i don't know what mistake i made here

5
  • The code seems correct. What it the error you are facing? Commented Apr 9, 2017 at 16:06
  • I add Some custom code but it not reflecting if i add in original file sales/order/shipment/create/form.phtml it working
    – Magento 2
    Commented Apr 9, 2017 at 16:07
  • is correct in my delivery.xml
    – Magento 2
    Commented Apr 9, 2017 at 16:08
  • Can you add your full config.xml file to the question? Commented Apr 9, 2017 at 16:10
  • Can you please check my updated question
    – Magento 2
    Commented Apr 9, 2017 at 16:11

1 Answer 1

4

If you want to override sales/order/shipment/create/form.phtml file with your own file then you need to use below code in your delivery.xml file.

<adminhtml_sales_order_shipment_new>
  <reference name="form">
      <action method="setTemplate"><template>delivery/sales/order/shipment/create/form.phtml</template></action>
  </reference>
</adminhtml_sales_order_shipment_new>

To use a function from your block, first you need to make changes to your config.xml add below lines.

<rewrite>
    <sales_order_shipment_create_form>MPS_Delivery_Block_Adminhtml_Sales_Order_Shipment_Create_Form</sales_order_shipment_create_form>
</rewrite>

Now create a new file in app\code\local\MPS\Delivery\Block\Adminhtml\Sales\Order\Shipment\Create\Form.php

<?php
class MPS_Delivery_Block_Adminhtml_Sales_Order_Shipment_Create_Form extends Mage_Adminhtml_Block_Sales_Order_Shipment_Create_Form
{
    public function myFunction() // Your function
    {
        echo "Hello";
    }
}

Now you can use this function in your form.phtml

8
  • IS it correct <rewrite> <sales_order_create_form>MPS_Delivery_Block_Adminhtml_Sales_Order_Create_Form</sales_order_create_form> </rewrite>
    – Magento 2
    Commented Apr 9, 2017 at 16:40
  • because i can't able to use that function in my templete
    – Magento 2
    Commented Apr 9, 2017 at 16:41
  • Please check updated answer Commented Apr 9, 2017 at 16:46
  • Invalid method MPS_Delivery_Block_Sales_Order_Shipment_Create_Form::myFunction(Array ( ) )
    – Magento 2
    Commented Apr 9, 2017 at 16:51
  • Can you share your phtml file Commented Apr 9, 2017 at 16:52

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.