0

We've created a module for Enterprise that has 2 controller actions, one is the index and the other is a save from a massaction. We're logging to the Admin Actions Log with the following logging.xml:

<?xml version="1.0" encoding="UTF-8"?>
<logging>
    <acme_productlabels translate="label">
        <label>Acme Product Labels</label>
        <actions>
            <productlabels_productlabels_print>
                <action>save</action>
                <post_dispatch>postDispatchGeneric</post_dispatch>
            </productlabels_productlabels_print>
            <productlabels_productlabels_index>
                <action>view</action>
                <post_dispatch>postDispatchSimpleSave</post_dispatch>
            </productlabels_productlabels_index>
        </actions>
    </acme_productlabels>
</logging>

This uses a custom route, so we added an observer in config.xml to accomplish this:

<config>
    <adminhtml>
        <events>
            <controller_action_postdispatch_productlabels>
                <observers>
                    <enterprise_logging>
                        <class>enterprise_logging/observer</class>
                        <method>controllerPostdispatch</method>
                    </enterprise_logging>
                </observers>
            </controller_action_postdispatch_productlabels>
        </events>
    </adminhtml>
</config>

This works fine for the index, but for the save action, it fails. When we use postDispatchSimpleSave for the save action, it logs the action but without the full details.

We need the save action, when logged, to also include the parameters that were submitted to the save action. Currently that includes a selection of products, a quantity, and a boolean value, submitted as a massaction in a grid.

So our basic question is, how do we log the full details of a save action in Magento's admin action log?

0

I spent many hours debugging and exploring Enterprise_Logging module and found that when admin mass updates product attributes, selected product ids are not being fetched correctly. But this module has functionality to save product ids while mass updating. See /app/code/core/Enterprise/Logging/Model/Handler/Controllers.php model and its function:

public function postDispatchProductUpdateAttributes($config, $eventModel, $processor)
    {
        $request = Mage::app()->getRequest();
        $change = Mage::getModel('enterprise_logging/event_changes');
        $products = $request->getParam('product');//here is incorrect values are coming
        if (!$products) {
            $products = Mage::helper('adminhtml/catalog_product_edit_action_attribute')->getProductIds();
        }
        if ($products) {
            $processor->addEventChanges(clone $change->setSourceName('product')
                ->setOriginalData(array())
                ->setResultData(array('ids' => implode(', ', $products))));
        }

    }

by the way $products = $request->getParam('product') expression should get product ids properly but, it is not correct and you should set "product" param as false and next lines

if (!$products) {
     $products = Mage::helper('adminhtml/catalog_product_edit_action_attribute')->getProductIds();
}

will be fetched product ids properly. See my solution: /app/code/local/Some/Module/etc/config.xml:

<global>
    <events>
        <controller_action_predispatch_adminhtml_catalog_product_action_attribute_save>
            <observers>
                <ssd_customeractivation>
                    <class>Some_Module_Model_Observer</class>
                    <method>fixProductIds</method>
                </ssd_customeractivation>
            </observers>
        </controller_action_predispatch_adminhtml_catalog_product_action_attribute_save>
    </events>
</global>

/app/code/local/Some/Module/Model/Observer.php:

class Some_Module_Model_Observer
{
    function fixProductIds()
    {
        //set product param as false
        Mage::app()->getRequest()->setParam('product', false);
    }
}

This solution gives me perfect result.

  • In our case we're trying to log actions on a custom module we've created. How would we capture the POST data submitted by the grid, and log it in admin logging? Would we need to write our own postDispatch method? – user3336 Sep 26 '13 at 0:45
  • Yes of course, I will add new answer – mageUz Sep 26 '13 at 5:14
  • See this answer magento.stackexchange.com/questions/9030/… – mageUz Oct 8 '13 at 8:51

Not the answer you're looking for? Browse other questions tagged or ask your own question.