Conditional Statement (if-else) on Store View and Website View in Magento

Magento is one of the most powerful e-commerce platform to manage your multiple website or multiple store, yet it has a very complex programming structure. I believe you have successfully setup your multi-store in an only one Magento folder. Sometime it isn’t necessary to create a child theme for your theme. You may prefer to do little programming like conditional statement. So let’s get started.

If you are planning to do a tweak in your .phtml theme file e.g. file path ~/yourtheme/default/template/page/html/head.phtml

..and do a conditional statement to display something according to either Store view or website view.

Store View

Get Store ID

<?php if (Mage::app()->getStore()->getId() == 'yourStoreID'){ ?>

     //Insert your HTML or JS Code Here

<?php } else { ?>

     //insert your HTML or JS Code Here

<?php } ?>

Or Get Store Code

<?php if (Mage::app()->getStore()->getCode() == 'yourStoreCode'){ ?>

     //HTML or JS Code Here

<?php } else { ?>

     //HTML or JS Code Here

<?php } ?>

Website View

Get Website ID

<?php if (Mage::app()->getWebsite()->getId() == 'yourWebsiteID'){ ?>

     //HTML or JS Code Here

<?php } else { ?>

     //HTML or JS Code Here

<?php } ?>

Or Get Website Code

<?php if (Mage::app()->getWebsite()->getCode() == 'yourWebsiteCode){ ?>

     //HTML or JS Code Here

<?php } else { ?>

     //HTML or JS Code Here

<?php } ?>

To get your Store Code
From Dashboard, go to System > Manage Stores
Under ‘Store View Name’ column, click your store name e.g. ‘Store1Name’
Get the store value in ‘Code*’ field
store code

To get your Store Code
From Dashboard, go to System > Manage Stores
Under ‘Website Name’ column, click your website name e.g. Store1Website
Get the website value in ‘Code*’ field
website code

Enjoy coding!

Conditional Statement (if-else) on Store View and Website View in Magento4.00/5 (80.00%) 3 votes
About

Elvin is one of the contributors of InnoveDesigns.com. He has been creating Wordpress Plugins, Magento Extensions, & Mobile Applications. If you find this article useful, please Follow him on .

Published under Magento, Web Development Guide