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';
}
}
?>