Reputation: 3574
Edit 4/4/12
I STILL HAVE ONE QUESTION:
I solved my issue but it adds my option at the top of the list. How can I sort it to my my option to the bottom of the list?
Please see answer for contents of my working config.xml
file...
I'm looking for in depth help here because I've been at this for quite a while now and seem to be getting nowhere.
Background
I was looking to make a printable RMA form for our customers to make it easier on them to Return/Exchange items.
I did this with the help of this extension: http://www.magentocommerce.com/magento-connect/admin-order-printing-extension.html
(Please download this to see the directory structure if needed)
It adds a button to the order and then I went in and edited the form/form layout so that it was an RMA (or has RMA content).
Everything is working great, however, we have to go into each order and press the button in order for it to print.
We really need a Mass Action
in order to make it more efficient and useful.
Problem
I've tried to different ways to get this to work but I really need help on this. Most recently I've tried to follow this tutorial (http://www.blog.magepsycho.com/adding-new-mass-action-to-admin-grid-in-magento/) using the second method of events
but I can't seem to get this to work.
Can someone please explain in more depth (this last method I've tried) so that I can get it working with this module???
I've added this in the config.xml
(according to the tutorial)
<events>
<core_block_abstract_prepare_layout_before>
<observers>
<orderprint_core_block_abstract_prepare_layout_before>
<class>orderprint/observer</class>
<method>addRmaAction</method>
</orderprint_core_block_abstract_prepare_layout_before>
</observers>
</core_block_abstract_prepare_layout_before>
</events>
And in Nastnet/OrderPrint/Model/Observer.php
I've added this (according to the tutorial)
<?php class Nastnet_OrderPrint_Model_Observer {
public function addRmaAction($observer) {
$block = $observer->getEvent()->getBlock();
if(get_class($block) =='Mage_Adminhtml_Block_Widget_Grid_Massaction'
&& $block->getRequest()->getControllerName() == 'sales_order')
{
$block->addItem('pdfrma_order', array(
'label' => 'Print RMA',
'url' => Mage::app()->getStore()->getUrl('nastnet/controller/action'),
));
}
} }
(Sorry for the messy code above - the only way I could get it highlighted)
EDIT 1 (4/2/12) This is my module's config.xml file. I've had to go with the rewrite/override method as of right now (deleting my attempts at using events). If you see anything, including the exact structure of what it would need to be please let me know...
Minus the <config>
tags:
<modules>
<Nastnet_OrderPrint>
<version>0.1.3</version>
</Nastnet_OrderPrint>
</modules>
<global>
<blocks>
<adminhtml>
<rewrite>
<sales_order_grid>Nastnet_OrderPrint_Block_Sales_Order_Grid</sales_order_grid> <!-- WORKIING METHOD -->
<sales_order_view>Nastnet_OrderPrint_Block_Sales_Order_View</sales_order_view>
</rewrite>
</adminhtml>
</blocks>
<rewrite>
<Nastnet_OrderPrint_OrderController>
<from><![CDATA[#/\w+/sales_order/print/#]]></from>
<to>/orderprint/order/print/</to>
</Nastnet_OrderPrint_OrderController>
</rewrite>
<models>
<Nastnet_OrderPrint>
<class>Nastnet_OrderPrint_Model</class>
</Nastnet_OrderPrint>
</models>
<pdf>
<order>
<default>Nastnet_OrderPrint/order_pdf_items_order_default</default>
<grouped>Nastnet_OrderPrint/order_pdf_items_order_grouped</grouped>
</order>
</pdf>
</global>
<admin>
<routers>
<Nastnet_OrderPrint>
<use>admin</use>
<args>
<module>Nastnet_OrderPrint</module>
<!-- This is used when "catching" the rewrite above -->
<frontName>orderprint</frontName>
</args>
</Nastnet_OrderPrint>
</routers>
Upvotes: 0
Views: 10196
Reputation: 3574
I've figured out the correct handles and everything in order for this to work (with the help of this article: http://mydons.com/simple-example-using-magento-event-observer/)
In the config.xml file, I had to make new <adminhtml>
handles after the <config>
handles. This got me to the right "depth". Here is the entire config.xml file minus the <config>
handles (cause it won't paste correctly):
<modules>
<Nastnet_OrderPrint>
<version>0.1.3</version>
</Nastnet_OrderPrint>
</modules>
<adminhtml>
<events>
<core_block_abstract_prepare_layout_before>
<observers>
<Nastnet_OrderPrint_Model_Observer>
<type>singleton</type>
<class>Nastnet_OrderPrint_Model_Observer</class>
<method>addRmaAction</method>
</Nastnet_OrderPrint_Model_Observer>
</observers>
</core_block_abstract_prepare_layout_before>
</events>
</adminhtml>
<global>
<blocks>
<adminhtml>
<rewrite>
<sales_order_view>Nastnet_OrderPrint_Block_Sales_Order_View</sales_order_view>
</rewrite>
</adminhtml>
</blocks>
<rewrite>
<Nastnet_OrderPrint_OrderController>
<from><![CDATA[#/\w+/sales_order/print/#]]></from>
<to>/orderprint/order/print/</to>
</Nastnet_OrderPrint_OrderController>
</rewrite>
<models>
<Nastnet_OrderPrint>
<class>Nastnet_OrderPrint_Model</class>
</Nastnet_OrderPrint>
</models>
<pdf>
<order>
<default>Nastnet_OrderPrint/order_pdf_items_order_default</default>
<grouped>Nastnet_OrderPrint/order_pdf_items_order_grouped</grouped>
</order>
</pdf>
</global>
<admin>
<routers>
<Nastnet_OrderPrint>
<use>admin</use>
<args>
<module>Nastnet_OrderPrint</module>
<!-- This is used when "catching" the rewrite above -->
<frontName>orderprint</frontName>
</args>
</Nastnet_OrderPrint>
</routers>
</admin>
This is the part that I needed and it is finally correct here:
<adminhtml>
<events>
<core_block_abstract_prepare_layout_before>
<observers>
<Nastnet_OrderPrint_Model_Observer>
<type>singleton</type>
<class>Nastnet_OrderPrint_Model_Observer</class>
<method>addRmaAction</method>
</Nastnet_OrderPrint_Model_Observer>
</observers>
</core_block_abstract_prepare_layout_before>
</events>
</adminhtml>
It points to my observer file (based on the correct event) here: app/code/local/Nastnet/OrderPrint/Model/Observer.php. This obviously then holds my addRmaAction
.
I STILL HAVE ONE QUESTION:
This puts my option at the top of the list. How can I sort it to my my option to the bottom of the list?
Contents of Observer.php
<?php
class Nastnet_OrderPrint_Model_Observer
{
public function addRmaAction($observer)
{
$block = $observer->getEvent()->getBlock();
if(get_class($block) =='Mage_Adminhtml_Block_Widget_Grid_Massaction'
&& $block->getRequest()->getControllerName() == 'sales_order')
{
$block->addItem('rmamassprint', array(
'label' => 'Print Return/Exchange',
'url' => Mage::app()->getStore()->getUrl('orderprint/order/pdfRma'),
));
}
}
}
Upvotes: 2
Reputation: 2004
Here is the working tutorial for adding mass action to Sales > Order Grid: http://www.blog.magepsycho.com/adding-new-mass-action-to-admin-grid-in-magento/
Try the 2nd approach(using event-observer method) which seems to be more upgrade proof way.
Thanks
Upvotes: 0
Reputation: 3054
For starters did you confirm whether or not your observer is being called? Just by adding a Mage::log("Observer called");
and watching the system.log file..
Upvotes: 0