Category Archives: Administrator/Back-end

For administrators and users of the back-end area of the site.

Customising Transactional Emails

If it is necessary to change the any of the transactional emails, it is possible to do this from within the administrator interface. First let’s clarify the term transactional email, by this consider the following forms that are generated with the standard operating processes:
Contact Form
Credit Memo Update
Credit Memo Update for Guest
Currency Update Warning
Forget Admin Password
Forgot Password
Invoice Update
Invoice Update for Guest
Log cleanup Warning
Moneybookers activate Email
New Credit Memo
New Credit Memo for Guest
New Invoice
New Invoice for Guest
New Order
New Order for Guest
New Shipment
New Shipment for Guest
New account
New account for Guest
Newsletter subscription confirmation
Newsletter subscription success
Newsletter unsubscription success
Order Update
Order Update for Guest
Payment Failed
Product alerts Cron error
Product price alert
Product stock alert
Remind Password
Send product to a friend
Share Wishlist
Shipment Update
Shipment Update for Guest
Sitemap generate Warnings
Token Status Change

To update any of these forms it is possible to enter the Administrator Backend. Then go to the following menu option System -> Transactional Emails.

Then Add New Template. From the new form that opens:

Backend -> System -> Transactional Emails -> Add New Template -> Load default template

This will allow selection of the forms listed above when selecting the Template* dropdown.

Then select the locale dropdown to define the language option that the new template will be applied to.

When the Load Template button is selected this will populate the bottom half of the form and it will be possible to customise this directly and save it. This template will then be used for the conditions applied.

Adding A Custom Column To The Adminhtml Grid Widget

Recently it was necessary to add a new custom column to the Adminhtml Grid widget, as a new delivery date value had been created but was not appearing in the orders view associated to the customer.

So the form to be modified has been centralised and can be found at: /app/design/adminhtml/default/{theme}/template/widget/grid.phtml

at the top of this form the following was added, based on the requirement of the custom delivery date field that had already been created.

$this->addColumn('delivery_datetime', array(
    'header' => $this->__('Delivery Datetime'),
    'index' => 'delivery_datetime',
    'type' => 'date',
    'width' => '100px',
));

This was superb and added the column to the end of the grid. However, it was far more useful to apply the column after the store information, so the order of the grid was changed with the following code snippet:

$this->addColumnsOrder('delivery_datetime', 'store_id')
    ->sortColumnsByOrder();

The store_id value was extracted when the following debug code was added into the form, which while a little unsightly, both from a coding and a layout perspective, identified the values involved in the grid:

‘);
var_dump ($innerInnerColumn);
}
}
}
?>
[\php]

This code was placed after

<?php foreach ($this->getColumns() as $_column): ?>

Resources:
magento-grid-column-position

Adding Checkboxes To An Admin Form

If the requirement is to offer an administrator an assortment of form options from an array it is possible to use a checkbox field.

The following will simply output the data from the array as defined in the

class {Namespace}_{Module}_Block_Adminhtml_{Controller}_Edit_Tab_{Formname} extends Mage_Adminhtml_Block_Widget_Form
{
    protected function _prepareForm()
    {
        $form = new Varien_Data_Form();
        $this->setForm($form);

        $fieldset = $form->addFieldset('{formname}_form',
            array('legend' => 'Legend'));

        $possibleOptionsArray = Mage::getModel('{namespace}/{module}')->getArrayFunction('array', 'name');

        $fieldset->addField('{id}', 'checkboxes', array(
            'label'     => $this->__('Label'),
            'name'      => '{row_name}[]',
            'value'     => $currentValueArray,
            'values'    => $possibleOptionsArray,
            'disabled'  => false
        ));

Important note: ‘name’ => ‘{row_name}[]’,
The name definition should be an array that ends with [].

controller saveAction to contain the following:

foreach ($data as $key => $value)
{
    if (is_array($value))
    {
        $data[$key] = implode(',',$this->getRequest()->getParam($key));
    }
}

Redirect In Grid To Admin URL

As part of the creation of a grid that contained sales orders, it was necessary to redirect the click on a grid row to the sales order view for the id of the row in question.

To accomplish this the following code was used in the Grid.php file:

public function getRowUrl($row) {
    return ($this->getUrl('adminhtml/sales_order/view', array('order_id' => $row->getId())));
}

Note that the adminhtml in the return line above was replaced with the magic key string for the administrator area.

Changing The Adminhtml Template Location

This solution came courtesy of the Magento forums, but is so simple, it deserves repetion here:

Create a folder in the /app/design/adminhtml/default/ directory, this will be the name of the new admin theme.

Then modify the local.xml file located in the /app/etc/ directory by adding the following code:

    <stores>
        <admin>
            <!-- default admin design package and theme -->
            <design>
                <theme>
                    <default>{folder_name}</default>
                </theme>
            </design>
        </admin>
    </stores>

Note that for simplicity, it may be ideal to place this code immediately before the closing tag at the end of the file.

Resources:
http://www.magentocommerce.com/boards/viewthread/17306/P15/

Creating Administrator Reports

While Magento offers a number of reports that cover many of the operational business needs, people always seem to need their own sort of data, in a format that makes sense to them. For this reason it is possible to create custom reports for Administrators. The basics of such reporting is covered here.

The following example requires the creation of the following files:
/app/code/etc/{Module}/{Namespace}_{Module}.xml
/app/code/local/{Namespace}/{Module}/Block/Adminhtml/{Module}.php
/app/code/local/{Namespace}/{Module}/Block/Adminhtml/{Module}/Grid.php
/app/code/local/{Namespace}/{Module}/Block/Adminhtml/{Module}.php
/app/code/local/{Namespace}/{Module}/controllers/{Module}Controller.php
/app/code/local/{Namespace}/{Module}/etc/config.xml
/app/code/local/{Namespace}/{Module}/etc/adminhtml.xml
/app/code/local/{Namespace}/{Module}/Helper/Data.php
/app/code/local/{Namespace}/{Module}/Model/{Module}.php
/app/code/design/adminhtml/default/default/layout/{module}.xml

Start by creating the directory tree and then create the file config.xml. Populate with the following:

<?xml version="1.0"?>
<config>
    <modules>
        <{Namespace}_{Module}>
            <version>1.0</version>
        </{Namespace}_{Module}>
    </modules>
    <admin>
        <routers>
            <{module}>
                <use>admin</use>
                <args>
                    <module>{Namespace}_{Module}</module>
                    <frontName>{module}</frontName>
                </args>
            </{module}>
        </routers>
    </admin>
    <global>
        <blocks>
            <{module}>
                <class>{Namespace}_{Module}_Block</class>
            </{module}>
        </blocks>
        <helpers>
            <{module}>
                <class>{Namespace}_{Module}_Helper</class>
            </{module}>
        </helpers>
        <models>
            <{module}>
                <class>{Namespace}_{Module}_Model</class>
            </{module}>
        </models>
    </global>
</config>

Resources:
http://www.summasolutions.net/blogposts/custom-reports-magento
http://www.codegento.com/2011/03/creating-custom-magento-reports/