1

I have followed this tutorial from inchoo.net to get a test module to override a frontend module and it worked. I am now trying to override an adminhtml module, but without much less success.

<config>
....

<global>
    <blocks>
        <adminhtml>
            <rewrite>
                <newsletter_queue_grid_renderer_action>Ps_Newsletter_Block_Adminhtml_Newsletter_Queue_Grid_Renderer_Action</newsletter_queue_grid_renderer_action>
            </rewrite>
        </adminhtml>

        <newsletter>
            <class>Ps_Newsletter_Block</class>
        </newsletter>
    </blocks>
</global>

<admin>
    <routers>
        <adminhtml>
            <args>
                <module>
                    <Ps_Newletter before="Mage_Adminhtml">Ps_Newsletter_Adminhtml</Ps_Newletter>
                </module>
            </args>
        </adminhtml>
    </routers>
</admin>
....
</config>

-

class Ps_Newsletter_Block_Adminhtml_Newsletter_Queue_Grid_Renderer_Action
extends Mage_Adminhtml_Block_Newsletter_Queue_Grid_Renderer_Action
{
public function render(Varien_Object $row)
{
    $actions[] = array(
        'url'       =>  $this->getUrl('*/newsletter_queue/send',array('id'=>$row->getId())),
        'caption'   =>  Mage::helper('newsletter')->__('Send'),
        'popup'     =>  true
    );

    $this->getColumn()->setActions($actions);
    return parent::render($row);
}
}

I have tried to follow a similar technique to the test module, while adding the additional nodes in for it being on the admin side, then tried this tutorial, I guess i've missed something, but what am I doing wrong?

===EDIT===

I have var_dump($actions) and it is displaying expected information, however "send" is not being applied in the action section, below "preview". When I add the above code into the core file it works. So what is happing here that is different? (I thought that extending a file would output the extension value as well as block are called automatically....or so i believe)

1
  • 1
    Don't add this in your config file <newsletter><class>Ps_Newsletter_Block</class></newsletter>. This will override all of your newsletter blocks for frontend. You will get a lot of errors or missing sections in frontend.
    – Marius
    Oct 10, 2013 at 8:47

1 Answer 1

5

You may have forgotten the 's' in the tag modules

<admin>
    <routers>
        <adminhtml>
            <args>
                <modules>
                    <Ps_Newletter before="Mage_Adminhtml">Ps_Newsletter_Adminhtml</Ps_Newletter>
                </modules>
            </args>
        </adminhtml>
    </routers>
</admin>

[EDIT] I tried to reproduce it with the following and for me it worked. You have maybe a conflict or a problem somewhere else. I cannot say without your complete code.

<?xml version="1.0"?>
<config>
    <modules>
        <Ps_Newsletter>
            <version>0.1.0</version>
        </Ps_Newsletter>
    </modules>

    <global>
        <blocks>
            <ps_newsletter>
                <class>Ps_Newsletter_Block</class>
            </ps_newsletter>
            <adminhtml>
                <rewrite>
                    <newsletter_queue_grid_renderer_action>Ps_Newsletter_Block_Adminhtml_Queue_Grid_Renderer_Action</newsletter_queue_grid_renderer_action>
                </rewrite>
            </adminhtml>
        </blocks>
        <helpers>
            <ps_newsletter>
                <class>Ps_Newsletter_Helper</class>
            </ps_newsletter>
        </helpers>
    </global>

    <admin>
        <routers>
            <adminhtml>
                <args>
                    <module>
                        <Ps_Newletter before="Mage_Adminhtml">Ps_Newsletter_Adminhtml</Ps_Newletter>
                    </module>
                </args>
            </adminhtml>
        </routers>
    </admin>
</config>

[EDIT 2] the overwrite of the class Mage_Adminhtml_Block_Newsletter_Queue_Grid_Renderer_Action is wrong, you should have a different approach regarding the actions. They are initialized in the parent class (the Newsletter one), so you have to copy the code of the parent class and skip it. For that extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Action instead of Mage_Adminhtml_Block_Newsletter_Queue_Grid_Renderer_Action. See below what I mean

class Ps_Newsletter_Block_Adminhtml_Newsletter_Queue_Grid_Renderer_Action extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Action
{
    public function render(Varien_Object $row)
    {
        $actions = array();

        if($row->getQueueStatus()==Mage_Newsletter_Model_Queue::STATUS_NEVER) {
               if(!$row->getQueueStartAt() && $row->getSubscribersTotal()) {
                $actions[] = array(
                    'url' => $this->getUrl('*/*/start', array('id'=>$row->getId())),
                    'caption'   => Mage::helper('newsletter')->__('Start')
                );
            }
        } else if ($row->getQueueStatus()==Mage_Newsletter_Model_Queue::STATUS_SENDING) {
            $actions[] = array(
                    'url' => $this->getUrl('*/*/pause', array('id'=>$row->getId())),
                    'caption'   =>  Mage::helper('newsletter')->__('Pause')
            );

            $actions[] = array(
                'url'       =>  $this->getUrl('*/*/cancel', array('id'=>$row->getId())),
                'confirm'   =>  Mage::helper('newsletter')->__('Do you really want to cancel the queue?'),
                'caption'   =>  Mage::helper('newsletter')->__('Cancel')
            );


        } else if ($row->getQueueStatus()==Mage_Newsletter_Model_Queue::STATUS_PAUSE) {

            $actions[] = array(
                'url' => $this->getUrl('*/*/resume', array('id'=>$row->getId())),
                'caption'   =>  Mage::helper('newsletter')->__('Resume')
            );

        }

        $actions[] = array(
            'url'       =>  $this->getUrl('*/newsletter_queue/preview',array('id'=>$row->getId())),
            'caption'   =>  Mage::helper('newsletter')->__('Preview'),
            'popup'     =>  true
        );

       /* Add your custom ACTIONS here */

       /* EOF */

        $this->getColumn()->setActions($actions);
        return parent::render($row);
    }
}
7
  • changing <module> to <modules> has had no effect, what else could I check for?
    – tony09uk
    Oct 10, 2013 at 9:03
  • thanks for that edit but it still doesn't work. In var/log/admin.log I get an unhelpful message 2013-10-10T09:52:45+00:00 INFO (6): myname /admin/newsletter_queue/ if there was a conflict would it not show up here?
    – tony09uk
    Oct 10, 2013 at 9:56
  • Please see my edit, yeah cache is a valid point but i always keep it disabled
    – tony09uk
    Oct 10, 2013 at 10:17
  • did you tried to just do an return echo 'test' to see if your render object is applied? Remove return parent::render(..) temporary Oct 10, 2013 at 10:26
  • 1
    I see your problem. You overwrite Mage_Adminhtml_Block_Newsletter_Queue_Grid_Renderer_Action::render and do return parent::render($row) but it's wrong. The actions are initialized in the parent (the newsletter class). You have to skip the parent and go higher in the hierarchy of the class or do have a different approach. See my edit again Oct 10, 2013 at 10:35

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.