Search This Blog

Friday 28 September 2012

Magento: Move Google Analytics code to head tag

To move the GA code from after <body> tag  to before closing </head> tag involves following two steps:

Step 1:
Add the following code with in the <block type="page/html_head" name="head" as="head"> tag in app\design\frontend\base\default\layout\page.xml

<block type="core/text_list" name="before_head_end" as="before_head_end" translate="label">
 <label>Page Top</label>
</block>

Step 2:
Now open app\design\frontend\base\default\layout\googleanalytics.xml file and replace
after_body_start

With

before_head_end


Note: Make sure you enabled GA in admin section Magento: Setting Up Google Analytics + eCommerce Tracking

If the changes not reflecting then refresh the Magento cache and check.....

Magento: Setting Up Google Analytics + eCommerce Tracking

Google Analytics is a free Google service which allows the webmasters and web site administrators to monitor their web sites' traffic and conversion ratio.
Magento supports two types of tracking:
  • Page View Tracking: Lists the origin from which your web store visitors linked to your store.
  • E-commerce Tracking: Lists the customers that make purchases and what they buy.
First you need to sign up at http://www.google.com/analytics/sign_up.html. You will receive a Google Analytics account number. Write it down since you will need it for the Magento configuration.
Then configure the Google Analytics tracking in Magento. Open the Magento Admin area and navigate to System->Configuration->Sales->Google API.
Expand the Google Analytics section.

Pick the Yes option from the Enable drop-down menu. Enter the Google Analytics account number in the Account number field. Click on the Save Config button.

Note: Make sure you enable Ecommerce tracking in Google Analytics profile settings. 

Monday 10 September 2012

Programmatically change Magento’s core config data

$configValue = Mage::getStoreConfig('sectionName/groupName/fieldName');
sectionName, groupName and fieldName are present in etc/system.xml file of your module.



$testSwitch = new Mage_Core_Model_Config();
/*
*turns notice on
*/
$testSwitch ->saveConfig('design/head/demonotice', "1", 'default', 0);
/*
*turns notice off
*/
$testSwitch ->saveConfig('design/head/demonotice', "0", 'default', 0);

Well explained at http://inchoo.net/ecommerce/magento/how-to-programmatically-change-magentos-core-config-data/


Get the core config data collection that match the path and update new path:

try {
        $path = 'old';
        $collection = Mage::getModel('core/config_data')->getCollection()
                        ->addFieldToFilter('path', array('like' => $path . '/%'));
        if ($collection->count() > 0) {
            foreach ($collection as $coreConfig) {
                $oldPath = $coreConfig->getPath();
                $newPath = str_replace("old", "new", $oldPath);
                $coreConfig->setPath($newPath)->save();
            }       
        }
    } catch (Exception $e) {
        Mage::log($e->getMessage(), Zend_Log::ERR);
    }
Read more about Core Config data at http://alanstorm.com/magento_loading_config_variables

Tuesday 4 September 2012

Get all customer groups in Magento

$customer_group = new Mage_Customer_Model_Group();
$allGroups  = $customer_group->getCollection()->toOptionHash();
foreach($allGroups as $key=>$allGroup){
   $customerGroup[$key]=array('value'=>$allGroup,'label'=>$allGroup);
}
return $customerGroup;

Get all websites and stores in Magento

foreach (Mage::app()->getWebsites() as $website) {
    foreach ($website->getGroups() as $group) {
        $stores = $group->getStores();
        foreach ($stores as $store) {
            //$store is a store object
        }
    }
}

Add Custom Field in the Billing and Shipping Address of Onepage Checkout in Magento

How to Add Custom Field in the Billing and Shipping Address of Onepage Checkout in Magento

http://indiestechtips.wordpress.com/2011/07/30/how-to-add-custom-field-in-the-billing-and-shipping-address-of-onepage-checkout-in-magento/

Magento: Admin Grid Column types

There are many types of column types in the admin grid.









Following are the list of available types in Magento:



  1. date
  2. datetime
  3. number
  4. currency
  5. price
  6. country
  7. concat
  8. action
  9. options
  10. checkbox
  11. massaction
  12. radio
  13. input
  14. select
  15. text
  16. store
  17. wrapline
  18. theme