12/28/2010

how to get all products in magento

To get All products in magento Store not from a particular category or to get all products from default store in magento ,write the following code

<?php
Mage::getModel('catalog/product')->getCollection()->getData();
?>

12/16/2010

Search is not working in magento after Import product

I use Icecat module to Import data and near about 10,000 product I upload to my site,After uploading all product when I searched some product ,it didn't display any result, but when clicking on category showing that product. Then I just login to admin section of my site then goto -> System -> Index management. There I clicked on Catalog Search Index and Reindex data.Clear my Cache and It worked .

12/13/2010

How to Add Customer Group field while register in magento

It's default magento Features.You need to Edit 2 file. one is config.xml which resides in app/code/core/Mage/customer/etc/config.xml and other is Register.phtml which resides app/design/frontend/your_interface/Your_theme/template/customer/form/Register.phtml

Open Config.xml then goto line number near about 82 there add <group_id><create>1</create><update>1</update></group_id> under
<fieldsets>
<customer_account>

The code will be something like this

<fieldsets>
<customer_account>
<group_id><create>1</create><update>1</update></group_id>
</customer_account>
</fieldsets>

Now go to register.phtml and write the following code under the section where you wanrt to put.

<li>
<label for="customer_groups" class="required"><em>*</em><?php echo $this->__('Customer Groups') ?></label>
<select name="customer_groups" id="customer_groups" title="<?php echo $this->__('Customer Groups') ?>" class="validate-group required-entry input-text">
<?php $cu_groups = Mage::helper('customer')->getGroups()->toOptionArray(); ?>
<?php foreach($cu_groups as $cuGroups){ ?>
<option value="<?php echo $cuGroups['value'] ?>"><?php echo $cuGroups['label'] ?></option>
<?php } ?>
</select>
</li>

How to get all products from a particular category id in magento

While i was working on magento ,I had one requirement that how to get all product under a particular category id.I got the id of that particular category.Now I wrote the following code to get all product under that category id.

My category id is

<?php $catid=10 ;?>

I go all product by writing the below code

<?php
$category = new Mage_Catalog_Model_Category();
$category->load($catid); //My cat id is 10
$prodCollection = $category->getProductCollection();
foreach ($prodCollection as $product) {
$prdIds[] = $product->getId(); ///Store all th eproduct id in $prdIds array
}?>

Now you have all the product ids in $prdIds variable. Just click here to get all details of the product from a particular product id.You can get individual product id by the following loop.

<?php foreach($prdIds as $_prdIds){
$prodId=$_prdIds;
// In each loop one by one product id will be assign in between this loop Fetch all data of the particular product id.To get this click here
}?>

12/10/2010

How to show/hide template path hints of admin panel/backend in magento

To show template path hints in admin panel of magento you need to login to your phpmyadmin then run the following sql command

INSERT INTO core_config_data (scope, scope_id, path, value)
VALUES ('default', 0, 'dev/debug/template_hints', 1),
('default', 0, 'dev/debug/template_hints_blocks', 1)

To hide template path hints of admin panel or backed just run the top code by changing 1 to 0, then the template path hints will be hide.
You also can run the following sql command to hide template path hints.

INSERT INTO core_config_data (scope, scope_id, path, value)
VALUES ('default', 0, 'dev/debug/template_hints', 0),
('default', 0, 'dev/debug/template_hints_blocks', 0)

If you have already activated template path hints in admin panel or if you already run the top sql command once then No need to run this code again.Just go to core_config_data table of your php myadmin then change the value of `dev/debug/template_hints` rows to 0 or 1 to show or hide

12/09/2010

How to add a new custom login block in left/right side in magento

If you want to add login page in a statick block and want to place that in left side or right side then use the following code to make your login block and place it anywhere it will work.

<?php $custmlogin= new Mage_Customer_Block_Form_Login();?>
<form action="<?php echo $custmlogin->getPostActionUrl() ?>" method="post" id="login-form">
<ul class="topLogin">
<li>
<label for="email" class="required"><?php echo $this->__('Email Address') ?><em>*</em></label>
<input type="text" name="login[username]" value="<?php echo $this->htmlEscape($this->getUsername()) ?>" id="email" class="input-text required-entry validate-email" title="<?php echo $this->__('Email Address') ?>" />
</li>
<li>
<label for="pass" class="required"><?php echo $this->__('Password') ?><em>*</em></label>
<input type="password" name="login[password]" class="input-text required-entry validate-password" id="pass" title="<?php echo $this->__('Password') ?>" />
</li>
<li class="logInButton">
<label>&nbsp;</label>
<button type="submit" class="button" title="<?php echo $this->__('Login') ?>" name="send" id="send2"><span><?php echo $this->__('Login') ?></span></button>
</li>
</ul>
</form>

