Tuesday, 26 March 2013

Funny Typo Errors in Magento EE 1.12

Few Day back i came across an issue in Magento Admin. Though its not a potentially a great functionality bug, i dig in to that because of our great testing team and ended up with funny typo error.


I though its the bug only in Magento EE 1.12, unfortunately :) its there in all the version and in multiple place. Ok Now coming to the issue.

"Success Message is not clearing even after i update something".

Lets say i am applying a promo which gives me success message or let say i am getting some error message in header, even after rectifying that error in cart it remains the same. Means the Error message not cleared.

Problem is because of

 if(this.loadingAreas.indexOf('message'==-1)) this.loadingAreas.push('message');

Refer the indexOf function above which is there in "js/mage/adminhtml/sales.js". It should be  if(this.loadingAreas.indexOf('message')==-1)

element.name.indexOf("[" + name[1] + "]") != -1 && messages[i].value != "") -- Line 821

area.indexOf('items' != -1) -- Line 853

I though it was actidental but it seems like intentional :) .... but any way we have to correct  if you are facing any funniest problem like this in Magento Admin hope you got some idea to dig further......

Sunday, 25 November 2012

Avoid Document Expire while hitting browser back





Using  Get Post Get rule you can avoid this.
  • Let say I have example1.php example2.php & example3.php
  • I am posting some value from example1.php to example2.php then i did all the DB stuff as per my need and rendered the page (Not Redirected - Just posted and the page got rendered).
  • After submitting values from example2.php to sometest.php and I have redirected the page to example3.php. Now if you click browser back the Document will Expire.
    • To Avoid this we can post the values from example1.php to some other PHP and then we need to Redirect the user to example2.php
    • This is the GPG rule which every developer needs to follow to avoid Document expire and also to avoid redundant entry in DB on refreshing the page.

Thursday, 30 August 2012

Magento DB locked while saving product

If you facing db lock while saving your product don't worry just you want to do the below.

Check the problem is due to your local module queries. If you have written any observer while before save or on after save.

If not take a backup of below listed tables and and truncate. Surely it will solve your problem i did the same and its worked for me.
 

truncate table sales_flat_quote;
truncate table sales_flat_quote_address;
truncate table sales_flat_quote_address_item;
truncate table sales_flat_quote_item;
truncate table sales_flat_quote_item_option;
truncate table sales_flat_quote_payment;
truncate table sales_flat_quote_shipping_rate;



Hip Hip Hurrey .............

Enjoy coding in magento............

Monday, 5 March 2012

SMTP Mail configuration Magento

1. You need to override Mage_Core_Model_Email_Template [ app/code/core/Mage/Core/Model/Email/Template.php need to be override].
2. Create a Module in your app/code/local/Company/Core
3. Create a config.xml in app/code/local/Company/Core/etc, copy and paste the below code in that file.

<?xml version="1.0"?>
<config>
        <modules>
        <Companyname_Core>
            <version>0.1.0</version>
        </Companyname_Core>
    </modules>
    <global>
        <models>
            <core>
                <rewrite>                   
                    <email_template>Companyname_Core_Model_Email_Template</email_template>
                </rewrite>
            </core>
        </models>
    </global>
</config>

3. Create a Template.php in app/code/local/Company/Core/Model/Email/, copy and paste the below code in that file.

