Change ‘My Cart’ to ‘Shopping cart’ in top right nav or in top links

You can change your toplinks as from “My cart” to “Shopping cart” from following URL:
See on line number 48 to 52.

and after that overrides the Links.php as follows


and also Change in Links.php

class Mage_Checkout_Block_Links extends Mage_Core_Block_Template 

class My_Module_Block_Checkout_Links extend Mage_Checkout_Block_Links 

What is a Helper ?

Create your own Helper

As you are now used to, it starts by declaring it in the config.xml of your plugin, do that in <global> and after </blocks>


What is a Helper

As the name implies a « helper » is something that is right for you ! It is an object that will contain practical functions for you and you can call it from anywhere, you just load your helper to use it. For example:

$helper = Mage::helper(‘monhelper’);

Note that this call is actually equivalent to:

$helper = Mage::helper(‘monhelper/data’);
Indeed, it is the default helper « data » which is called.

Call helper of custom module

$helper = Mage::helper(‘modulename/helpername’);

Create your own Helper

As you are now used to, it starts by declaring it in the config.xml of your plugin, do that in <global> and after </blocks>


Then creates the folder and the file app/code/local/Pfay/Test/Helper/data.php function wich will contains the function bytwo($ nbr) with a number as an argument and returns that number multiplied by two. A helper is an object that extends the core class Mage_Core_Helper_Abstract.

class Pfay_Test_Helper_Data extends Mage_Core_Helper_Abstract{
public function bytwo($nbr){
return $nbr*2;

Now in/app/code/local/Pfay/Test/Block/monblock.php we change the function by:

class Pfay_Test_Block_Monblock extends Mage_Core_Block_Template
public function methodblock()
$helper = Mage::helper('test');
return '2*2 = '.$helper->bytwo(2);

Now when we go on, we see that it works!

Here we are ! you understand how to create a helper on magento, I invite you to practice, the only way to improve yourself ;) If you have any questions, feel free to leave a comment.

You want to help me? Share this article on twitter, do an article on this series of tutorials on your blog, tell your friends, participate in the comments and return to this site;)

Magento – Updating product prices using CSV

