Thursday 14 February 2013

How to create csv file using magento

Creating csv files in magento is very easy and flexiable

         $fileName = "example.csv";
         $file_path = Mage::getBaseDir('media').DS.$fileName; // path of the file

         $mage_csv = new Varien_Convert_Parser_Csv();

          try {
         $mage_csv->saveData($file_path, $rows); //note $rows will be two dimensional array
         $result = $mage_csv->unparse();
              } catch (Exception $e) {
         echo $e->getMessage();exit;

         header("Content-type: application/csv");
         header("Content-Disposition: attachment; filename=$fileName");
         header("Pragma: no-cache");
         header("Expires: 0");
         echo $result->getData();

     $fileName = "example.csv";
         $file_path = Mage::getBaseDir('media').DS.$fileName; // path of the file

         $mage_csv = new Varien_Convert_Parser_Csv();
         $rows = array();
        $_data['n'] = 'name';
         $_data['a'] = 'address';
         $_data['g'] = 'gender';

           $data['n'] = 'Ram';
         $data['a'] = 'Hyd';
         $data['g'] = 'Male';
        $rows []=$data;
          try {
         $mage_csv->saveData($file_path, $rows); //note $rows will be two dimensional array
         $result = $mage_csv->unparse();
              } catch (Exception $e) {
         echo $e->getMessage();exit;

         header("Content-type: application/csv");
         header("Content-Disposition: attachment; filename=$fileName");
         header("Pragma: no-cache");
         header("Expires: 0");
         echo $result->getData();

Wednesday 13 February 2013

How to remove currency symbol from price?

We can remove symbol from price admin

System > Manage Currency > Symbols

Monday 11 February 2013

To create a order programmatically in magento

Below is the php code to create an order in magento. It requires a valid customer account with shipping and billing address setup.
$id=1; // get Customer Id
$customer = Mage::getModel('customer/customer')->load($id);
$transaction = Mage::getModel('core/resource_transaction');
$storeId = $customer->getStoreId();
$reservedOrderId = Mage::getSingleton('eav/config')->getEntityType('order')->fetchNewIncrementId($storeId);
$order = Mage::getModel('sales/order')
//Set your store currency USD or any other
// set Customer data
// set Billing Address
$billing = $customer->getDefaultBillingAddress();
$billingAddress = Mage::getModel('sales/order_address')
$shipping = $customer->getDefaultShippingAddress();
$shippingAddress = Mage::getModel('sales/order_address')
/*some error i am getting here need to solve further*/
//you can set your payment method name here as per your need
$orderPayment = Mage::getModel('sales/order_payment')
->setPo_number(' – ');
// let say, we have 1 product
//check that your products exists
//need to add code for configurable products if any
$subTotal = 0;
$products = array(
    '1' => array(
    'qty' => 2
foreach ($products as $productId=>$product) {
$_product = Mage::getModel('catalog/product')->load($productId);
$rowTotal = $_product->getPrice() * $product['qty'];
$orderItem = Mage::getModel('sales/order_item')
$subTotal += $rowTotal;
$transaction->addCommitCallback(array($order, 'place'));
$transaction->addCommitCallback(array($order, 'save'));

How to call custom blocks that are created already in phtml in magento?


How to upgrade magento 1.4 1.1 to

How to upgrade magento 1.4 1.1 to 1. Change permissions on lib/pear folder to writable (recursively): command: chmod -R 777 lib/PEAR 2.Execute this command to prepare Magento for upgrade: command: ./pear mage-setup Most likely you will see this result after command execution: Channel “” is already initialized Upgrade from Magento 1.4.1.x to Magento This step is necessary even if you upgrade your Magento store to 1.5 or 1.6 versions.

3.Execute Magento upgrade command: command: ./pear upgrade -f magento-core/Mage_All_Latest-stable Output of the command will show you what core packages were upgraded: channel:// upgrade ok: channel:// upgrade ok: channel:// upgrade ok: channel:// upgrade ok: channel:// 4.When this part of the upgrade will be complete, enter these commands: command: .chmod 550 ./mage command: ./mage mage-setup . Running initial setup...


Successfully added:

It means that Magento connect 2.0 channel was added to the channels list successfully. 5.Next, enter this command: command: ./mage sync The result will be: Successfully added: community/Lib_Js_Mage-

Successfully added: community/Lib_Js_Calendar-1.51.1

Successfully added: community/Mage_Downloader-

Successfully added: community/Lib_Js_TinyMCE-

Successfully added: community/Lib_Js_Ext-

Successfully added: community/Lib_Google_Checkout-

Successfully added: community/Interface_Install_Default-

Successfully added: community/Lib_Js_Prototype-

Successfully added: community/Find_Feed-1.0.7

Successfully added: community/Lib_LinLibertineFont-

Successfully added: community/Lib_Varien-

Successfully added: community/Mage_Centinel-

Successfully added: community/Lib_Phpseclib-

Successfully added: community/Mage_All_Latest-

Successfully added: community/Mage_Locale_en_US-

Successfully added: community/Lib_PEAR-

Successfully added: community/Lib_Mage-

Successfully added: community/Mage_Pear_Helpers-1.0.18800

6.Upgrade from Magento to Magento 1.5.10 or Magento Now you can upgrade your store to version 1.5 or 1.6. Before proceeding with this part of Magento upgrade, it is very important to see to what version Magento upgrade scripts will upgrade your store. Enter this command to check this:

command: ./mage list-upgrades Updates for community:

Lib_Js_Mage: =>
Lib_Js_Calendar: 1.51.1 =>
Mage_Downloader: =>
Lib_Js_TinyMCE: =>
Lib_Js_Ext: =>
Lib_Google_Checkout: =>
Interface_Install_Default: =>
Lib_Js_Prototype: =>
Find_Feed: 1.0.7 => 1.1.1
Lib_LinLibertineFont: =>
Lib_Varien: =>
Mage_Centinel: =>

Lib_Phpseclib: =>

Mage_All_Latest: =>

Mage_Locale_en_US: =>

Lib_Mage: =>
7.Enter this command to change the upgrade channel to stable: command: ./mage config-set preferred_state stable Result : Success 8.After channel selection you can upgrade your Magento to (or to Magento using this command: command: ./mage upgrade-all --force 9.Clear the Cache and give permissions to magento folders. 10.Replace old .htaccess file insted of new file.

Important notes: 1.When upgrade magento version to that time DB issues occured: Tables List: a.wishlist_item b.Catalog_Category_Flat_Store_30 c.tax_order_aggregated_updated d.sales_order_tax_item Solution: First of all take backup of above tables, After delete those tables issue is resolved. For alternative backup of above data re-import the backup tables. (This tables are not mandatory, just keeping it backup) NOTE: if create any table issue rise in upgrade time take bakup table and delete it. 2.“Integrity constraint violation: 1062 Duplicate entry “
This error can be solved by disabling the unique indexes check.
In the app/etc/config.xml, change this


3.Error: Fatal error: Call to a member function getAllOptions() on a non-object in /var/www/html/magento/app/code/core/Mage/Core/Model/Cache.php on line 455
Solution: Uncomment line 198 in app/mage.php:

//self::$_appRoot = null;

which is called by app/code/core/Mage/Core/Model/Config/Options.php at line 54:

$appRoot= Mage::getRoot();
4.Admin Side not disply
app/code/core/Mage/Admin/Model/Session.php (Commented Line No:93)

How to setup Magento ecommerce on Cpanel Server without SSH access(Fast way)

Here is source

Original Post:
I would advise to check the original guide posted on magentohub as we always update the guide from time to time when necessary with new updates/changes.
First of all, make sure your webhost meet the [url=[/url] before you install magento.

Two reasons why you should use this guide:

1. Your account do not come with SSH access and upload files via FTP is taking so long( it took me > 20minutes just to upload entire magento files via FTP)
2. OR you do not know how to install magento using SSH.
This guide is for you.
Here is a quick way to upload all magento files using cpanel file manager:
Upload magento
1. Upload your file to public_html/ via FTP. This gonna take sometime since the zip file alone is about 15mb big.
2. Upload finish.
Login to Cpanel > File manager
3. Navigate to the directory where you have just upload the zip file.
4. Right click the zip file and choose “Extract” . It should extract a “magento” folder.
5. Enter into “magento” folder , “Select all” . Right click on one of the selected file. Choose “move”
Move all files outside of “magento” folder.
6. Delete “magento” folder and the zip file.
Start installation
1. Create a mysql database & mysql user.
2. Import the sample data to your mysql database. (You can do so at Cpanel > mysql > phpmyadmin)
(You can get the .sql sample data from )
3. Start the installation wizard
Note: My site is hosted on a suexec/suphp environment. Therefore, i do not have chmod 777 to make certain directories writable. For other who are no on suexec/suphp ennvironment, you may require to make the file magento/var/.htaccess, the directories magento/app/etc, magento/var, and all the directories under magento/media are writable by the web server.