Results 1 to 9 of 9
  1. #1
    Join Date
    Apr 2007
    Posts
    182
    Plugin Contributions
    0

    Default function replace_accents(), Japanese, PayPal

    Hi Doc, well I am guessing that you are the one I will be talking to in this area of the forum.

    While I might get the not a bug tag here, bare with me and forgive me if this isn't a bug.

    I am making the Japanese pack for 1.3.8, encoded in UTF-8. The problem I am having is in using the PayPal IPN module. The function replace_accents()

    PHP Code:
    function replace_accents($s) {
        
    $s htmlentities($s);
        
    $s preg_replace ('/&([a-zA-Z])(uml|acute|elig|grave|circ|tilde|cedil|ring|quest|slash|caron);/''$1'$s);
        
    $s html_entity_decode($s);
        return 
    $s;
      } 
    This function being used in the $optionsCust array in the paypal.php file, is causing my Japanese characters to be turned into Junk.

    Now before I start to edit this code, I would like to ask the writer of the code what you see as the best fix and to let you know of the problem as I could see it being a problem for people using other languages that PayPal supports.

    Until then I am going to write a new function for this, and just use if for PayPal. Any heads up would be great here.

    A little final info for you. I am running zc in UTF-8 both English and Japanese also the database collation is utf8_general_ci, all this is to fix a lot of problems that happen if you run the cart in iso-8859-1, that you get with Japanese.


    Regards,
    CKD

  2. #2
    Join Date
    Jan 2004
    Posts
    66,364
    Blog Entries
    7
    Plugin Contributions
    274

    Default Re: function replace_accents(), Japanese, PayPal

    I suppose you could add a new statement as the first line of the function which would exit if the language is Japanese:
    Code:
        if ($_SESSION['languages_code'] == 'jp') return $s;
    This is just a quick fix and not necessarily the best approach. The function was added because of difficulties submitting accented characters during transmission to PayPal.
    .

    Zen Cart - putting the dream of business ownership within reach of anyone!
    Donate to: DrByte directly or to the Zen Cart team as a whole

    Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
    Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

  3. #3
    Join Date
    Apr 2007
    Posts
    182
    Plugin Contributions
    0

    Default Re: function replace_accents(), Japanese, PayPal

    In playing around with the function I found that this is the major problem.
    PHP Code:
    $s preg_replace ('/&([a-zA-Z])(uml|acute|elig|grave|circ|tilde|cedil|ring|quest|slash|caron);/''$1'$s); 
    I will add an if else for that part of the function. But maybe I can pinpoint it more.

    Will the override system work for the functions_general.php file?

    Also I don't know if its ok for me to tag a question on here, but PayPal splits the zip code for Japan zip1 and zip2

    I was thinking of trying to add this to the module
    PHP Code:
    substringData("customer['postcode']"0, -4),
     
    substringData("customer['postcode']",-4), 
    Any quick input on that would be great, if not I will play with it some more and if I still have a question on it, I will move it to the payment area of the forum.

    Regards,

    CKD

  4. #4
    Join Date
    Apr 2007
    Posts
    182
    Plugin Contributions
    0

    Default Re: function replace_accents(), Japanese, PayPal

    Hi Doc,

    In looking at this. I'm not going to pretend that I know more than I don't here.

    If you can explain this, or point me in the right direction to find the meaning of all that is in this string here.

    PHP Code:
    $s preg_replace ('/&([a-zA-Z])(uml|acute|elig|grave|circ|tilde|cedil|ring|quest|slash|caron);/''$1'$s); 
    I understand preg_replace, but things like uml|acute|.... , it seems that its hard to find a definition on what this. I find meanings but not really sure which apply here.

    If its too much, no problem. I am sure you are busy, and with enough time I will understand it.

    Regards,

    CKD

  5. #5
    Join Date
    Apr 2007
    Posts
    182
    Plugin Contributions
    0

    Default Re: function replace_accents(), Japanese, PayPal

    I guess I should also post my fix for anyone else with this problem.

    For 1.3.8a /includes/functions/functions_general.php line 1482 or so

    From this:
    PHP Code:
      function replace_accents($s) {
        
    $s htmlentities($s);
        
    $s preg_replace ('/&([a-zA-Z])(uml|acute|elig|grave|circ|tilde|cedil|ring|quest|slash|caron);/''$1'$s);
        
    $s html_entity_decode($s);
        return 
    $s;
      } 
    To this:
    PHP Code:
      function replace_accents($s) {
        
    $s htmlentities($s);
        
    //If for Japanese language
        
    if ($_SESSION['languages_code'] != 'ja'){
            
    $s preg_replace ('/&([a-zA-Z])(uml|acute|elig|grave|circ|tilde|cedil|ring|quest|slash|caron);/''$1'$s);
        }
        
    $s html_entity_decode($s);
        return 
    $s;
      } 

  6. #6
    Join Date
    Aug 2008
    Posts
    29
    Plugin Contributions
    0

    Default Re: function replace_accents(), Japanese, PayPal

    Will this fix work with other installs?

    I have an single language English cart but every time someone use accented special characters the do not pass through to pay-pal or to admin.

    Instead they come through as unreadable characters.

  7. #7
    Join Date
    Jan 2004
    Posts
    66,364
    Blog Entries
    7
    Plugin Contributions
    274

    Default Re: function replace_accents(), Japanese, PayPal

    To make it more universal than just for Japanese, I think I would implement it as follows:

    1. Replace the code posted by CrystalKoi in post#5 above with this:
    Code:
      function replace_accents($s) {
        $skipPreg = (defined('OVERRIDE_REPLACE_ACCENTS_WITH_HTMLENTITIES') && OVERRIDE_REPLACE_ACCENTS_WITH_HTMLENTITIES == 'TRUE') ? TRUE : FALSE;
        $s = htmlentities($s);
        if ($skipPreg == FALSE) {
          $s = preg_replace ('/&([a-zA-Z])(uml|acute|elig|grave|circ|tilde|cedil|ring|quest|slash|caron);/', '$1', $s);
        }
        $s = html_entity_decode($s);
        return $s;
      }
    2. Then, if you wish to enable the "skip" that the earlier "fix" was proposing, simply create a NEW file on your server:
    /includes/extra_datafiles/skip_accent_replacements.php
    containing just the following PHP code:
    Code:
    <?php
    define ('OVERRIDE_REPLACE_ACCENTS_WITH_HTMLENTITIES', 'TRUE');

    This is the approach taken in v1.3.9.
    .

    Zen Cart - putting the dream of business ownership within reach of anyone!
    Donate to: DrByte directly or to the Zen Cart team as a whole

    Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
    Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

  8. #8
    Join Date
    Jan 2004
    Posts
    66,364
    Blog Entries
    7
    Plugin Contributions
    274

    Default Re: function replace_accents(), Japanese, PayPal

    Quote Originally Posted by CrystalKoi View Post
    Will the override system work for the functions_general.php file?
    No.
    Quote Originally Posted by CrystalKoi View Post
    Also I don't know if its ok for me to tag a question on here, but PayPal splits the zip code for Japan zip1 and zip2

    I was thinking of trying to add this to the module
    PHP Code:
    substringData("customer['postcode']"0, -4),
     
    substringData("customer['postcode']",-4), 
    Really that should be treated as an entirely separate topic.
    If I recall correctly, it's already been discussed elsewhere, and the resolution was akin to this:
    Code:
        if ($order->customer['country']['iso_code_2'] == 'JP') $optionsCust['zip'] = substr($order->customer['postcode'], 0, 3) . '-' . substr($order->customer['postcode'], 3);
    (note the division happening at the 3rd character, not the 4th ... perhaps you can clarify on that?)
    .

    Zen Cart - putting the dream of business ownership within reach of anyone!
    Donate to: DrByte directly or to the Zen Cart team as a whole

    Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
    Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

  9. #9
    Join Date
    Apr 2007
    Posts
    182
    Plugin Contributions
    0

    Default Re: function replace_accents(), Japanese, PayPal

    Hi DrByte,

    Most of the issues have been dealt with. With the start up of our new company (same services, more people, more ability), we have not been able to release the new version just yet. We hope to in the future, I will review what you said and apply that too the pack.

    Regards,

    CKD

 

 

Similar Threads

  1. Replies: 3
    Last Post: 11 Jan 2011, 02:53 AM
  2. Japanese Yen and Paypal - JPY error 10401
    By CrystalKoi in forum Bug Reports
    Replies: 14
    Last Post: 17 Dec 2009, 06:38 AM
  3. Replies: 2
    Last Post: 29 Nov 2009, 06:01 AM
  4. Paypal Credit Card page encoding problem using Zen Cart 1.30 Japanese version
    By caborela in forum All Other Contributions/Addons
    Replies: 0
    Last Post: 24 Jun 2009, 04:04 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
disjunctive-egg
Zen-Cart, Internet Selling Services, Klamath Falls, OR