<?php
class Companyname_Core_Model_Email_Template extends Mage_Core_Model_Email_Template
{
    public function send($email, $name=null, array $variables = array())
    {
   
        if (!$this->isValidForSend()) {
            Mage::logException(new Exception('This letter cannot be sent.')); // translation is intentionally omitted
            return false;
        }

        $emails = array_values((array)$email);
        $names = is_array($name) ? $name : (array)$name;
        $names = array_values($names);
        foreach ($emails as $key => $email) {
            if (!isset($names[$key])) {
                $names[$key] = substr($email, 0, strpos($email, '@'));
            }
        }
       
        $variables['email'] = $email;
        $variables['name'] = $name;
       
        ini_set('SMTP', Mage::getStoreConfig('system/smtp_settings/host'));
        ini_set('smtp_port', Mage::getStoreConfig('system/smtp_settings/port'));
       
        $host = Mage::getStoreConfig('system/smtp_settings/host');
        $smtpuser = Mage::getStoreConfig('system/smtp_settings/username');
        $smtpuserpass = Mage::getStoreConfig('system/smtp_settings/password');
        $port = Mage::getStoreConfig('system/smtp_settings/port');
        $auth = strtolower(Mage::getStoreConfig('system/smtp_settings/auth'));
        $mail = $this->getMail();
       
        $setReturnPath = Mage::getStoreConfig(self::XML_PATH_SENDING_SET_RETURN_PATH);
        switch ($setReturnPath) {
            case 1:
                $returnPathEmail = $this->getSenderEmail();
                break;
            case 2:
                $returnPathEmail = Mage::getStoreConfig(self::XML_PATH_SENDING_RETURN_PATH_EMAIL);
                break;
            default:
                $returnPathEmail = null;
                break;
        }
       
        if ($returnPathEmail !== null) {
            $mailTransport = new Zend_Mail_Transport_Sendmail("-f".$returnPathEmail);
            Zend_Mail::setDefaultTransport($mailTransport);
        }
       
        foreach ($emails as $key => $email) {
            $mail->addTo($email, '=?utf-8?B?' . base64_encode($names[$key]) . '?=');
        }
       
        $this->setUseAbsoluteLinks(true);
        $text = $this->getProcessedTemplate($variables, true);
       
        if($this->isPlain()) {
            $mail->setBodyText($text);
        } else {
            $mail->setBodyHTML($text);
        }
        $config = array('port' =>$port);
        if($auth != 'NONE'){
            $config = array('port' =>$port, 'auth' => $auth, 'username' => $smtpuser, 'password' => $smtpuserpass);
        }
        $transport = new Zend_Mail_Transport_Smtp($host, $config);
       
        $mail->setSubject('=?utf-8?B?'.base64_encode($this->getProcessedTemplateSubject($variables)).'?=');
        $mail->setFrom($this->getSenderEmail(), $this->getSenderName());
       
        try {
            $mail->send($transport); // Zend_Mail warning.. // Note. here the $transport parameter contains the configuration for smtp authentication
            $this->_mail = null;
        }
        catch (Exception $e) {
            return false;
        }
        return true;
    }
}

Thats all now you can enjoy sending mail with smtp in magento................ :)

Wednesday, 7 December 2011

PHP - JAVA BRIDGE

1) Download PHP-Java bridge here.

2) Extract the Zip there you can find JavaBridge.war extract that too.

3) You can find JavaBridge.jar here [JavaBridge.war\WEB-INF\lib\]. Copy that file to your lib\php\modules [LINUX]. For windows xampp/php/ext.

4) Run this command 

java -jar /usr/lib/php/modules/JavaBridge.jar HTTP_LOCAL:8088 3 JavaBridge.log

5) Make sure the path in above command is matches your path where you have placed the JavaBridge.jar

6)Make sure port 8088 is not listening some other service like tomcat.

7)Extract JavaBridge.jar and copy the java folder which is present in JavaBridge.jar\META-INF\  to wherever you want.  [Don't change the existing one which is present in your ext or module folder] 

8) Then run the below. It will display the info and java bridge version and some other properties.

9) require_once("java/Java.inc"); [Present in the below coding]. You need to change the path as per your requirement.
<?php
/* load extension and check it */
function check_extension() {
  if(!extension_loaded('java')) {
    $sapi_type = php_sapi_name();
    if ($sapi_type == "cgi" || $sapi_type == "cgi-fcgi" || $sapi_type == "cli") {
      if(!(PHP_SHLIB_SUFFIX=="so" && @dl('java.so'))&&!(PHP_SHLIB_SUFFIX=="dll" && @dl('php_java.dll'))&&!(include_once("java/Java.php"))) {
          echo "java extension not installed.";
          exit(2);
      }
    } else {
      require_once("java/Java.inc");
    }
  }
  if(!function_exists("java_get_server_name")) {
    echo "Fatal: The loaded java extension is not the PHP/Java Bridge";
    exit(7);
  }
}