$mageFilename = 'app/Mage.php';
require_once $mageFilename;
ini_set('display_errors', 1);
Mage::register('isSecureArea', 1);
/***************** UTILITY FUNCTIONS ********************/
function _getConnection($type = 'core_read'){
    return Mage::getSingleton('core/resource')->getConnection($type);
function _getTableName($tableName){
    return Mage::getSingleton('core/resource')->getTableName($tableName);
function _getAttributeId($attribute_code = 'price'){
    $connection = _getConnection('core_read');
    $sql = "SELECT attribute_id FROM " . _getTableName('eav_attribute') . "
            WHERE entity_type_id = ? AND attribute_code = ?";
    $entity_type_id = _getEntityTypeId();
    return $connection->fetchOne($sql, array($entity_type_id, $attribute_code));
function _getEntityTypeId($entity_type_code = 'catalog_product'){
    $connection = _getConnection('core_read');
    $sql        = "SELECT entity_type_id FROM " . _getTableName('eav_entity_type') . " 
                   WHERE entity_type_code = ?";
    return $connection->fetchOne($sql, array($entity_type_code));
function _getIdFromSku($sku){
    $connection = _getConnection('core_read');
    $sql        = "SELECT entity_id FROM " . _getTableName('catalog_product_entity') . " WHERE sku = ?";
    return $connection->fetchOne($sql, array($sku));
function _checkIfSkuExists($sku){
    $connection = _getConnection('core_read');
    $sql        = "SELECT COUNT(*) AS count_no FROM " . _getTableName('catalog_product_entity') . " WHERE sku = ?";
    $count      = $connection->fetchOne($sql, array($sku));
    if($count > 0){
        return true;
        return false;
function _updatePrices($data){
    $connection     = _getConnection('core_write');
    $sku            = $data[0];
    $newPrice       = $data[1];
    $productId      = _getIdFromSku($sku);
    $attributeId    = _getAttributeId();
    $sql = "UPDATE " . _getTableName('catalog_product_entity_decimal') . " cped
                SET  cped.value = ?
            WHERE  cped.attribute_id = ?
            AND cped.entity_id = ?";
    $connection->query($sql, array($newPrice, $attributeId, $productId));
/***************** UTILITY FUNCTIONS ********************/
$csv                = new Varien_File_Csv();
$data               = $csv->getData('prices.csv'); //path to csv
$message = '';
$count   = 1;
foreach($data as $_data){
            $message .= $count . '> Success:: While Updating Price (' . $_data[1] . ') of Sku (' . $_data[0] . '). <br />';
        }catch(Exception $e){
            $message .=  $count .'> Error:: While Upating  Price (' . $_data[1] . ') of Sku (' . $_data[0] . ') => '.$e->getMessage().'<br />';
        $message .=  $count .'> Error:: Product with Sku (' . $_data[0] . ') does\'t exist.<br />';
echo $message;

Set Special Price Programatically In Magento



$product = Mage::getModel('catalog/product')->load(114912);
$product->setSpecialPrice( ($product->getPrice() * .90) );


<span style="font-family: Consolas, Monaco, monospace;">


Magento: Programmatically Updating SKUs in Bulk

Magento does not make it easy to change SKUs in bulk. Try to do it via the import/export or dataflow profiles and you run into all kinds of problems. There is, however, a fairly easy way to do it and it simply involves adding a php script to your server and a CSV file of before and after SKUs. Here’s the step-by-step;

Note: Be sure to test this with only one or two product SKUs before doing it with all your SKUs. Also, be sure to backup your database before attempting this.

1. Create a CSV File with Before and After SKUs

In the first column, list your current SKUs and in the second column list the new SKUs.

Do not include headings in your CSV file.

Be sure this file is saved as a CSV file in the UTF-8 or ANSI encoding. You might run into problems with this if you create the file using Excel.

2. Put the CSV File on Your Server

Upload the CSV file to the var/export directory on your Magento server so that it’s path is /var/export/sku2sku.csv.

3. Create the PHP Script

On your server, in your Magento installation directory (the one where you see the app, var, skin, media, js and other directories), create a new file, save it, and name it “updateskus.php”.

Paste the following php code into updateskus.php and save the file.

include_once './app/Mage.php';
$updates_handle=fopen($updates_file, 'r');
if($updates_handle) {
       while($sku_entry=fgetcsv($updates_handle, 1000, ",")) {
            echo "<br>Updating ".$old_sku." to ".$new_sku." - ";
            try {
                   $get_item = Mage::getModel('catalog/product')
                               ->loadByAttribute('sku', $old_sku);
                   if ($get_item) {
                          echo "successful";
                    } else {
                          echo "item not found";
                } catch (Exception $e) {
                    echo "Cannot retrieve products from Magento: ".$e->getMessage()."<br>";

4. Run the Script

To run the script simply use your internet browser and navigate to If you have a multi-site setup use the master or primary site as set by your hosting provider.

When the page opens you should see confirmation messages that your SKUs were updated. Your SKUs should now be successfully updated.

If you’re finished updating the SKUs, remove the CSV and PHP files that you added to the server.

5. Errors

If you run into the following error, don’t worry too much. Just re-run the script and see if more SKUs get updated.

Cannot retrieve products from Magento: SQLSTATE[40001]: Serialization failure: 1213 Deadlock found when trying to get lock; try restarting transaction

If you have a lot of SKUs to update you can expect the script to take several minutes at least, to complete.

This method was tested on a multi-site Magento Community 1.6.1 installation.

Magento get total quantity of product sold

$id = 123; // enter your product ID here
$_productCollection = Mage::getResourceModel('reports/product_collection')
    ->addAttributeToFilter('id', $id)
    ->setOrder('ordered_qty', 'desc')
$product = $_productCollection;

echo 'Already Bought '.(int)$product->ordered_qty;