12/01/2010

How to merge all css files in magneto

If you wish to merge your all css file in magento you can do that by your magento Admin Panel. Log in to your magento admin panel the go to System->Congiguration. From the Current Configuration Scope: Select your Store view then click on Developer tab.Now click on Css Settings Tab .From the Merge CSS Files Drop down select yes to merge your css. Default No is selected . Now clear your browser cache and also refresh your magento cache.You all css file is merged Now.

Merge Css in Magento

How to redirect a page to a new page using javascript

To redirect a page we can use Javascript.

<script>
window.location.href="http://www.yourdomainname.com";
</script>

How to get Customer group id in magento

while i was working on one magento site one of my client wants to show a page only for wholesale customer.I knew How to assign customer group in magento But didn't know how to check it.I had to make this condition on Aw_blog module page, I opened that module and wrote the Following code and worked correctly.

First I check whether a Customer logged in or not ,then I fetch the value of customer group id to know in which cutomer group visited this page.In my website Wholesale customer Id was 2.

<?php
$login = Mage::getSingleton( 'customer/session' )->isLoggedIn(); //Check if User is Logged In
if($login)
{
$groupId = Mage::getSingleton('customer/session')->getCustomerGroupId(); //Get Customers Group ID
if($groupId == 2) //My wholesale customer id was 2 So I checked for 2. You can check according to your requirement
{
echo 'You are a wholesale Customer';
}
}
?>

11/30/2010

Magento 1.4.1.1 checkout problem

Magento 1.4.1.1 checkout problem with custom theme in magento 1.4.1.1 after selecting the payment method continue button doesnot work and onepage checkout become freezed.

If you are using Magento 1.4.1 or just upgraded any of your old Magento sites to the latest Magento version, then you may be getting a very weird error on your checkout page, that the checkout CONTINUE button on payment screen, either on Authorize.net or PayPal , just doesnt work.

The cause of this error is, Magento Team has introduced a new javascript file, which validates the credit card numbers, etc on the payment screen.

So, if you are using the default theme, then you should not get this problem.

But if you are using any custom theme, then you have to do some changes on your files.

Few symptoms of this problem is, you will see such errors,
Please verify the card with the issuer bank

or
Unable to initialize Express Checkout review.

or
CONTINUE button on Credit Card Form doesnt work.

I will give the instructions in details below, how to fix this issue :

Just add this js in your page.xml:

find <action method="addJs"><script>lib/ccard.js</script></action> under <block type="page/html_head" name="head" as="head">
replace it with
<action method="addJs"><script>prototype/prototype.js</script></action>
<action method="addJs" ifconfig="dev/js/deprecation"><script>prototype/deprecation.js</script></action>
<action method="addJs"><script>lib/ccard.js</script></action>

find <action method="addJs"><script>lib/ccard.js</script></action> under

<block type="page/html" name="root" output="toHtml" template="page/print.phtml">

<block type="page/html_head" name="head" as="head">

replace it with
<action method="addJs"><script>prototype/prototype.js</script></action>
<action method="addJs"><script>mage/translate.js</script></action>
<action method="addJs"><script>lib/ccard.js</script></action>

This must solve your complete problem .
But in case, its still not working, then here is another fix, which I got from another member from a forum,

I was experiencing the same issue: Nothing happens when you enter the credit card information and hit continue. After investigating with Firebug, it seemed that the method verifyCreditCard was not defined in validation.js.

You can fix this by pasting the following javascript code into validation.js under js->prototype in root folder:

/ Credit Card Validation Javascript
// copyright 12th May 2003, by Stephen Chapman, Felgall Pty Ltd

// You have permission to copy and use this javascript provided that
// the content of the script is not changed in any way.

function validateCreditCard(s) {
// remove non-numerics
var v = "0123456789";
var w = "";
for (i=0; i < s.length; i++) {
x = s.charAt(i);
if (v.indexOf(x,0) != -1)
w += x;
}
// validate number
j = w.length / 2;
k = Math.floor(j);
m = Math.ceil(j) - k;
c = 0;
for (i=0; i<k; i++) {
a = w.charAt(i*2+m) * 2;
c += a > 9 ? Math.floor(a/10 + a%10;) : a;
}
for (i=0; i<k+m; i++) c += w.charAt(i*2+1-m) * 1;
return (c%10; == 0);
}

Now you have to disable Mage_Centinel from backend system->configuration->advanced to make it work in mozilla and firefox.
But it will work on IE without disabling centinel module.

