Magento tips

The most comprehensive open-source shopping cart script, get all the tips you need to make a better Magento site.

Custom Add to Cart button on CMS page
Published on December 24th, 2010

Magento provides an easy way of adding products to shopping cart via query string. To create a simple add to cart button on any magento’s CMS page open it in WYSIWYG editor and the following HTML to its contents: <p><button onclick=”location.href =’{{config path=”web/unsecure/base_url”}}/checkout/cart/add?product=1&qty=1′”>Buy It Now</button></p>

Change Admin URL
Published on December 24th, 2010

By default magento admin panel is accessible via http://example.com/admin URL. For security reasons, you may want to change it into smth like http://example.com/sighO_0 In order to do that edit magento’s app/etc/local.xml file and replace <frontName><![CDATA[admin]]></frontName>

How to Build Magento URL for Admin Pages
Published on December 23rd, 2010

If you’re developing a custom module with some admin pages, most likely you’ll face a problem of creatig a URL for some admin area. In order to accomplish that adminhtml helper should be used. Here’s the example: <?php echo Mage::helper(‘adminhtml’)->getUrl(‘adminmodule/controller/action’); ?>

Add JS to All Pages
Published on December 23rd, 2010

Magento has various locations for its javascipt files and there are several ways to add them to your page. In order to add js to all your pages use javascript inclusion instruction within <default> handle in your layout file. Here are some examples: The layout below will add js/mydir/myscript.js javascript to all pages. <default> <action method=”addJs”><script>mydir/myscript.js</script></action> </default>

How to Enable Debug Mode
Published on December 23rd, 2010

It’s very handy to enable debug mode at developement stage. In order to do that you have to modify magento’s index.php file. Change lines if (isset($_SERVER['MAGE_IS_DEVELOPER_MODE'])) { Mage::setIsDeveloperMode(true); } to

Debug Your Layout
Published on December 23rd, 2010

So, you’ve created your module, added layout files and templates, but they are not showing up on front? You can see what’s going on with your layouts using Mage::log() method in your controller. The code below would log loaded layout handles and compiled layout update string into var/log/layout.log file. Don’t forget to enable debug mode in your index.php, see how to do it. public function testAction() { $this->loadLayout(); // …