Question

Here I will add the solution to the question just in case someone else has the same issue/extension. I have also sent the Code updates to [link]http://www.boostmyshop.com/english/magento/product-return-rma.html to add to a possible upgrade of their RMA's extension.

I needed to add the name of the logged in admin that created an RMA in Magento CE 1.7 using the above extension that I purchased along with their Embedded ERP solution.

Here's the code:

add this to AdminController.php (Not sure if it is really neccessary)

    public function getUser()    {  

   return Mage::getSingleton('admin/session')->getUser();   

}

At the top of info.phtml add this:

 <?php $user = Mage::getSingleton('admin/session');$userName = $user->getUser()>getUsername();?>

Then this around line 10

<input name="data[rma_admin]" type="hidden" value="<?php echo $userName ?>" />

Then create an additional tr/td and add this:

       <tr><td class="label"><?php echo $this->__('Updated by'); ?></td><td class="input-ele"><?php echo $this->getRma()->getrma_admin(); ?> </td> </tr>

You must also add the additonal columns to display the admin name in the Grid.php files

 $this->addColumn('rma_admin', array(
'header'=> Mage::helper('ProductReturn')->__('Updated by'),
'width' => '100px', 
'type'  => 'text', 
'index' => 'rma_admin', )); 

Finally inside the rma Database table ceate a new column called "rma_admin"

Done!!!

Was it helpful?

Solution

This answer refers to the Enterprise_Rma module, not the CE extension the OP is using.

As far as I understand, what you are wanting to do is set the admin user value on the RMA model when an RMA is created in the backend.
You already have added the column admin_user (or whatever you have used as your attribute code) to the enterprise_rma table.

Instead of using a controller overwrite to achieve your goal, it's much more compatible and upgrade safe to use an event observer.

Unfortunately, the RMA model doesn't set it's own event prefix, so you will have to observer the generic core_abstract_save_before event, and check the object instance type in the observer method.

To do so, you first need to define it in your modules etc/config.xml file.

<global>
    <models>
        <myModul_productReturn>
            <class>MyModul_ProductReturn_Model</class>
        </myModul_productReturn>
    </models>
</global>
<adminhtml>
    <events>
        <core_abstract_save_before>
            <observers>
                <myModul_productReturn>
                    <class>myModul_productReturn/observer</class>
                    <method>coreAbstractSaveBefore</method>
                </myModul_productReturn>
            </observers>
        </core_abstract_save_before>
    </events>
</adminhtml>

Then, in the observer class:

class MyModul_ProductReturn_Model_Observer
{
    public function coreAbstractSaveBefore(Varien_Event_Observer $observer)
    {
        $model = $observer->getObject();
        if ($model instanceof Enterprise_Rma_Model_Rma) {
            /** @var Enterprise_Rma_Model_Rma $model */
            if ($model->isObjectNew()) {
                /** @var Mage_Admin_Model_User $admin */
                $admin = Mage::getSingleton('admin/session')->getUser();
                if ($admin && $admin->getId()) {
                    $model->setAdminUser($admin->getUsername());
                }
            }
        }
    }
}

Now, every time a new RMA is saved, the admin's username will be set.

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top