8/28/2010

Change default Home page url to any page url in Magento

To change default index page of magento any cms page or any page like login page is quite easy .To do so you need to login to the admin panel then goto System -> Configuration , then click on web tab from the right side tab.Now click on Default Pages tab and change the Default web url as per your required Url.Here is one example where I have changed my Homepage url to Login page Url


Change default Home page url to any page url in Magento

8/26/2010

How to find third highest salary from a database table by sql or mysql

By this query you can find all possible(nth) highest salary starting from 2nd to nth.Just palace your find number salary in the place of `n` and you can get result. Here I have wrote the `n`th highest salary.


Select salary
from `tablename`
order by `columnname` desc
limit n-1,1;

Write 2 instead of n-1 to find the 3rd highest salary.Write 1 instead of n-1 to find the 2nd Highest salary.

How to Count all li elements in an ul tag by javascript

<script type="text/javascript">
var ulId = document.getElementById("ulid");
var totalLi = ulId.children.length;
alert(totalLi);
</script>

The list of the li in ul tag example is


<ul id="ulid">
<li>Item1</li>
<li>Item2</li>
<li>Item3</li>
<li>Item4</li>
</ul>

How to get parent category Id in Magento

To get Parent Category Id you must know the current category Id, for that you need to write
<?php
$_cat = new Mage_Catalog_Block_Navigation();
$curent_cat = $_cat->getCurrentCategory();
$curent_cat_id = $curent_cat->getId();?>

Now you can get Parent Category Id.
write the code given below to get the Id
<?php $parentId=Mage::getModel('catalog/category')->load($curent_cat_id)->getParentId();
echo $parentId; // $parentId will print your current category's parent Id
?>

How to change logo and alter logo text in Magento

There is 2 way to change logo in Magento
1) From Admin panel
2) From core file

To change logo of magento from admin panel you need to login to admin panel . Then go to System -> Configuration -> Design
Then click on Header tab to change the logo src (source ) to your respective filename or path. There also you can change logo alt (alternet) text


TO change logo from core file you need to go app/code/core/Mage/Page/config.xml. There you can change <logo_src> to your respective file name/path. There you can change logo alt text from <logo_alt> tag.

7/27/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 ?>

7/20/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)) ?>')" />

6/21/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();

6/07/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