Follow by Email

Friday, July 29, 2011

Show subcategory in a category page

If you're comfortable editing your theme, this code snippet will bring you a list of all sub-categories of the current category (from the session, so this should work anywhere in your theme). I typically use this in app/design/frontend/default/*theme_name*/template/catalog/category/view.phtml

= $this->getCurrentCategory();
= Mage::getModel('catalog/category')->getCategories($_category->entity_id);
= Mage::helper('catalog/category');

<?foreach ($collection as $cat):?>
<?php if($_category->getIsActive()):?>
= Mage::getModel('catalog/category')->load($cat->getId());
= $cur_category->getImageUrl();  
                                <a href="
<?php echo $helper->getCategoryUrl($cat);?>">
                                     <img src="
<?php echo $_img?>" title="$cat->getName()"/>
<cite><?php echo $cat->getName();?></cite>
<?php endif?>
<?php endforeach;?>

Wednesday, July 27, 2011

Magento form validation from js

I have work on Contact us page in magento. I have add some extra field in the contact us Country, Subject etc.
If you want to make the field mandatory then must give the id name same with name and add class="input-text required-entry" then the field automatically validate from the js file.

Monday, July 25, 2011

Change category page layout

Generally category page in magento lies in 3 columns. if you want to change it then you have to do a simple thing. just go to the "catalog.xml" in your "layout" folder and add the following code

<reference name="root">

<action method="setTemplate"><template>page/2columns-left.phtml</template> </action>


in the line 81 under
<catalog_category_default translate="label">

<label>Catalog Category (Non-Anchor)</label>

Friday, July 22, 2011

Magento: Display Categories in Sidebar

Magento: Display Categories in Sidebar

It seems my posts lately are always in relation to solving a problem or answering a question for someone else. If you’re looking for a way to display categories in the sidebar, change category display, or create a category menu then this post is probably for you.

Creating the Block

The first thing you need to do is create a block in your layout. Navigate to /app/design/frontend/default/default/layout/catalog.xml

The first thing in your layout is a definition of the default layout noted by the comment “Default layout, loads most of the pages” depending on where you want to put your category nav (right sidebar, left sidebar, footer, etc) you’ll need to define the block a little differently. I’m going to do it with the left sidebar so you see what’s going on.

<reference name="left"> 
<block type="catalog/navigation" name="catalog.leftnav"
template="catalog/navigation/left_nav.phtml" />

Okay, so what i did was locate the left sidebar which is referenced simply as “left” inside those tags i define my block type and template. The next thing you’ll want to do is create that template file, note that i defined it within /app/design/frontend/default/default/template/catalog/navigation/left_nav.phtml so i will need to create that file.

Creating the Template

Once I’ve created the file, it’s time to put in my code to populate my links automatically of all my categories:

<div class="block">
<ul id="nav_category" class="nav_category">
<?php foreach ($this->getStoreCategories() as $_category): ?>
<?php echo $this->drawItem($_category) ?>
<?php endforeach ?>
<?php echo $this->getChildHtml('topLeftLinks') ?>

If you want to take this a step further, you can target subcategories based on current page with this little script

<?php  $obj = new Mage_Catalog_Block_Navigation();
$store_cats = $obj->getStoreCategories();
$current_cat = $obj->getCurrentCategory();
$current_cat = (is_object($current_cat) ? $current_cat->getName() : '');
foreach ($store_cats as $cat) {
if ($cat->getName() == $current_cat) {
echo '<li class="current"><a href="'.$this->getCategoryUrl($cat).'">'.$cat->getName()."</a>\n<ul>\n";
foreach ($obj->getCurrentChildCategories() as $subcat)
echo '<li><a href="'.$this->getCategoryUrl($subcat).'">'.$subcat->getName()."</a></li>\n";
echo "</ul>\n</li>\n";
} else {
echo '<li><a href="'.$this->getCategoryUrl($cat).'">'.$cat->getName()."</a></li>\n";

Thursday, July 21, 2011

Wednesday, July 13, 2011

How to show all product in a category page

In the magento 1.5 if you want to see all the product in a category in the same page then go to the
find this line near line 228
// we need to set pagination only if passed value integer and more that 0
$limit = (int)$this->getLimit();

now chenge it
$limit = 0;

and it will work.

Saturday, July 9, 2011

Create New category via soap api

In magento 1.5 it's very easy to create a category via soap api

$proxy = new SoapClient('http://magentosite/api/soap/?wsdl');

$sessionId = $proxy->login('apiuser', 'apikey');

$newCategoryId = $proxy->call($sessionId,'category.create',array(3,array('name'=>'New openerp','is_active'=>1,'include_in_menu'=>2,'available_sort_by'=>'position','default_sort_by'=>'position')) );

//where 3 is the parent category

Friday, July 8, 2011

How to get newsletter block in the footer

I am using magento 1.5+. To get the newsletter block in footer open
and pest this code

after this line
the block will come
have fun...

Thursday, July 7, 2011

How to add group in register form

in magento 1.5+ go to the
add following code in the page

<div class="input-box">

<label for="group_id" class="required"><?php echo $this->__('Group') ?><em>*</em></label><br/>

<select name="group_id" id="group_id" title="<?php echo $this->__('Group') ?>" class="validate-group required-entry input-text" />

<?php $groups = Mage::helper('customer')->getGroups()->toOptionArray(); ?>

<?php foreach($groups as $group){ ?>

<option value="<?php print $group['value'] ?>"><?php print $group['label'] ?></option>

<?php } ?>


<br /><p class="required" style="float:left;">Retailer group require admin authentication </p>


also change some code in app\code\core\Mage\Customer\controllers\AccountController.php

now replace $customer->getGroupId(); with


How to Setup a Multiple Currency Magento

How to Setup a Dual Currency Magento Shop

Login as admin and select System->Configuration, then select ’Currency Setup’ from GENERAL section,
then select Base currency, Default display currency, allowed currencies (press Control Key and Click the needed currencies) and ’Save Config’


Now come to "System->Manage Currencies’ menu


Click in Import currencies to load the exchange rate(s).


You are done. Visit the frontend and reload (you may need to refresh your cache) to see the drop down added to your product pages.