11/29/2010

How to redirect from one controller to product page in magento

While I was working on a module , it was required to redirect to a particular page,I tried to using header('lcoation')... .But it was not worked,So I searched in net How to redirect from a controller to product page, No solution Found .i tried myself and got a solution ,Which I am posting here.

In my controller i was sending the product Id and After doing some work I need to redirect to that product page.

I got this solution and worked.

$productId=$this->getRequest()->getParam('productId');
$obj = Mage::getModel('catalog/product');
$_product = $obj->load($productId);
$prdurl=$_product->getProductUrl();
$url=Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_LINK);
$_prdurl=explode($url,$prdurl);
$this->_redirect($_prdurl[1]);

How to Create Custom login Session in magento

If you are trying to make a custom login module in magento then Magento have a default functionality to make a Custom login session,Which destroy automattically after some time, if you will be Inactive for a moment.

Here I am showing you How to set login session value and How to get login session value.

$username=$this->getRequest()->getParam('username');
$password=$this->getRequest()->getParam('password');
$sql='select * from `tablename` where `username`= "'.$username.'" and `password`="'.$password.'" ';
$read = Mage::getSingleton('core/resource')->getConnection('core_read');
$row = $read->fetchAll($sql);
if($row)
{
Mage::getSingleton('core/session')->setlogin($row[0]['username']);
$this->_redirect('customer/account/index/');
}

Now You have Logged in to your account. If you want to retrive login Session value then you need to write the following code

$login = Mage::getSingleton('core/session')->getlogin();
if($login)
{
$this->loadLayout();
$this->renderLayout();
}

11/27/2010

How to and Where to change default welcome message text in Magento

It's very simple go to admin panel of your site then go to system->config. Then click on Design tab from the left sidebar. now click on the Header tab .

Here you can Change your default welcome message in magento. You also able to change your Logo Image Alternet text. Logo Source file also.

11/26/2010

How to change value of input text by jquery

I was searching in the internet for this solution ,But I couldn't find the proper solution.But I tried it myself so I think to share with all.

First i have created one input text with id inputText by this html code .
<input type="text" id="inputText" value="1" />


Now I wrote the following code in jquery to change value 1 to 5

