Thursday, 5 June 2014

Magento – get Skin Url

This method return the path url of the current selected Skin.


<?php
 $this->getSkinUrl();
 ?>

How to View all modules system config.xml in Magento?

In Magento Config.xml file is used to setup the module details. We used to setup config.xml file in PackageName/ModuleName/etc/.
Magento collect all the config data from different modules and combine it all into a single file named config.xml.
To view this file simply paste this code in any controllers, run it and see the magic. A huge tree with lots of nodes.


<?php header('Content-Type: text/xml');
 //header('Content-Type: text/plain');
 echo $config = Mage::getConfig() ->loadModulesConfiguration('config.xml') ->getNode() ->asXML();
 exit();
 ?>

Magento – check if coupon code used:

Once on the Onepage Checkout page, I need to track if the customer has used any specific coupon code. This can be checked by the checkout session.
Use this code to hunt up the coupon code. This code will return the coupon code if used or empty result.


<?php
 $coupon_code = Mage::getSingleton('checkout/session')->getQuote()->getCouponCode();
 if($coupon_code){
      echo "coupon used";
       }
       else
       {
            echo "coupon not used";
             }
              ?>

Magento – Get base url inside controller:

Magento’s $this->getBaseUrl() method works inside template and blocks only but not in the controllers because it’s a Core_Block class method. To get the base url inside controller use instead this method.


<?php
 Mage::getUrl();
 ?>

Magento – view entire system config – system.xml :

In Magento modules, system.xml file is used to create admin configuration tabs and options. Magento’s great feature allows developers to create advanced configurable modules in a little time. At the run time Magento collects all the xml files and group them into a single file.
To view the system.xml file simply paste this code snippet in any controllers and run it. A large xml will be open.


<?php
 //header('Content-Type: text/plain');
  header('Content-Type: text/xml');
   echo $config = Mage::getConfig()
    ->loadModulesConfiguration('system.xml')
     ->getNode()
     ->asXML();
    exit();
    ?>

Magento – Add Remove top links using Layout.xml:

Removing or Adding top links in the header section of the theme is very easy via Layout.xml files. However we need to edit multiple files to accomplish this task like wishlist.xml, customer.xml, checkout.xml etc.
1. To Remove Wishlist link from top links
—————————————————————————–
Open the file /app/design/frontend/package/theme/layout/wishlist.xml and find the lines given below, simply comment these lines to remove the wishlist link.
?
1
2
3
4
5
6
<!--
<reference name="top.links"> 
   <block type="wishlist/links" name="wishlist_link"/>
    <action method="addLinkBlock"><blockName>wishlist_link</blockName></action>
 </reference>
-->
2. To remove My Account link
—————————————————————————————
Open the file /app/design/frontend/package/theme/layout/customer.xml and find the lines and comment these lines.
?
1
2
3
<!--<action method="addLink" translate="label title" module="customer"><label>My Account</label>
 <url helper="customer/getAccountUrl"/><title>My Account</title><prepare/><urlParams/> <position>10</position> </action>
-->
3. Add Home Link in top menu
—————————————————————————————-
Open the file /app/design/frontend/package/theme/layout/customer.xml and search the line
‘’
Under the ‘’ add these lines.
?
1
<action method="addLink" translate="label title" module="customer"> <label>Home</label><url helper="core/url/getHomeUrl"/><title>Home</title><prepare/><urlParams/> <position>10</position> </action>
4. To Remove or Add Checkout and My Cart link in top menu
———————————————————————————————
To show or hide the Checkout and My Cart link in the top links just comment or un-comment these lines in /app/design/frontend/package/theme/layout/checkout.xml file.
?
1
2
3
4
5
6
<?php
 //My Cart link
 <action method="addCartLink"></action>
  //Checkout link
  <action method="addCheckoutLink"></action>
  ?>

Magento – display root category products with filters

I had to display all the child categories products of the root category on a page with filtered navigation on the left column, but by default Magento does not display the root category products.
After some search and research I find the solution for this. It can be accomplished using Layout Update XML inside the CMS page. Not only layered nav but toolbar will also be displayed. For this we need to create a new CMS page or we can use any existing page where we want to display the products of the root category with filtered nav.
Follow steps:
1. Open Manage Category page in admin and choose the root category you want to display. Make sure that the category is Active and Is Anchor yes. Note down the category id.
2. Create a new CMS page, CMS > Pages > Add New Page or Edit any existing one where you want to display the products.
3. Fill the proper information in the required fields.
4. Under Design tab, paste the given code in the Page Layout > Layout Update XML textarea.
5. In the code find “category_id 3 category_id” and change your category id with 3. For example your category id is “2″ so it should be “category_id 2 category_id“.
6. Select the Layout 1, 2 or 3 columns whatever you want.
7. Note: I used reference name=”left” so layered nav will display only if 2columns with left bar is selected. If you want the right side column than change reference name=”left” to reference name=”right”.


<reference name="content">
     <block type="catalog/product_list"  name="product_list" template="catalog/product/list.phtml">
        <block type="catalog/product_list_toolbar" name="product_list_toolbar" template="catalog/product/list/toolbar.phtml">
            <block type="page/html_pager" name="product_list_toolbar_pager"/>
         </block>
         <action method="setCategoryId"><category_id>3</category_id></action>
        <action method="setToolbarBlockName"><name>product_list_toolbar</name></action>
     </block>
 </reference>
<reference name="left">
    <block type="catalog/layer_view" name="catalog.leftnav" after="currency" template="catalog/layer/view.phtml"/> </reference> 
 
Save the page. Refresh cache and visit the page using the URL assigned in the CMS page .