Thứ Ba, 27 tháng 7, 2010

How to see all category and subcategory menu in Magento

By default there is a top.phtml file in magento which show all category and subcategory .To modify menu display style it needs to modify in core file whcih will create problem to Update magento in future,So without touching the core file we can access all category and subcategory in magento.

For that we will write the code in top.phtml file



<?php foreach ($this->getStoreCategories() as $_category): ?>

<li>

<a href="<?php echo $this->getCategoryUrl($_category) ?>"><?php echo $this->htmlEscape($_category->getName()) ?></a>

<?php

$_catid=$_category->getId();

$category = Mage::getModel('catalog/category')->load($_catid);

$subcategory = $category->getAllChildren(true);

array_shift($subcategory);

if($subcategory!=null)

{

echo '<ul>';

foreach ($subcategory as $sub)

{

$sub1 = Mage::getModel('catalog/category')->load( $sub);?>

<li><a href="<?php echo $sub1->getUrl();?>"><span>

<?php echo $sub1->getName();

echo '</span></a></li>';

}?>



</ul>

<?php }?>



</li>

<?php endforeach ?>

Thứ Ba, 20 tháng 7, 2010

Get Add to cart button url in Magento

<input type="button" title="<?php echo $this->__('Add to Cart') ?>" class="addtocart" onclick="setLocation('<?php echo Mage::getUrl('checkout/cart/add', array('product'=>$row['product_id'],'qty'=>1)) ?>')" />

Thứ Hai, 21 tháng 6, 2010

Refresh page Using Javascript

we can Refresh a page Using Meta tag and javascript

By Meta tag

<meta http-equiv="refresh" content="600">


By Javascript

<a href="javascript:location.reload(true)">Refresh this page</a>




Click here to Refresh this page

How to Get Current Category in Magento

There are Many way to get Current category in magento

I am showing here two way

If you wish to check the current category in everypage(including Homepage as default category is 2) then you can write these code
$_cat = new Mage_Catalog_Block_Navigation();

$curent_cat = $_cat->getCurrentCategory();

$curent_cat_id = $curent_cat->getId();


$category = Mage::registry('current_category')->getName();


By the Help of registry()function of magento we can get the Current category ,For get name of that category we can use getName() function .If you need the Id then write getId() instead of getName();

Thứ Hai, 7 tháng 6, 2010

How to Use Custom Font By CSS

Most of the programmer use Machine font like Verdana, Aria, Tahoma, Times New Roman, Georgia, Trebuchet MS etc...This is because Every Operating system have this font. But They never use other font Like "OCR A Extended" , "Tempus Sans ITC" etc. If anybody wants to use these fonts then they needs to paste this font into the Server, And by css they can use that font into their website.

First paste the font into your website with proper location/path. e.g :- I have paste "OCR A Extended.ttf" file into a font folder then I wrote my css like the example given below.


@font-face {
font-family: OCR;
src: url(../fonts/OCR A Extended.ttf); /* For IE */
src: url(../fonts/OCR A Extended.ttf) format("opentype");
/* For non-IE */
}



body{font-family:OCR;}





You can change URL/path according to your website . Now you can see the effect in every Operating System

Thứ Bảy, 29 tháng 5, 2010

Enable Template Path Hints in Magento

Template Path Hints is the one of the most Use full Feature in Magento for the Magento Developer and Designer .It Helps to show the Phtml file's path.For example:- if you want to Modify header of a Magento template then Template Path Hints will help you to find the actual location where the Phtml file located. To show the Template Path Hints you need to
log in to the admin panel of your Magento site
Go to System tab ->From the drop down select Configuration
select Main website from the left top Current Configuration Scope
scroll down towards footer there you will find Developers -> Click on it and again scroll up to wards Header.
Expand the Debug Tab
Set Template Path Hints to Yes. Now got to your Frontend and refresh your page You will see all the path hints of your template

Thứ Ba, 11 tháng 5, 2010

How to add Javascript or Css file into Magento

By default there already some css and Javascript file included in the page.xml. If you want to add some more new css file then write

<action method="addCss"><stylesheet> css/Yourcss.css </stylesheet> </action>


into the page.xml which is inside Your app/design/Frontend/base/default/layout/Page.xml (in Magento 1.4.0.0 or Higher version of Magento).
If you want to add a javascript then you can directly write that code into your header.Phtml file which is in the app/design/frontend/base/default/template/page/html/header.phtml .Open the file and write

<script type="text/javascript" src="<?php echo $this->getSkinUrl('js/yourjs.js')?>"></script>

and upload/paste your js into Skin/frontend/default/default/js Folder.