Sunday, 30 March 2014

window.onbeforeunload ajax request problem

From last few hours I was facing a problem with window.onbeforeunload. My need was to save form data(partial saving) by ajax, in case user opts to close the browser, reload the window or close the window. I was using following code :

//Old Code
window.onbeforeunload = function () {
              saveFormData(); 
  return msg;
};

It was saving my content but the return statement was showing me a confirmation message with options ‘Leave Page’ and ‘Stay on Page’. It was so embarrassing. Without return statement it was not saving my data at all.

After spending lot of time on internet and brainstorming a little found the following solution:

//New Code

$(window).bind('beforeunload', function () {
                //this will work only for Chrome
                saveFormData();
});

$(window).bind("unload", function () {
 //this will work for other browsers
 saveFormData();
});

It worked like a charm for me. Hopefully it will help someone else as well on internet.


Thanks!!!!! Enjoy Programming :)



Sunday, 23 March 2014

Magento : Add “Subscribe to Newsletter” checkbox on Contact Form


To add "Subscribe to Newsletter" checkbox on Contact form, follow following steps: 

1) Go to contacts/form.phtml file of your selected theme.

2) Place following code in the file as per your requirement :
    <input type="checkbox" name="subscribe_newsletter"><?php echo    
     Mage::helper('contacts')->__(' Subscribe to Newsletter ') ?>

3) Now go to \app\code\local\Mage\Contacts\controllers\IndexController.php file 
    and put following code in postAction() function :

    Note: If you are not able to find Mage/Contacts.... folder in local directory please create new one and refer to the link (http://www.magentocommerce.com/wiki/5_-_modules_and_development/0_-_module_development_in_magento/how_to_create_a_local_copy_of_app_code_core_mage

/*Start of code*/

            if(isset($_POST['subscribe_newsletter'])){

                        $email = $_POST['email'];
                        $status = Mage::getModel('newsletter/subscriber')->subscribe($email);
                        if ($status == Mage_Newsletter_Model_Subscriber::STATUS_NOT_ACTIVE) {
Mage::getSingleton('customer/session') ->addSuccess($this->__('Confirmation request has been sent.'));
                        }
                        else
{
Mage::getSingleton('customer/session') ->addSuccess($this->__('Thank you for your newsletter subscription.'));
                        }
            }

       /*End of code*/


That’s it and you are done. Hopefully it will help you guys as well.


Thanks!!!!!!!! Enjoy Programming J


      

Sunday, 16 March 2014

Magento 1.7 not showing Google Analytics code in application.

Recently, faced an issue with Google Analytics code implementation in Magento version 1.7. Done with all the settings to implement Google Analytics, still it was not showing Google Analytics code in my Magento application.

Searched a little and came up with following solution.

Go to \app\design\frontend\default\mytheme\layout\googleanalytics.xml file :

Replace
<reference name="after_body_start">
        <block type="googleanalytics/ga" name="google_analytics" as="google_analytics" />
</reference>

Code Block 

With
<reference name="after_body_start">
        <block type="googleanalytics/ga" name="google_analytics" as="google_analytics" 
            template="googleanalytics/ga.phtml" />
 </reference>

Above code worked for me. Hopefully it will work for others as well.


Thanks!!!!!!!!! Enjoy Programming :)
 

Gmail: Download blocked file

Hi, today we are going to learn, how to download blocked file in gmail. Sometimes you see following message in gmail: and you can...