$(document).ready(function(){
$('#inputText').val('5');
}

11/25/2010

How to show add Success message and add Error message in Magento

This is one of the easiest way to show Either Error message or Success message in magento for one time.If you are thinking to show an error message or success message one time when a page load then it is the best method to use in mganeto.

Show Error Message in frontend

$message = $this->__('Email Id Already Exist.');
Mage::getSingleton('core/session')->addError($message);

Show Success message in frontend

$message = $this->__('You have Register Successfully');
Mage::getSingleton('core/session')->addSuccess($message);

If you wish show Success message or Error Message in Admin html then you need to write your code little bit different

Show Error Message in Admin page

$message = $this->__('1 row has been updated successfully');
Mage::getSingleton('adminhtml/session')->addSuccess($message);

Show Success Message in Admin page

$message = $this->__('Email Id Already Exist.');
Mage::getSingleton(adminhtml/session')->addError($message);

11/22/2010

How to check if an user is logged in or log out in Magento

This is Magento default feature. In top.link you can find login or logout link.But if you want to put somewhere login/logout button then you need to check whether a user logged in or not by the code given below.

<?php
if ($this->helper('customer')->isLoggedIn() )
{
echo '<a href="<?php echo $this->getUrl('customer/account/login/');?>">Login</a>';
}
else
{
echo '<a href="<?php echo $this->getUrl('customer/account/logout/');?>">Logout</a>';
}
?>

How to overwrite cart controller add Action index Action in Magento

The Following Tutorial will Shows How to override cart controller Add Action or Index Action

First you need to give your Module name and Name_space ,I have taken Anjan as Namespace and override as Modulename
Now Create your module folders and files like below Instruction

1. Magento/app/code/local/Anjan/Override/etc/config.xml
2. Magento/app/code/local/Anjan/Override/controllers/CartController.php
3. Magento/app/etc/modules/Anjan_Override.xml

In config.xml Write the Foloowing code

<?xml version="1.0" encoding="UTF-8"?>
<config>
<modules>
<Anjan_Override> <!--Change Anjan To Your Module NameSpace and Override to Your Module name-->
<version>0.1.0</version>
</Anjan_Override>
</modules>
<frontend>
<routers>
<checkout>
<args>
<modules>
<Anjan_Override before="Mage_Checkout">Anjan_Override</Anjan_Override><!--Change Anjan To Your Module NameSpace and Override to Your Module name-->
</modules>
</args>
</checkout>
</routers>
</frontend>
</config>

In CartController.php write the following code

<?php
require_once 'Mage/Checkout/controllers/CartController.php';
class Anjan_Override_CartController extends Mage_Checkout_CartController
{
public function addAction()
{
echo 'I successfully Override Cart Controller';
parent::addAction();
}
public function indexAction()
{
echo 'I successfully Override Cart Controller';
parent::addAction();
}
}
?>

In Anjan_Override.xml write the following code

<?xml version="1.0" encoding="UTF-8"?>
<config>
<modules>
<Anjan_Override>
<active>true</active>
<codePool>local</codePool>
</Anjan_Override>
</modules>
</config>

Now upload these files into your server,refresh your cache , the click on Add to cart button you can see the message is displaying . You can use die() statement to make sure whether is overrides or not .

How to Get Product details Using Product Id in Magento

If you got the product id then you can get details of a product by using the following method in magento.

$obj = Mage::getModel('catalog/product');
$_product = $obj->load($product_id); // Enter your Product Id in $product_id
// get Product's name
echo $_product->getName();
//get product's short description
echo $_product->getShortDescription();
//get Product's Long Description
echo $_product->getDescription();
//get Product's Regular Price
echo $_product->getPrice();
//get Product's Special price
echo $_product->getSpecialPrice();
//get Product's Url
echo $_product->getProductUrl();
//get Product's image Url
echo $_product->getImageUrl();

11/18/2010

How to Make http to https in magento login page register page checkout page and admin panel

Https is an important part in magento as customer or user gain trust and it increase web site's search engines rank also. To make your login page, register page, checkout page and admin panel as https you need to install SSL certificate into your server first.After Successful installation do the following process .
Go to System->Config->Web
then Click on Secure tab.
Change your base url to https://www.yoursite.com [ Important : Write HTTPS in your base url otherwise it will not work]
Make Use Secure URLs in Frontend to Yes
Make Use Secure URLs in Admin to Yes.

Seethe Below screenshot
Make http to https in magento login page register page checkout page and admin panel
Then Save config Clear your cache, Now go to your frontend then click on login page you can see that your login page is changed to https.

How to Read all files name in a folder using php

Write the below code to read filse name from an particular folder.

function dirFiles($directry) {
$dir = dir($directry); //Open Directory
while (false!== ($file = $dir->read())) //Reads Directory
{
$extension = substr($file, strrpos($file, '.')); // Gets the File Extension
if($extension == ".xml" || $extension == ".csv" || $extension == ".php" |$extension == ".txt") // Extensions Allowed
$filesall[$file] = $file; // Store in Array
}
$dir->close(); // Close Directory
asort($filesall); // Sorts the Array
return $filesall;
}

$array = dirFiles('/home/your absolute directory/');

foreach ($array as $key => $file)
{
echo $file; // Display Images
echo '<br />';
}

How to Reset all Folder and File permission in magento

There is two way to Reset all Folder and File permission in magento.

1. By using SSH

a. find . -type f -exec chmod 644 {} \;
b. find . -type d -exec chmod 755 {} \;
c. chmod 550 pear

2. By Using Magneto clean Up Tool
a.Download the magento clean up tool .
b.Unzip magento-cleanup.php to the root directory where Magento is installed.
c.Browse to http://yourdomain.com/magento-cleanup.php

11/17/2010

How to Change admin default url in magento

It's very important to change default admin url in magento to save your website from hackers. For this you need to do little bit changes in your site.

1. Go to app/etc folder of your magento website and open local.xml
<admin>
<routers>
<adminhtml>
<args>
<frontName><![CDATA[admin]]></frontName>
</args>
</adminhtml>
</routers>
</admin>
Instead of admin Write your new url (e.g: magAdmin).

2. Now go to your system cahce which located under var folder. Rename or delete the Cache folder.Clear all session. Now It's done. Visit the site admin by typing the new admin path.

11/16/2010

How to change the Magento Email Templates

app\locale\en_US\template\email\ is the actual path where you can find all Email templates of magento. There are 20 html files .Edit Html file which you want,

11/13/2010

How to remove index.php from url in magento

Default All url of a Magento website shows index.php .For search engine indexing it's necessary to remove index.php from all url.Then You need to login to your madento admin panel.

Go to System-> Configuration > Web > Search Engine Optimization. Make Yes from Use Web Server Rewrites Drop Down.

Now goto your Cache Management page and refresh your Cache ,then index.php will remove from all url of your magento website

How to change category page layout in Magento

Default Category page layout is written in page.xml file which resides in app/design/frontend/default/your-theme/layout/. Open Page.xml then change line number 35 or find .
<default translate="label" module="page">
<label>All Pages</label>
<block type="page/html" name="root" output="toHtml" template="page/3columns.phtml">
Change default 3columns.phtml to 1Coloumn.phtml or 2columns-left/right.phtml .Then save and upload it .
Clear your cache to see the effects.
Note :: Changing all page layout doesn't effect other pages of magento it effects only the category page. So don't hesitate to change this.

11/12/2010

How to call a phtml file in magento cms page

You can't call a phtml file by writing php code in Magento admin panel as Magento admin panel doesn't support this. To call a PHTML write the folllowing code .

{{block type="core/template" name="a-name" template="cms/home.phtml"}}

inside template="" you can write your file path. and in name="" you can give proper and unique name , in type="" you can write your module directory also(e.g:- customer/account if you are calling login.phtml file).

One more way to call a phtml file. You can use your layout or xml file to do. For example i am going to attached home.phtml file which reside in cms folder of my thmeme template then I am writing the code given below

<reference name="content">
<block type="core/template" name="homepage" template="cms/homepage.phtml"/>
</reference>

How to Get skin url in magento admin panel cms page

In frontend to calll skin url we write
<?php echo $this->getSkinUrl('');?>
To call Skin Url in Magento admin panel you have to write
<img src="{{skin url='images/your-image-name'}}" alt="">
{{skin url='images/your-image-name'}}
You can write css/style.css to call style.css in your theme

How to Get store url in magento admin panel cms Page

In frontend to calll store url we write
<?php echo $this->getUrl('');?>
But in admin Panel we can't write php or echo like statement. So to call base Url in Magento CMS Page or store url you have to write like the code given below.
<a href="{{store url='index.php'}}">Home</a>
{{store url='index.php'}}
This the actually way to call store url in admin panel.
You can use your required link instead of index.php (e.g:- contacts to call Contact us page).

11/11/2010

How to Get value of a select box in JavaScript

If you are using Id to get a select box value then it's little bit easier . If you don't have id in your select box then you need to use name attribute to select the select box. I have used name tag to get the select box value.

<script type="text/javascript">
function slectBox()
{
var aa= document.form.selectBox.selectedIndex;
var ab= document.form.selectBox.options[aa].value;
alert(ab);
}
</script>

<form action="" name="form">
<select name="selectBox">
<option value="1">one</option>
<option value="2">Two</option>
</select>
<input type="button" onclick="slectBox()" value="clickme" />
</form>

This is the example how it works.try it

11/08/2010

Get Product price excluding Tax class in Magento

Normally in magento Price shown including Tax.But if you want to show Price Excluding Tax then you need to call the following helper class.


<?php echo $this->helper('checkout')->formatPrice($_product->getPrice())
// For Special Price write this
echo $this->helper('checkout')->formatPrice($_product->getSpecialPrice()) ?>

11/04/2010

get skin url, get js url, get media url, get store url ,get base url in magneto

These are the following methods to get Magento Base Url, Magento Skin Url, Magento Media Url, Magento Js Url.to get all write the following code

Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_LINK); or you can write $this->getUrl();
e.g:- http://yoursite.com/index.php/

Get Magento Media Url
Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA);
e.g:- http://yoursite.com/media/
Get Magento Skin Url

Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_SKIN); or you can write $this->getSkinUrl();
e.g:- http://yoursite.com/skin/

