5/30/2012

Magento: Can not login to Magento Admin after installation

Are you not able to login to admin panel of newly installed magento, even there is no error message.

If the domain is not a true domain, then sometimes this problem occurs. Try this solution:

Go to: [Magento Root Folder]/app/code/core/Mage/Core/Model/Session/Abstract/Varien.php

and comment below lines-

'domain' => $cookie->getConfigDomain(),
'secure' => $cookie->isSecure(),
'httponly' => $cookie->getHttponly()

and remember to remove comma(,) from the line above these three.

Cheers :)

Note: Remember that above file is in core Magento folder, so override it using your own package name.

5/23/2012

Magento: 404 Error on Product Page


If your product pages are all going to 404 Not Found Page in Magento, then thats a headache for you.

But, don't worry, here is the fix :

Go to phpmyadmin and run this command:

-- Dumping data for table `report_event_types`

INSERT INTO `report_event_types` (`event_type_id`, `event_name`, `customer_login`) VALUES
(1, 'catalog_product_view', 1),
(2, 'sendfriend_product', 1),
(3, 'catalog_product_compare_add_product', 1),
(4, 'checkout_cart_add_product', 1),
(5, 'wishlist_add_product', 1),
(6, 'wishlist_share', 1);

5/22/2012

Magento: Add to compare not working without login


If Add to Compare is not working in your store without log in, there can be some problem of log cleaning.

Try truncating below tables:

log_url_info
log_url
log_visitor
log_visitor_info


After that, check. In my case, it worked.

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

5/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();
                  }

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

5/15/2012

How to get current product id

Try below code to get currently loaded product id:

$product_id = $this->getProduct()->getId();

When you don’t have access to $this, you can use Magento registry:

$product_id = Mage::registry('current_product')->getId();

Enjoy.. :)

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

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

5/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>';

     }
?>


                           
                           
                             

5/05/2012

Magento: Hide Tax from Grand Total in Customer Shopping Cart

If you want to hide tax from checkout/cart page, try the following:

Go to:

\app\design\frontend\[base]\[default]\template\checkout\cart\totals.phtml

Find the line (about 41):
<?php echo $this->renderTotals(); ?>
and replace with this:
<?php
      $rendertot = $this->renderTotals();
      $rendertot_tr = explode('</tr>', $rendertot);
          
      foreach($rendertot_tr as $trkey => $trval) {
         if( strpos($trval, __('Tax')) ) {
             unset($rendertot_tr[$trkey]);
         }
      }
      $rendertot_tr = implode('</tr>', $rendertot_tr);
      echo $rendertot_tr;
?>
It will remove tax row from cart page.
Note: Replace [base] with your current Package name and [default] with your theme name.

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

Magento: Sort products by Created At filter

Many times, we want to sort products by the newest first and the oldest last. But in magento, there are only three sorting filters by default, i.e. Name, Price and Best Value.

So, to make products list sorted by Newest first, we need to override some core code of magento.

To do this, go to:
                  app/code/core/Mage/Catalog/Block/Product
and copy List.php to [local] folder to override it.

Find the code of block:

$this->_productCollection = $layer->getProductCollection()

and replace it with:

$this->_productCollection = $layer->getProductCollection()->addAttributeToSort('created_at','DESC');

That's all.. Enjoy.. :)

Note: This method will work if you don't want to see dropdown of default sort filters, and just want to sort by newest products first.

If you also want to sort by default sort filters of Magento, i.e. Name, Price and Position, as well as add your custom filter to sort dropdown, then try with: