How to add log in your OpenCart Module

If, you want to add ‘logging’ feature to your module, include the global $log object like this

function myFunc() {
global $log;
$log->write('My log message');

This you can do in both the catalog and admin sections.
The logged message can be seen in the [opencart path]/systems/log/error.txt file

Its good to also note that all PHP related messages generated in OpenCart are also logged in this file.

How show more order statuses on the admin order details page

As of 1.4.2 it is deprecated to define order statues and states via config.xml. Then, how will you get more order statuses in the admin order details page?

Consider for example you have an order in ‘Pending Payment’ state and you want to change it to ‘Processing’. If, you go to the order details page in the admin you will find only one option in the order status drop down (which is ‘Pending Payment’ itself!)
What if you want to show ‘Processing’ too in the drop down?
You will need to make changes in the Magento sales_order_status_state table like this:

INSERT INTO `sales_order_status_state` (`status`, `state`, `is_default`) VALUES ('processing', 'pending_payment', '0');

[EDIT] Just for your info:
Before 1.4.2 you would need to override the Mage/Sales/etc/config.xml file and modify the <global><sales><order><states> section to look like this:

				<pending_payment translate="label">
					<label>Pending Payment</label>
						<pending_payment default="1"/>
						<processing default="0"/>

How to add static blocks to a CMS page

You have created a static block and now you want to add it to your CMS page.
You can do it in 2 ways. Assume you have created a block called sch_myblock:

1. CMS Page “Content” tab:
// In the CMS page “content” you can include a custom static block like this

{{block type="cms/block" block_id="sch_myblock" template="cms/content.phtml"}}

2. CMS Page “Design” tab:
// In the “Page layout” section you can add a custom block like this

// In the "Page layout" section you can add a custom block like this
<reference name="left">
	<block type="cms/block" name="sch_myblock" before="-">
		<action method="setBlockId"><block_id>sch_myblock</block_id></action>

How to change Magento admin url

By default Magento Admin Url is:
http://[your magento shop]/admin

But, what if you do not want to use admin in the URL? For example, you want your admin URL to look like this:
http://[your magento shop]/shopadmin

If, you check your files via FTP you will not see a folder called admin. So, how do you do it?
Open app/etc/local.xml – you will find a section like this:


The name that you enter in the “frontend” tag is the name that will be used to view the admin.
In this example, the Magento admin URL will be
http://[the magento shop]/mybiz

Magento controller, action and what happens when you browse a URL

Assuming you know how to create a custom module, consider a case where you need to create a URL for your module. Follow these steps:

In your module’s config.xml file:

		<schurl> --> name that will used in the URL
			<use>standard</use>  ---> standard means its a frontend url; admin will mean it is a backend url
				<module>Mage_Schogini</module>  ---> which is the module to be used
				<frontName>schurl</frontName>   ---> name that will used in the URL

Create a controller file TestController.php in your module’s controller folder like this (as you may have guessed, my modules name is Schogini):

class Mage_Schogini_TestController extends Mage_Core_Controller_Front_Action
	public function showmsgAction()
		echo 'Here';

This is what happens when you browse this URL

  • schurl tells that the controller to check is Mage_Schogini (the name that is specified in the config file in the section: args > module)
  • test tells that controllers/TestController.php file must be checked
  • showmsg tells that showmsgAction() method must be called.

Hence, it will look for the method showmsg() inside the Mage_Schogini_TestController class

Magento – Please enter a valid credit card verification number – message

If, you get a message like this:  “Please enter a valid credit card verification number.” every time you enable “CVV check” in your payment gateway, and you are sure that your payment module settings are correct and your card details are valid then, its most likely that the message is not coming from your payment module.

Instead it could be that the control is not reaching the payment module at all and the message is coming from this Magento file:
app/code/core/Mage/Payment/Model/Method/Cc.php line #150, validate credit card verification number section.

Why is this happening? Does this error occur for ‘Saved CC’ payment method too (it is the default card payment method got with Magento)?

Well, one reason that I found is – custom checkout module. Are you using any custom checkout module? If yes, then disable it and try the normal Magento one page checkout. The chances are all will work fine. I have noticed that some custom checkout modules fail to send the CVV number back to the code – hence, Magento will catch it and throw back the error – the payment module is nowhere in the picture yet.

So, before you panic that your card details are invalid or your Payment Gateway or payment module is not working, confirm that it is not your custom checkout module that is the culprit.

Intro to Themes

A theme is a combination of files which are responsible for the visual output.

What files form the theme ?

Magento themes are split into two directories.  The files are separated into “browser accessible” (such as image and Javascripts) and those that can be hidden from it for security reasons.

  • Directory 1: app/design/frontend/default/default/ — This directory contains the layout, translation (locale) and template materials.
  • Directory 2: skin/frontend/default/default/ — This directory contains the images, CSS and block-specific Javascripts.

So a theme consists of the following files :

Layout (located in app/design/frontend/your_interface/your_theme/layout/)
These are basic XML files that define block structure for different pages.

Templates (located in app/design/frontend/your_interface/your_theme/template/)
These are PHTML files that contain (X)HTML markups and any necessary PHP tags to create logic for visual presentation.

Locale (located in app/design/frontend/your_interface/your_theme/locale/)
Theses are simple text documents organized on a per language basis that contain translations for store copy.

Skins (located in skin/frontend/your_interface/your_theme/)
These are block-specific Javascript and CSS and image files that compliment your (X)HTML.

Hierarchy of themes:

Magento has a very powerful theme concept. For instance, you can use a default theme which comes with Magento and a new one of your own side by side. That new individual theme only contains files which differ from the default theme. Thus it forms a hierarchy of themes.

For example If you simply want to move the mini cart from the left sidebar to the right sidebar you just copy the required file from “default” to your new theme directory and adjust some code. Magento first loads all files from your new theme and then falls back to the next theme lower in hierarchy (in this case “default”) and requires all missing files from that theme.

Doing so, Magento conserves the ability to be upgraded. With every upgrade,  files in your default theme are getting overwritten. The original files are protected this way.

What are Blocks ?

In Magento we work with structural blocks and content blocks. Structural blocks represent the basic structure of a page. Usually we have structural blocks like header, left sidebar, middle content, right sidebar and footer. We can assign content blocks like category list, navigation, search bar, callout etc. to a certain structural block.


Content blocks are assigned to structural blocks with the help of layout. Layout is build with XML files and can be found under app/design/frontend/default/default/layout. This way you can reuse earlier created templates, such as the mini cart module on the sidebar, on different pages by simply calling them within a layout xml file.


In this case we are adding the content block ‘cart_sidebar’ (shopping cart) to the structural block ‘left’.

Template Path Hints:

You can see info about the template that a block uses by turning on Template Path Hints. Here are the steps to turn on template path hints. Make sure you disable your cache by going to System->Cache Management.

Open admin page and go to System->Configuration. Then Select Developer on the left sidebar. Also select Main Website from the Current Config Scope Drop Down.  Next Open the debug drop down and set template hints to yes.


The result will be as follows. Each content block will be outlined and labeled with the location of template file which is used to design that block.


Change best selling products

Default Magento installtion homepage has a section ’Best Selling Products’. You want to put your products to appear instead…follow these steps:

  1. Login as Admin -> CMS -> Manage Pages
  2. Edit the ’Homepage’ page
  3. In the ’Content’ textarea you will find the ’Best Selling Products’ section like this
    Technorati Tags: ,,

    The bold section is

    <div class="box best-selling">
      <h3>Best Selling Products</h3>
      <table border="0" cellspacing="0">
          <tr class="odd">
            <td><a href="{{store url=""}}furniture/living-room/gayatri-test1.html"><img class="product-img" src="{{skin url=’images/media/vishi.jpg’}}" border="0" width="95" /></a>
              <div class="product-description">
                <><a href="{{store url=""}}furniture/living-room/gayatri-test1.html">Gayatri Test Product</a></>
                <> See all <a href="{{store url=""}}furniture/living-room/">Living Room</a> </>
            <td><a href="{{store url=""}}nine-west-women--lucero-pump.html"><img class="product-img" src="{{skin url=’images/media/best_selling_img02.jpg’}}" border="0" width="95" /></a>
              <div class="product-description">
                <><a href="{{store url=""}}nine-west-women--lucero-pump.html">Nine West Women’s Lucero Pump</a></>
                <> See all <a href="{{store url=""}}apparel/shoes">Shoes</a> </>
          <tr class="even">
            <td><a href="{{store url=""}}olympus-stylus-750-7-1mp-digital-camera.html"><img class="product-img" src="{{skin url=’images/media/best_selling_img03.jpg’}}" border="0" width="95" /></a>
              <div class="product-description">
                <> <a href="{{store url=""}}olympus-stylus-750-7-1mp-digital-camera.html">Olympus Stylus 750 7.1MP Digital Camera</a> </>
                <> See all <a href="{{store url=""}}electronics/cameras/digital-cameras">Digital Cameras</a> </>
            <td><a href="{{store url=""}}acer-ferrari-3200-notebook-computer-pc.html"><img class="product-img" src="{{skin url=’images/media/best_selling_img04.jpg’}}" border="0" width="95" /></a>
              <div class="product-description">
                <> <a href="{{store url=""}}acer-ferrari-3200-notebook-computer-pc.html">Acer Ferrari 3200 Notebook Computer PC</a> </>
                <> See all <a href="{{store url=""}}electronics/computers/laptops">Laptops</a> </>
          <tr class="odd">
            <td><a href="{{store url=""}}asics-men--gel-kayano-xii.html"><img class="product-img" src="{{skin url=’images/media/best_selling_img05.jpg’}}" border="0" width="95" /></a>
              <div class="product-description">
                <><a href="{{store url=""}}asics-men--gel-kayano-xii.html">ASICS® Men’s GEL-Kayano® XII</a></>
                <>See all <a href="{{store url=""}}apparel/shoes">Shoes</a></>
            <td><a href="{{store url=""}}coalesce-functioning-on-impatience-t-shirt.html"><img class="product-img" src="{{skin url=’images/media/best_selling_img06.jpg’}}" border="0" width="95" /></a>
              <div class="product-description">
                <> <a href="{{store url=""}}coalesce-functioning-on-impatience-t-shirt.html">Coalesce: Functioning On Impatience T-Shirt</a> </>
                <> See all <a href="{{store url=""}}apparel/shirts">Shirts</a> </>