Get Magento Store Url
Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB);
e.g:- http://yoursite.com/

Get Magento Js Url
Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_JS);
http://www.yoursite.com/js

11/03/2010

How to find your blogger blogs sitemap Url

To find the location of your sitemap, use the following steps:

1. Open up your web browser, and type in your Blogger blog’s URL.
2. At the end of the URL add robots.txt.

For example, if the URL of your blog is http://myblog.blogspot.com, then enter http://myblog.blogspot.com/robots.txt
3. Some text should now be displayed in your browser. Look for a line that starts with Sitemap:. The URL after that label is the location of your sitemap.

Using the example above, the line would look like:

Sitemap: http://myblog.blogspot.com/feeds/posts/default?orderby=updated
4. Back in Google’s Webmaster Tools, the domain name part of the URL would already be included, so you would just need to specify the feeds/posts/default?orderby=updated portion of the sitemap URL. If other sites are able to accept a sitemap, then you may need to include the entire URL

11/01/2010

How to Show static block only on homepage in magento

If you are in header.phtml file then you can call $this->getIsHomepage();

But if you are not there then you must have to create instance of Mage_Page_Block_Html_Header(); then write the following code to check homepage

<?php
$ref = new Mage_Page_Block_Html_Header();
if($ref->getIsHomePage()){ ?>
<div class="homepage"><?php echo $this->getLayout()->createBlock('cms/block')->setBlockId('Your_StaticBlock_Id')->toHtml();?></div>
<?php
}
?>

