Follow by Email

Tuesday, May 22, 2012

Get catagory name from product id in cart page

          echo Mage::getModel('catalog/category')->load($this->getProduct()->
getCategoryIds($_item->getProductId()))->getName();



This is the code to get category name in cart page

Friday, May 18, 2012

Register , Login , Forget password code for magento

Create user
$customer = Mage::getModel('customer/customer');
                  $customer->setWebsiteId(Mage::app()->getWebsite()->getId());
                  $customer->loadByEmail($create['email']);
                  if(!$customer->getId())
                  {
                      $customer->setEmail($create['email']);
                      $customer->setFirstname($create['firstname']);
                      $customer->setLastname($create['lastname']);
                      $customer->setPassword($create['password']);               
                      $customer->save();
                      $customer->setConfirmation(null);
                      $customer->save();
                      $customer->sendNewAccountEmail();
                      $session->login($create['email'], $create['password']);
                   }

Login user
          $session->login($login['username'], $login['password']);

Forget password
$customer = Mage::getModel('customer/customer');
                  $customer->setWebsiteId(Mage::app()->getWebsite()->getId());
                  $customer->loadByEmail($forget['email']);
                  if($customer->getId())
                  {
                      $customer->sendPasswordReminderEmail();
                  }

Wednesday, May 16, 2012

Autocomplete ajax search in magento

