2

Below is an image of the screen at this URL in our Magento Community edition.

It is the grid view of all sales orders.

I have been tasked with building a printable worksheet report that will list all the orders in our Magento so in a nutshell I need to get the data that you see on this image below along with a couple other items about an order, such as the image for the products and dimensions. As well as be able to sort the data based of different order statuses.

I am not sure the best way that I can get all this data though.

Is it possible to query the database for all this data? What I build does not even have to be a Magento extensions, if it;s possible to simple query the database and build these reports that would be fine too.

Another idea, is perhaps the API is the best route to get all this data?

As I am new to Magento and haven't touched it in the past month even, I am just not sure where to start here.

Would appreciate any tips on how you would achieve this task.

All orders in our System have a Status and my boss would like these printable reports to list each Status as a heading section and then list all orders under each status section, so that is how I need to sort the data

http://www.domain.com/index.php/admin/sales_order/index/key/d99d05283bcf037b8476eb938cdd8649/

enter image description here

4

Collections

First start out with a basic script including the Magento core, instantiating Mage::app() with store ID 0 (admin) and using the following code to retrieve an order collection in this case filtered by date.

$collection = Mage::getModel('sales/order')->getCollection()
                ->addAttributeToFilter('created_at', array(
                   'from' => '2013-09-05',
                   'to' => '2013-09-05',
                   'date' => true,
                ));

More on collections here.

Adminhtml extensions

Once you're comfortable with creating these collections and you're able to retrieve the data you need you'll have to look into creating an adminhtml extension with it's own controller to output the data to print.

This slideshare presentation should point you in the right direction. You'll probably need something like a form to let the user define some filters like order dates which posts to the final output page.

Printing the orders

Now for the last step we'll need to actually output the data in a printable format. I'd suggest using the PDF format for that since it works well with printers (breaking data up into pages etc)

Creating PDF's in Magento is best done with the Zend_Pdf class that comes standard with Magento. I found a nice example over on stackoverflow.

The stackoverflow link also gives another solution that adds a PDF export function to the sales > order grid. It's also a nice approach that you might want to look into the only downside being that you are limited by the collection provided in the grid.

[EDIT] Using a non-coding approach

So I just realised that if you want to do this quickly without getting your hands dirty on code just throw in a print media stylesheet.

<link rel="stylesheet" type="text/css" href="http://www.domain.com/skin/adminhtml/base/default/css/myprintablegrid.css" media="print" />

Add a display:none; to basically all elements except for the grid which should work pretty well I guess. :)

  • thanks this deffinetly puts me back on the right track, I actually need to get more data than is available in just this collection but this is a big help, thanks – JasonDavis Sep 12 '13 at 19:31
  • You can always join other tables into the collection you're retrieving. I'd suggest using the Magento models over direct queries to prevent issues when you upgrade to a newer Magento version. – Sander Mangel Sep 12 '13 at 19:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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