10/28/2010

How to add or install a new language in Magento

Installing a second language in magento or Adding a new language in Magento is very easy.

I am describing it with an example.Installing the French language
For this I search extension in magento Commerce for France language and copied the extension (magento-community/Locale_Mage_community_fr_FR). Now I logged in to magento connect manager of my website and installed this extension. Then I Create 2 store view one is for English and another one is for French .Be sure to use en in the code field for English Store view and Fr for France store view. Now go to System->configuration, from Current Configuration Scope: select your storeview (i select France) .then click on Locale Options Tab. From locale select Frech(France) and save store view. Do same for English and select United kingdom.Now save Config and refresh the cache of your site to see the effect.

10/27/2010

How to remove parent category path from sub category url in Magento

Go to app/code/core/Mage/Catalog/Model/

Open Url.php and go to line no 632 and comment(//) the below line

If you are using Magento 1.5 then please go to line number 797 instead of 632

//if (null === $parentPath) {
//$parentPath = $this->getResource()->getCategoryParentPath($category);
//}
//elseif ($parentPath == '/') {
$parentPath = ''; //('Don't comment it')
//}

Now save and upload it.

Now login to admin panel of your site then go to System->Config->Index Management and click on select all then select Reindex Data from the Action Dropdown then click on submit.

10/26/2010

How to set or change Page title of a custom module in magento

If you are making a new Module in magento then you must set your page title. To set Page title in your module write the code below inside your all action of your module Design XML.
You can find your module xml inside
app/design/frontend/default/yourtheme/layout

<reference name="head">
<action method="setTitle"><title> Your Page Title </title></action>
</reference>

10/25/2010

get Special price or Regular Price in magento

To get Special Price or Regular Price of a product you need to Know the product Id.
Then write the code Below to fetch the All Price of a procduct

<?php 
$product= Mage::getModel('catalog/product')->load(product_id); 
$price = $product->getPrice();
$webprice = $product->getwebprice();
$specialprice = $product->getFinalPrice();
if($specialprice==$price)
{?>
<span class="price">$<?php echo number_format($price,2);?></span>
<?php } else { ?>
<div class="regular-price">
<span>Regular Price:</span>
<span class="price">$ <?php echo number_format($price,2); ?></span>
</div> 
<div class="special-price">
<span>Web Special:</span>
<span class="price">$ <?php echo number_format($specialprice,2); ?> </span>
</div>
<?php } ?>

How to get Special price or Regular Price in magento

To get Special Price or Regular Price of a product you need to Know the product Id.
Then write the code Below to fetch the All Price of a procduct

<?php
$product= Mage::getModel('catalog/product')->load(product_id);
$price = $product->getPrice();
$webprice = $product->getwebprice();
$specialprice = $product->getFinalPrice();
if($specialprice==$price)
{?>
<span class="price">Price $<?php echo number_format($price,2);?></span>
<?php } else { ?>
<div class="regular-price">
<span>Regular Price:</span>
<span class="price">$ <?php echo number_format($price,2); ?></span>
</div>
<div class="special-price">
<span>Web Special:</span>
<span class="price">$ <?php echo number_format($specialprice,2); ?> </span>
</div>
<?php } ?>

10/24/2010

Magento Set Session value and Get Session value

Set a Session value into a session Id in magento is little bit different. If you want to follow the Magento process than you must have to write the code given below to set a value and get a value of a particular Session Id.

To set Session write <?php Mage::getSingleton('core/session')->setData('session_Id'); ?>

To get that session value write

<?php Mage::getSingleton('core/session')->getData('session_Id'); ?>

10/20/2010

get value send in post method in magento

To get value send in post method , Magento use getRequest()->getParam() Method.The Proper code written below.

<?php $var = $this->getRequest()->getParam('<b>yourfieldname</b>');?>

10/06/2010

Calling a static block into phtml file in Magento

To call a static block in Magento ,You can use the following code;
<?php
echo $this->getLayout()->createBlock('cms/block')->setBlockId('Your_Static_Block_Name')->toHtml();
?>

To create your Static Block you can log into your admin panel than go to CMS->Static Blocks. There create your static Block with a name, then write the name in setBlockId() to call that into phtml file.

add facebook share button in magento

You can get Facebook share button from http://www.facebook.com/share/. But to add this in magento you need to get the current page url.
From the below code you can get the Current page Url in magento
<?php 
echo $currUrl= $this->getUrl('').$_SERVER['REQUEST_URI'];
?>
Now Write this code into the header/footer section of your site To see the Share Button
<a name="fb_share" type="button" href="http://www.facebook.com/sharer.php?u=<?php echo $currUrl;?>">Share</a>
<script src="http://static.ak.fbcdn.net/connect.php/js/FB.Share" type="text/javascript"></script>

How to get Current page url in magento

get Current page url in magento is so easy.You can get lots of solution in differnet site.But this one is the sort and best solution for getting Current page url. <?php
echo $currUrl= $this->getUrl('').$_SERVER['REQUEST_URI'];
?>

You can also use the folllowing magento features to get current page Url.

echo $this->helper('core/url')->getCurrentUrl();

9/14/2010

change My Cart text in magento

To Chnage the text of My Cart in top links you need to go app/code/core/Mage/Checkout/Block/ there you will find Links.php .there will be below function


public function addCartLink()
{
if ($parentBlock = $this->getParentBlock()) {
$count = $this->helper(’checkout/cart’)->getSummaryCount();

if( $count == 1 ) {
$text = $this->__(’My Cart (%s item)’, $count);
} elseif( $count > 0 ) {
$text = $this->__(’My Cart (%s items)’, $count);
} else {
$text = $this->__(’My Cart’);
}

$parentBlock->addLink($text, ‘checkout/cart’, $text, true, array(), 50, null, ‘class="top-link-cart"’);
}
return $this;
}

Change “My Cart” to your required text and Upload it to server.then clear the catche to see the effect

9/06/2010

how to change theme in magento

To change theme of Magento you need to login to your admin panel.There is two way to change it
1) Go to System->Design .Click on Add Design Change ,there from Custom Design click on the DropDown to select your Design , then save it to change your theme
Change theme in Magento