Hi all,
I had a problem with Ajax search auto suggest in magento. The top search in magento i want to make it as a ajax search. so i did some change in
app\code\core\Mage\CatalogSearch\Block\Autocomplete.php
under the "getSuggestData" function
just comment the    foreach ($collection as $item) {     start to end
and past the this code

$resource = Mage::getSingleton('core/resource');
            $conn = $resource->getConnection('core_read');
            $results = $conn->query("SELECT pv.value,pv.entity_id FROM catalog_product_entity_varchar pv,catalog_product_entity pe where pv.attribute_id=65 and pv.value like '%".$query."%' and pv.entity_id=pe.entity_id and pe.type_id='configurable'")->fetchAll();       
            //this custom query add by sourav for autocomplet product search
           
            $counter = 0;
            $data = array();
            foreach ($results as $item) {
                $_data = array(
                    'title' => $item['value'],
                    'row_class' => (++$counter)%2?'odd':'even',
                    'num_of_results' => ''
                );
       
                if ($item['value'] == $query) {
                    array_unshift($data, $_data);
                }
                else {
                    $data[] = $_data;
                }
               
            }

Execute custom SQL query in magento

This is the code to run custom sql in magento.

$resource = Mage::getSingleton('core/resource');
$conn = $resource->getConnection('core_read');
$results = $conn->query("SELECT pv.value,pv.entity_id FROM catalog_product_entity_varchar pv,catalog_product_entity pe where pv.attribute_id=65 and pv.value like '%".$query."%' and pv.entity_id=pe.entity_id and pe.type_id='configurable'")->fetchAll();   

Monday, May 14, 2012

How to list all special price products according the category

Hi all,
I have a part in my project that i have to show all special price products in a page for different category and i have done it. It\’s very simple just go to your admin and create a static page \"Sale\". Now add
{{block type=\"catalog/product_list\" name=\"home.catalog.product.list\" alias=\"product_homepage\" template=\"catalog/product/sale.phtml\"}}
and save the page.
after that go to your app\\code\\core\\Mage\\Catalog\\Block\\Product and create a file sale.phtml and pest the following code in to your file and run it. 
<?php if(Mage::app()->getRequest()->getParam(\'category_id\')==\'\'){ ?><h2 class=\"subtitle\"><?php echo $this->__(\'Sale\'?></h2><?php
    $category_model 
Mage::getModel(\'catalog/category\'); //get category model
    
$_category $category_model->load(2);  
//$categoryid for which the child categories to be found    
    
$all_child_categories $category_model->getResource()
->getAllChildren($_category);
   
    foreach(
$all_child_categories as $category)
        
{
            
if($category!=2){
                $cur_category 
Mage::getModel(\'catalog/category\')->load($category);
                if(
$cur_category->getIsActive()){  ?>
                    
<a href=\"<?php echo $this->getBaseUrl(\'all-new-arrival\').\'sale/?category_id=\'.$category; ?>\"><img src=\"<?php echo $cur_category->getImageUrl(); ?>\" />
<div><?php echo $cur_category->getName(); ?></div></a>                   
            
<?php    }
            }
        }
?>   
<?php }else{ ?>

<?php
    $todayDate  
Mage::app()->getLocale()->date(
)->toString(Varien_Date::DATETIME_INTERNAL_FORMAT);
    
$categoryId Mage::app()->getRequest()->getParam(\'category_id\');
    
$catagory_model Mage::getModel(\'catalog/category\')->load($categoryId); //where $category_id is the id of the category
    
$collection Mage::getResourceModel(\'catalog/product_collection\');
    
$collection->addCategoryFilter($catagory_model); //category filter
    
$collection->addAttributeToFilter(\'status\',1); //only enabled product
    
$collection->addAttributeToFilter(\'special_from_date\'
      array(\'date\' => true\'to\' => $todayDate))
       ->
addAttributeToFilter(\'special_to_date\', array(\'or\'=> 
        array( => array(\'date\' => true\'from\' => $todayDate),
                    
=> array(\'is\' => new Zend_Db_Expr(\'null\')))
                ), 
\'left\');
    
$collection->addAttributeToSelect(array(\'name\',\'url\',\'small_image\',\'price\',\'special_price\')); //add product attribute to be fetched
         
    
$collection->addStoreFilter();   
    if(!empty(
$collection))
    
{ ?>
    
<div class=\"category_products\">
      
<?php  foreach ($collection as $_product):  ?>
          
<div class=\"product\">
            <
a href=\"<?php echo $_product->getProductUrl(); ?>\">
            <
img src=\"<?php echo $this->helper(\'catalog/image\')->init($_product, \'small_image\')->resize(172,235); ?>\" width=\"172\" height=\"235\" />
            <
div class=\"product-name\">
                <
a href=\"<?php echo $_product->getProductUrl() ?>\" >
                
<?php echo substr($_product->getName(),0,40).\' ...\' ?> 
                </
a>
            </
div><br/>
            <
div class=\"price\">
            
<?php echo $this->getPriceHtml($_producttrue?>
            
</div>           
            </
a>
         </
div>  
      
<?php endforeach;   ?>
     
</div>      
 
<?php   }else{ ?>          
        
<class=\"note-msg\"><?php echo \'No products exists\';  ?>  </p>
 
<?php   }  ?>
<?php } ?>
 

Category wise New product

If you want to show new product Category wise then go to the app\code\core\Mage\Catalog\Block\Product\New.php add
if($categoryId = Mage::app()->getRequest()->getParam('category_id')){           
        $category = Mage::getModel('catalog/category')->load($categoryId);
        $collection->addCategoryFilter($category);
        }          
before
        $this->setProductCollection($collection);

also open app\design\frontend\base\default\template\catalog\product\new.phtml

<?php if(Mage::app()->getRequest()->getParam('category_id')==''){ ?>
<h2 class="subtitle"><?php echo $this->__('New Arrivals') ?></h2>
<?php
    $category_model = Mage::getModel('catalog/category'); //get category model
    $_category = $category_model->load(2); //$categoryid for which the child categories to be found    
    $all_child_categories = $category_model->getResource()->getAllChildren($_category);
   
    foreach($all_child_categories as $category)
        {
            if($category!=2){
                $cur_category = Mage::getModel('catalog/category')->load($category);
                if($cur_category->getIsActive()){  ?>
                    <a href="<?php echo $this->getBaseUrl('all-new-arrival').'all-new-arrival/?category_id='.$category; ?>"><img src="<?php echo $cur_category->getImageUrl(); ?>" /><div><?php echo $cur_category->getName(); ?></div></a>                   
            <?php    }
            }
        }
?>   
<?php }else{  ?>
before
<?php if (($_products = $this->getProductCollection()) && $_products->getSize()): ?>
and close the bracket end of the page.

Friday, May 11, 2012

Add configurable product with size to wishlist

Hi all,
I have found some solution. I am using magento 1.6.2
if you go through the wishlist link in the product details page you will find the link like
/index.php/wishlist/index/add/product/47/
where product id is 47
Now you want to add a size with this configurable product. suppose your size attribute id is 128 and the value is 6 it's located the size M
now you can modify the wishlist url with
index.php/wishlist/index/add/product/47/?super_attribute[128]=6
you can change it using jQuery also.
when this url is open in the browser the product which id 47 will add in the wishlist with the size M.

Thursday, May 10, 2012

How to echo the number of reviews on the product page?

I have found out that this code finaly works when inserting into catalog/product/view.phtml
<?php
   $reviewData 
Mage::getModel('review/review/summary');
   echo 
'number of reviews: ' $reviewData->getTotalReviews($_product->getId());

   $reviews = Mage::getModel('review/review')->getCollection()
     ->addStoreFilter(Mage::app()->getStore()->getId())
     ->addStatusFilter(Mage_Review_Model_Review::STATUS_APPROVED)
     ->addEntityFilter('product', $_product->getId())
     ->setDateOrder();


     foreach ($reviews->getItems() as $review){
     echo $review->getTitle().'<br>';
     echo $review->getNickname().'<br>';
     echo $review->getDetail().'<br>';

     }
?>


                           
                           
                             

Wednesday, May 2, 2012

Product stock back alerts

Magento having a good process That if a product is out of stock then there should be a link for product notification. when the product back in stock it will send a mail to user.
if you want to activate it. go to System > Configuration > Catalog > Catalog > Product Alerts
and configure it.
clear magento cash. and it's work.