check_extension();
if(java_get_server_name()!=null){

  phpinfo();
  print "\n\n";

  $v = new Java("java.lang.System");
  $p = @$v->getProperties();
  if($ex=java_last_exception_get()) {
    $trace = new Java("java.io.ByteArrayOutputStream");
    $ex->printStackTrace(new java("java.io.PrintStream", $trace));
    echo "Exception $ex occured:<br>\n" . $trace . "\n";
    exit(1);
  }
  $arr=java_values($p);
  foreach ($arr as $key => $value) {
    print $key . " -> " .  $value . "<br>\n";
  }
  echo "<br>\n";
  $Util = new JavaClass("php.java.bridge.Util");
  echo "JavaBridge back-end version: ".java_values($Util->VERSION)."<br>\n";
  echo "<br>\n";

  // java.util.Date example
  $formatter = new Java('java.text.SimpleDateFormat',
                        "EEEE, MMMM dd, yyyy 'at' h:mm:ss a zzzz");

  print $formatter->format(new Java('java.util.Date'));
  echo "<br>\n";


 } else {

  phpinfo();
  print "\n\n";

  /* java_get_server_name() == null means that the back-end is not
   running */
  if(PHP_SHLIB_SUFFIX=="so") $ext_name="java.so";
  else if(PHP_SHLIB_SUFFIX=="dll") $ext_name="php_java.dll";
  else $ext_name="unknown suffix: ".PHP_SHLIB_SUFFIX;

  echo "Error: The PHP/Java Bridge back-end is not running.\n";
  echo "\n";
  echo "Please start it and/or check if the directory\n";
  echo "\n\t".ini_get("extension_dir")."\n\n";
  echo "contains \"$ext_name\" and \"JavaBridge.jar\".\n";
  echo "\n";
  echo " Check if the following values are correct:\n\n";
  echo "\tjava.java_home = ".ini_get("java.java_home")."\n";
  echo "\tjava.java = ".ini_get("java.java")."\n\n";
  echo "If you want to start the back-end automatically, disable:\n\n";
  echo "\tjava.socketname = ".ini_get("java.socketname")."\n";
  echo "\tjava.hosts = ".ini_get("java.hosts")."\n";
  echo "\tjava.servlet = ".ini_get("java.servlet")."\n";
  echo "\n";
  echo "If that still doesn't work, please check the \"java command\" above and\n";
  echo "report this problem to:\n\n";
  echo "\tphp-java-bridge-users@lists.sourceforge.net.\n";

}
?>
Reference taken From :: http://php-java-bridge.sourceforge.net/pjb/


Wednesday, 16 November 2011

Jquery history plugin in magento

Main aspect of this is , at the time of using ajax powered search some one has search some thing and they have refreshed the page then they need to make the search another one time but using this plugin you can achieve the same result after the user have refreshed their page. Although it will work in the startergy for browser back and front button

Add history plugin js in your layout.xml as below [You can download the jquery plugin here :  http://tkyk.github.com/jquery-history-plugin/]

<reference name="head">
      <action method="addJs"><script>javascript/jquery.history.js</script></action>
</reference>

And then add the hash (#store | #product) to your href for example you have store and product search in your application the it will goes like below.

href="#store" onclick="jQuery.history.load('store');" [to search stores]

href="#product" onclick="jQuery.history.load('product');" [to search products]


You need to add the below script in your basic template if your using for 1column page then you need to add the below snippet inside the head tag.

<script type="text/javascript">
    //<![CDATA[
        $j(document).ready(function(){
        var flag = false;
            $j.history.init(function(url){
                if(!flag)
                {
                    flag =true;
                    SwapBwnStoreProducts(url == "" ? "" : url);
                }else
                    SwapBwnStoreProducts(url == "" ? "product" : url);
            });
        });
        //]]>
    </script>

use the below function for your ajax call you can write this function in a separate file and then you need to include the same in the layout xml of your module.

function SwapBwnStoreProducts(swap){  
     ajax call goes here
 }