2) Go to System->Configuration then click on Design,there from Themes Tab you can change your theme.Write your theme name in Templates and Skin (Images / CSS) Field. then click on save Config to save your theme.

Change theme in Magento

If you don't know you theme name then it is beter to choose First option,Because it is much easier than the second one.One more thing that if you have two store and you want to make 2 different Theme for that two store than you have to follow the first process.

difference between append() and html() in jquery

.aapend() and .html() is the most usefull method in jQuery.But these are far different from one another, .append() add some value with the existing one.whether .html() do the same but it removes the old value
Here is an example is given

<ul id="test">
<li>test</li>
</ul>

Now I will use .append() to add one <li>, For that I will write
<script type="text/javascript>"
jQuery("#test").append("<li>test1</li>");
</script>


The output of this jQuery will be
<ul id="test">
<li>test</li>
<li>test1</li>
</ul>

Now if I use .html() to add one <li>, For that I will write
<script type="text/javascript>"
jQuery("#test").html("<li>test1</li>");
</script>

The output of this Script will be
<ul id="test">
<li>test1</li>
</ul>

Here in this example .append() add one extra <li>, whether .html() removes the old one with new one. This is the main difference between .append() and .html() in Jquery

hide subcategory menu in magento

There is two way to hide subcategory menu.One is from admin panel and other is by css.


1) From Admin Panel :-
Login to admin panel of your magento site then go to System->Configuration. from the left hand side panel click on Catalog, then click on Category Top Navigation tab.Default the value written in the Maximal Depth is 0 , make it 1 to hide the submenu.


Hide Subcategory Menu

2) From Css :-
go to your ...

9/01/2010

Magento connect manager internal server error

This is the most common problem for all Magento User.This problem is only for the File Permission in the server.To solve this Problem first you need to login to your FTP(File Transfer Protocol), then go to your magento installation path their you will find downloader Change the file permission to 755 , Again goto the index.php file inside downloader folder and change the file permission to 755.Now refresh the page you will see the effect.

8/30/2010

How to get all Store Ids in Magento

<?php
$allStores = Mage::app()->getStores();
foreach ($allStores as $_eachStoreId => $val)
{
$_storeCode = Mage::app()->getStore($_eachStoreId)->getCode();
$_storeName = Mage::app()->getStore($_eachStoreId)->getName();
$_storeId = Mage::app()->getStore($_eachStoreId)->getId();
echo $_storeId;
echo $_storeCode;
echo $_storeName;
}
?>

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

5/30/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

5/11/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.

4/06/2010

Add a css Class Using Jquery

To use Css Class in an HTML Tag we can use a Jquery function addClass(). This function add a css class into your HTML tag.The most intresting things is that you can use this class on a eventhandler also, To get effects when a client/user response on it.
This is an example to add a css class into a Html Tag

