Building a Magento Admin Module

Have you ever wanted to build a custom module for the Magento admin panel? Today I am going to share this information hoping you will find this post useful!

Creating the Module Folder Structure

Lets start by creating the following folders:

app/code/community/Toto/ImportXml/etc
app/code/community/Toto/ImportXml/controllers
app/code/community/Toto/ImportXml/Helper

Building the Module

Within the ‘etc’ folder create a file called config.xml and paste in the following code:

configxml

Next create a file called adminhtml.xml within the ‘etc’ folder and paste in the following:

adminhtml

We need to tell Magento to load our module and to do this we need to create a file within /app/etc/modules. I called my file Toto_ImportXml.xml and it contained the below XML code:

xml

Now if you refresh your Magento admin panel, you should notice a new tab called ‘Tofu & Tomato Commerce’. However, if you click on it you will be given a PHP error saying that Magento can’t find a helper class. This is because within adminhtml.xml we told Magento that the tab is associated with the module ‘importxml’ and by default Magento looks for a helper file called Data.php.

module=”importxml”

In the config file we also declared the helper class within the global node.

globalhelper

To fix this problem we need to create a file called Data.php with the Helper folder (/app/code/community/ Toto/ImportXml/ Helper/Data.php). This will be an empty class for the time being but it will fix the warning we are currently getting. Paste the following into Data.php:

helper

Note: The class name needs to be file path structure to Helper/Data.php.

The final stage is to add the controller. This will route the user to the method specified within adminhtml.xml. For example lets take the following:

<action>greenmodule/index/index</action>

Magento will look in the module ‘Greenmodule’ for an index controller with the method called indexAction. So lets create a php file called ‘IndexController.php’ within the controllers folder (/app/code/community/Toto/ImportXml/controllers/ IndexController.php). Paste in the below PHP code:

controller

The above method simply creates a block with a the heading ‘Tofu & Tomato Commerce’ by using Magento factory methods. Refresh your browser and you click on the custom menu tab – you should now see a brand new page with the h1 tag.

Note: You may have to clear your magento cache or log out and log back in for the new page to show. This has caught me out many times.

tofu&tomato-commerce

Enjoy!

Magento: Get Bundled Items name / title by bundled product Id

This post is jut a small snippets that will help you to get all bundle items’ title.

Of course, I’m not sure how useful can it be as is, so if you need optimized version of it, you will need to play with it for a while. I tried to find it on google few days ago and I had no luck, so if anybody has better solution, please comment.

Here we go:

bundle products

Bundled Products, Magento will not recalculate the Price – Bundle.reloadPrice()

Hello, I’m Tofu, nice to see you again.

My client gave me a purchased Magento template and asked me to install and configure a new Magento store for him. The template was very clean and professional. However, there was an weird issue since it did not support the latest Magento version 1.9.

I created serveral bundle products just for testing purpose then I added or subjected items to the cart, the price did not change. I got js errors:

Uncaught ReferenceError: taxCalcMethod is not defined 
Uncaught TypeError: Cannot call method ‘reloadPrice’ of undefined

Finally, I figured out the problem. We will need to copy the following javascript snippets from BASE theme to our activated theme in
/app/design/frontend/default/YOUR_TEMPLATE/template/
/bundle/catalog
/product/view/type/bundle.phtml

bundle-magento-products

Enjoy!

[Magento] 503 error after installing extensions

Hello, I just installed Magento shopping cart, via host monster. Earlier in the day, I installed a bunch of extensions through Magento Connect Manager. When I went to go back to my Admin section, I got the 503 Error.

“Service Temporarily Unavailable
The server is temporarily unable to service your request due to maintenance downtime or capacity problems. Please try again later.”

maintenance-flag

I’ve seen this happen before after upgrading or installing extensions and in many of the cases it appeared to be that the maintenance.flag stuck. Check your Magento installation root folder, look for that file and then delete it.

maintenance.flag.solution

[Magento] How to place a product on sale or special in Magento?

When you go around some online shop, sometime you’ll see products with ribbon ‘Sales‘ or will see two price (1 for original price, 1 for new price) and something like that….

So how to do it in magento?

It’s very esay. I’ll explain step by step in this below:

1. Login to the Magento admin.
2. On the top menu go to ‘Catalog > Manage Products.
3. Click the product on the grid to edit.
4. On the left menu, click ‘Prices‘.
5. (If you only have one store skip this step) On the top left, select the appropriate Store from the drop down.
6. Enter the desired Sale price on the field ‘Special Price‘.
7. If applicable, assign a date range using the fields ‘Special Price From Date’ and ‘Special Price To Date‘.
8. Click Save.
9. On the top menu go to ‘System > Index Management‘.
10. Find “Product Prices” from the grid and hit ‘Reindex Data‘.
11. On the top menu go to ‘System > Cache Management‘.
12. Check the ‘Page Cache’ item, make sure the ‘Actions’ dropdown has a value of ‘Refresh‘, and click Submit.

That’s all.

[Magento] How to remove index.php from URLs?

Working with magento, sometime, you can see index.php appear in URLs of your website url. The index.php appears in your URLs because it is the file responsible for processing all requests to the system. In a URL such as http://example.com/index.php/template_group/template, the template_group/template segments are simply information passed to index.php and do not refer to actual files or folders in the server’s filesystem.

Actually, they are not good for SEO, bad for site structure and consistency, and then they’re even worse for a clean URL freak like me.

Let’s clean it…

1. Log-in to your Mangento administration area the go to ‘System -> Configuration -> Web‘.

2. Navigate to Unsecure’ and Secure’ tabs. Make sure the ‘Unsecure‘ and ‘Secure‘-‘Base Url‘ options have your domain name within it, and do not leave the forward slash off the end of the URL. Example: http://tofuandtomato.com/

3. While still on the ‘Web’ page, navigate to the ‘Search Engine Optimisation‘ tab and select ‘Yes‘ underneath the ‘Use Web Server Rewrites‘ option.

4. Navigate to ‘Secure‘ tab again (if not already on it) and select ‘Yes‘ on the ‘Use Secure URLs FrontEnd‘ option.

5. Now go to the root of Magento website folder and use this code for your .htaccess:

* If your Magento store is installed in root(public_html) , use this:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ – [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

** If your Magento store is installed in a subfolder (public_html/shop), use this:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /shop/
RewriteRule ^index\.php$ – [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /shop/index.php [L]
</IfModule>

Save the .htaccess and replace the original file (You need backup your original file before replacing).

6. Now go to ‘Cache Management‘ in Administration area to clear Cache.

You are done!

Let’s me know in the comments below if you use this or run into any issues.

[Tofu And Tomato] Magento 1.7 “Database server does not support InnoDB storage engine message”

I’m trying to re-install a cloned Magento 1.7 website on a local server using AMPPS. InnoDB is set as the default engine but it still shows me the message: Database server does not support InnoDB storage engine.

To sort out this issue:

Go To Line 59 of the file app/code/core/Mage/Install/Model/Installer/Db/Mysql4.php

Replace:

public function supportEngine()
{
    $variables  = $this->_getConnection()
        ->fetchPairs('SHOW VARIABLES');
    return (!isset($variables['have_innodb']) || $variables['have_innodb'] != 'YES') ? false : true;
}

With:

public function supportEngine()
{
    $variables  = $this->_getConnection()
        ->fetchPairs('SHOW ENGINES');
    return (isset($variables['InnoDB']) && $variables['InnoDB'] != 'NO');
}

Also see my screenshot:

magento1.7.inodb