Search This Blog

Friday, 9 March 2012

Add column to mysql table if it does not exist in the table

<?php
$DBHOST = 'HOSTNAME';
$DBUSER = 'USERNAME';
$DBPASS = 'PASSWORD';
$DATABASE = 'DBNAME';
$table = 'talble_name';
$column = "column_name";

mysql_connect($DBHOST,$DBUSER,$DBPASS) or die(mysql_error());
mysql_select_db($DATABASE) or die(mysql_error());
$result=mysql_query("SELECT $column FROM $table;");
if (mysql_errno())
{
        echo "Unknown column CREATE one first";

        // Alter table add column goes here
}
else
{
          echo "column exists";
}
mysql_close();
?>

 

Wednesday, 7 March 2012

Magento: Format Price

<?php echo $formattedPrice = Mage::helper('core')->currency('100.00',true,false); ?>

OR

<?php echo Mage::app()->getLocale()->currency(Mage::app()->getStore()->getCurrentCurrencyCode())->getSymbol(); ?> 90.00

Wednesday, 22 February 2012

Customizing the Magento Error Report and Maintenance Page

 There are several  Error Report and Maintenance Pages 404, 503 and Error report. Customizing the each page information can be found at below link.


http://magebase.com/magento-tutorials/customizing-the-magento-error-report-and-maintenance-page/

Thursday, 2 February 2012

Upgrading Magento and Data Management

Database repair tool: http://www.magentocommerce.com/wiki/1_-_installation_and_configuration/db-repair-tool

Moving Magento To Another Server: http://www.magentocommerce.com/wiki/groups/227/moving_magento_to_another_server

Moving Magento from development to production: http://www.iwebux.com/moving-magento-from-development-to-production/

Magento 2 Magento data migration: http://www.shopping-cart-migration.com/shopping-cart-migration-options/223-magento-to-magento-migration


Magento 2 Magento data migration: http://www.shopping-cart-migration.com/shopping-cart-migration-options/223-magento-to-magento-migration

My approach for upgrading Magento involves following:
1. Setting up a New Development Environment (ex: dev.domain.com or domain.com/dev etc.,) As upgrading Magento in production server is not recommended
2. In production, archive all the customizations that should be part of the upgrade and copy them to dev Environment
a. Export the production database.
b. Media directory from production installation
c. All theme files
d. All the custom Modules
e. Extensions and other core extensions or customizations
3. In dev Environment, download the latest stabled version
4. Resetting file permissions in dev server to make the Magento work properly
5. Make appropriate changes in Dev Database base URLs to reflect dev environment links
6. Run setup wizard to upgrade the Magento
7. Make changes to the customizations to match the new version standards [If the existing customizations conflicts with the new version of Magento]
8. Testing upgraded site to ensure everything working properly
9. Once everything is done, make the production site unavailable / down for the users until below process is completed
a. Backup product Database and file system
b. Remove all cache
c. Copy all the files from development to production environment
d. Run setup wizard to upgrade the production Magento with existing database (so that we will not lose any data like orders, products and customers)
e. Test and ensure everything is fine
10. Making the upgraded site live for all the users.
11. The best time for production Magento upgrade would be night hours.


Wednesday, 16 November 2011

Emails not sending in Magento 1.3.1

 As a temporary measure a fix can be issued in the form of editing core code.

1) Enter the root directory of your Magento store and enter
# mkdir app/code/local/Mage
# mkdir app/code/local/Mage/Core
# mkdir app/code/local/Mage/Core/Model
# mkdir app/code/local/Mage/Core/Model/Email
# cp app/code/core/Mage/Core/Model/Email/Template.php  app/code/local/Mage/Core/Model/Email/
2) Using your favourite editor open up Template.php and make changes at these lines
ini_set('SMTP', Mage::getStoreConfig('system/smtp/host'));
        ini_set('smtp_port', Mage::getStoreConfig('system/smtp/port'));
        $mail = $this->getMail();
        if (is_array($email)) {
            foreach ($email as $emailOne) {
+               # Fix for mini_sendmail
+                # $mail->addTo($emailOne, $name);
+                $mail->addTo($emailOne);
-                $mail->addTo($emailOne, $name);
            }
        } else {
+           # Fix for mini_sendmail
+           # $mail->addTo($email, '=?utf-8?B?'.base64_encode($name).'?=');
+           $mail->addTo($email);
-           $mail->addTo($email, '=?utf-8?B?'.base64_encode($name).'?=');
        }
        $this->setUseAbsoluteLinks(true);
        $text = $this->getProcessedTemplate($variables, true);
$mail->setSubject('=?utf-8?B?'.base64_encode($this->getProcessedTemplateSubject($variables)).'?=');
+       # Fix for mini_sendmail
+       # $mail->setFrom($this->getSenderEmail(), $this->getSenderName());
+       mail->setFrom($this->getSenderEmail());
-       $mail->setFrom($this->getSenderEmail(), $this->getSenderName());
3) Recompile (if using extension) to update includes
It is not a perfect solution, but should provide a fix until we find an alternative to mini_sendmail.

For more information click here

If the issue is not in 1.3.1 version then the solution can be found here 

Friday, 11 November 2011

Preventing Enter Button event from Form Submission

    if (document.layers)
        document.captureEvents(Event.KEYDOWN);
    document.onkeydown = function (evt) {
    var keyCode = evt ? (evt.which ? evt.which : evt.keyCode) : event.keyCode;
    if (keyCode == 13) {
        return false;
        //Your function here.
    }
    else
        return true;
    };

 OR

function preventEnter(evt) {
    var keyCode = evt ? (evt.which ? evt.which : evt.keyCode) : event.keyCode;
    if (keyCode == 13)
        return false;
    else
        return true;
};

Usage:  onkeydown="return preventEnter(event);"