Category: Blog

Magento : How to speed up product imports and exports and decrease database size

To speed up magento products imports/exports and make database size decrease please run following query in your magento database :

TRUNCATE dataflow_batch_export;
TRUNCATE dataflow_batch_import;
TRUNCATE log_customer;
TRUNCATE log_quote;
TRUNCATE log_summary;
TRUNCATE log_summary_type;
TRUNCATE log_url;
TRUNCATE log_url_info;
TRUNCATE log_visitor;
TRUNCATE log_visitor_info;
TRUNCATE log_visitor_online;
TRUNCATE report_viewed_product_index;
TRUNCATE report_compared_product_index;
TRUNCATE report_event;
TRUNCATE index_event;
TRUNCATE catalog_compare_item;
TRUNCATE catalogindex_aggregation;
TRUNCATE catalogindex_aggregation_tag;
TRUNCATE catalogindex_aggregation_to_tag;

Magento : How to place an order for free ( using free payment option) in admin?

Some time we need to place and order for our customer as a demo or any missing products in last orders, in such of conditions we create order manually, and we don’t need to use any payment method to create such types of orders.
In that situation we need a free payment option in admin and not for front end. I am going to share with you how we can use free payment option in admin which is shows in follwoing steps:

1. Go to app/code/core/Mage/Payment/Model/Method and open file Free.php file.

2. Then go to Line 48-49 you will notice following code:

 protected $_canAuthorize                = true;
 protected $_canCapture                  = true;

3. After these lines add 2 lines of custom code as show in following:

 protected $_canAuthorize                = true;
 protected $_canCapture                  = true;
 protected $_canUseInternal              = true;
 protected $_canUseCheckout              = false; 

4. Next you will notice follwoing code :

public function isAvailable($quote = null)
    {
        return parent::isAvailable($quote) && (!empty($quote))
            && (Mage::app()->getStore()->roundPrice($quote->getGrandTotal()) == 0);
    }

5. Replace above code with the following code (in this function only change ‘== 0′ to ‘> 0′):

public function isAvailable($quote = null)
    {
        return parent::isAvailable($quote) && (!empty($quote))
            && (Mage::app()->getStore()->roundPrice($quote->getGrandTotal()) > 0);
    }

6. Now save Free.php file and upload it to custom local location app/code/local/Mage/Payment/Model/Method/Free.php

7. Next go to Admin panel and using navigation open System -> Configuration -> Payment Methods then Enable Zero Subtotal Checkout payment method, you can rename its title according to your desire.

8. Now clear Magento cache.

9. Done, now when to create any new order from admin you will see Zero Subtotal Checkout. it will not show on front end.

10. Hope it help you :)

11. For more detail visit Magento Post.

Magento : How to find out if a record already exists in a database or not ?

To check whether record exist in database or not, you can use following query:

<?php
$collection = Mage::getModel('sample/sample')->getCollection()->addFieldToFilter('field_name', $value_to_check)->getFirstItem();
if($collection->getId()){
   //executing this block if record found in database
}else{
   //executing this block if record not found in database
}

?>

Magento : How add translation ability into cms page or static block ?

As we all know magento have multi-language store. Magento use following syntax in .pthml to make text translate to multi-language which is like this :

    <?php   echo $this->__('text to translate'); ?>

OR

    <?php   echo Mage::helper('ModuleName')->__('text to translate');  ?>

But text written in cms page or static block have not translation ability.
To make cms page or static block text compatible with translation ability we need to do some extra coding work which is like this:

We can use following directive in cms page or static block

{{translate text="text to translate"}} 

To make it working in cms page or static block we need to add directive function in magneto code as show in following steps.

1. Go to app/code/core/Mage/Core/Model/Email/Template/ and download Filter.php file

2. open Filter.php and add following function after function mediaDirective(), found at approximate Line : 280


public function translateDirective($construction)
{
	$params = $this->_getIncludeParameters($construction[2]);
	$text = $params['text'];
        return Mage::helper('page')->__($text);
} 

3. Save file.

4. Next upload Filter.php in new custom location : app/code/local/Mage/Core/Model/Email/Template/

5 Now you can easily use following directive in any cms page or static block.

{{translate text="text to translate"}} 

6. Done. :)

Magento – Get category name in a custom product list on homepage

In all magento store mostly we show any category products list at home page. for that purpose we use list.phtml file or any custom file to show product list at home page using following block:

   {{block type="catalog/product_list" category_id="3" template="catalog/product/list.phtml"}}

This block only show products list on home page, but it don’t show category name.
For showing category name with that products list we need to add following code into list.phtml or any custom file you are using.

1. Go to app/design/frontend/default/your_theme/template/catalog/product and open list.phtml then paste following code :

<?php echo Mage::getModel('catalog/category')->load($this->getCategoryId())->getName(); ?>

2. Now relaod your store home page, you will see category name there.

3.Done.

Enjoy magento :)