2

We have created a module that connects to and submits order data to a web-service when a new order is placed an paid for (status = Processing). With every call, we are writing some info to a log file (Successful/Failed/etc).

What I would like to do is push the log entries into the database and create a grid accessible by any admin with permissions to view these log entries. So this will be completely read-only. The grid will show 3 columns -> ID, OrderNumber, and Status (Success/Failed). Clicking on an entry should show them more details about the log entry.

Can anyone please point me towards some online references for implementing this?

2
  • Why don't you store the data in some table instead of log? Log can be deleted or anything can happen.
    – MagePsycho
    Commented Jan 15, 2016 at 16:13
  • My apologies ... was meant to say that I want to instead store logs in the database. I've edited my question.
    – maGz
    Commented Jan 16, 2016 at 4:04

2 Answers 2

3

To make this the most easiest approach, you should alter your logging to go into a database (it'll make creating a grid far easier and more flexible as well.

There are plenty of tutorials out there for creating admin grids, for example: http://inchoo.net/magento/how-to-create-a-custom-grid-from-scratch/

The important parts really come from: _prepareCollection in your grid block. This is where you define the data which is going to be used for powering the grid and this is why I suggest using a Model to store the logs, rather than convert from file system to represent the data. You will be able to simply use a model collection from your module.

The second important part is: _prepareColumns From here your defining the column and what they match up to i.e. your ID, OrderNumber and Status columns.

If you wanted to keep the file system, then your _prepareCollection would need to open the file and parse it into individual models to be represented and add this to a generic collection.

$collection = new Varien_Data_Collection();
// Loop through log file to process this: 
$itemFromLogFile = new Varien_Object();
$itemFromLogFile->setData(/*From Log File Parsing*/); 
$collection->addItem($itemFromLogFile);
5
  • NB: varien_data_collection does not behave as most of the grid collections thus pagination,sorting and filtering won't work by default and you will need modify your custom class to get those functionalities working if you need them Commented Jan 15, 2016 at 18:51
  • Thank you John, I'll have a look at the Inchoo link. And yes, I was meant to say that I want to store the logs in the database (I've edited my answer).
    – maGz
    Commented Jan 16, 2016 at 4:06
  • Thank you John, and sorry for the very late response! I also followed this article which helped me tremendously: smashingmagazine.com/2014/03/…
    – maGz
    Commented Feb 4, 2016 at 10:38
  • Now, I'm just stuck on getting the View action to work when you click on a row in the grid, but I'm sure I can figure that out on my own.
    – maGz
    Commented Feb 4, 2016 at 10:39
  • @RaphaelatDigitalPianism Could you help me with magento.stackexchange.com/q/169333/3895
    – Mukesh
    Commented Apr 10, 2017 at 13:29
0

Another Approach:

Since logs are related to the orders, you can modify the Sales > Order grid columns.
You can either rewrite the block class Mage_Adminhtml_Block_Sales_Order_Grid OR observe the event core_block_abstract_to_html_before for the purpose.

With either approach you will be doing the following:

  1. Adding custom renderer column which will be a link to /your-route/controller/action/order_id/XXXX where order id as parameter
  2. In that controller action, using order_id populate the log entries and display in whatever format you like.

Note that it's not necessary to show in Grid it self. You can simply make your own html table and render from step #2

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.