<script type="text/javascript">
$(document).ready(function(){
$('.click').click(function(){
$('p').addClass('green');
});
});
</script>
<style type="text/css">
.green{ color:green;}
</style>

Write this code into your body tag
<button class="click">Click Me</button>

What is Jquery and How it Works

Jquery is a Library fucntion of Javascript.It's very easy to write and very much faster than Javascript. When we use onLoad event handler on body tag ,the onload function will fired when all body content will download successfully ,that means all the image should download completely,then only this event will fired.But in Jquery when your Html DOM(Document Object Model) will load completely than the Jquery function can be fired,it's no need to wait for downloading any Image.That is why it is very nuch popular than other language/script.


For example I am going to give red color into all h1 tag When this page will loaded. For that i will write

<script type="text/javascript">
$(document).ready(function(){
$('h1').css('color','red');
});
</script>

Before Run this script You need to link JQUERY Library into your page which you can get from these links
http://code.jquery.com/jquery-1.4.2.min.js
or you can use this one
http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js

Attach any one of this script then You can see the effect only

Mouseover effect using Javascript and css

Mouse over effect can be done by css e.g(button:hover{background:red;}.But this css will not work in IE6. So it needs to use java script for mouse over effect in a button .By using Javscript it can be possible to show mouseover effect in every browser. The demo of this script is applied in the button given below.

This effect will work in every browser.The javascript of this button is given bellow

<input style="width:113px; height:31px; border:none; background:url(button.gif);" onmouseover="this.style.background='url(buttonHover.gif)';" onmouseout="this.style.background='url(button.gif)'" type="button" value="See here" />

3/31/2010

Show a messagebox By javascript

If you want to give a message to User thesn Simply right a javascript.Basically most of the websites uses this messagebox to show any kind of error or message to the User

To Show this Message simply write a script in header Section of your Html
I have Used this message to show when somebody clicks on a buton


This is the code you need to write in header section of your html

<script type="text\javascript">
function message(){
     alert("Type your message here");
}
</script>


Write this code into your body part

<input type="button" onclick="message();" value="click me" />

3/26/2010

CSS Hacks for Internet Explorer 8

Like IE6 and IE7,IE8 also needs some hacks .Let the css is something like given below

.style1{ width:320px;}

If this css will not show perfect only in IE8 then we need to write

.style1{ width:320px;width:300px\9;}

Using ( \9 ) sign indicates that this css will render by only in IE8 Browser not any browser will understand it's meaning.

3/20/2010

CSS Hacks for Internet Explorer 7

Like IE6 ,IE7 also needs some hacks some times.For that we need to write the css something like given below

.style1{ padding:10px 0 0 20px;}

If this css will have any problems in IE7 then we need to write the css like

.style1{ padding:10px 0 0 20px; !padding:10px 0 0 18px;}

Using ( ! ) sign indicates that this css will render by both IE7 and IE6 not in other browser.

CSS Hacks for Internet Explorer 6

Css Hacks is the most important things for all the designer,if they want to show a page perfect in every browser. Basically all browser show perfect design,But all IE Browser have some problems to show the actual view for that it needs to give some css hacks

Css hacks For IE6

when we give the width of a block level element by css maybe that width increase in IE6 or when we give padding or margin of an Element Ie6 may show some more Padding or margin.That time it needs to write the _padding or _margin and decrease the padding or margin or width;By writing _width or _padding will effect only in IE6 browser not in other browser. For Example

.style1{ width:500px;}

If this width will not show in IE6 perfectly then we need to write this class like

.style1{ width:500px;_width:490px;}

Ie6 will render the 2nd width but all browser will render the first width

3/14/2010

Show or hide an image by javascript

It is very easy to hide or show an image according to client's click.
simply call a js function in onclick event handler for example:-


Write this script into your header Tag


Write these code in to your body tag

3/05/2010

File Uploading by php

Uploading Files to server is not so hard it's very simple.
$dir="images/";  // Give your server path where to upload
$uploaddir=$dir.basename($_FILES['f1']['name']); // to Give a new file name
if(move_uploaded_file($_FILES['f1']['tmp_name'],$uploaddir))
    {
    }

2/26/2010

XHTML VS HTML

I have asked many people about the difference between HTML and XHTML , Somebody given me the right answer and somebody couldn't. Lastly I got the difference between HTML and XHTML, which is given below.

  1. XHTML documents Should be properly nested whether it's not important in HTML
  2. XHTML tags should be always closed
  3. XHTML documest should be only one root element
  4. All XHTML tags should be writen in lowercase ,Uppercase is not allow