Results 1 to 6 of 6
  1. #1
    Join Date
    Aug 2007
    Location
    Gijón, Asturias, Spain
    Posts
    2,829
    Plugin Contributions
    31

    Default controlling/forcing session language

    I am working on an auto emailer script called by a cron job which runs through past orders and sends an invitation to comment on the purchase.
    I have a dual language shop and so the emails have to be in the correct language.
    I have an extra field for the order record which records the order language so it’s not a problem to retrieve the orders per language.
    The problem is forcing zen_mail to use the correct language defines for the email template.

    ie. the cron job would call something like emailer.php?lang=en or emailer.php?lang=es,

    the script will pull out the english or spanish orders and use zen_mail to send them.

    I can use specific (en or es) defines to put the correct language text in the body of the emails but once it goes through zen_mail it uses whatever language it feels like (it seems) to add in the template block email footer text/copyright/anti-spam etc.

    In the script I have set the session variables to the relevant language values to try get zen_mail to cooperate but it doesn’t work.
    $_SESSION['language'] = $language;
    $_SESSION['languages_id'] = $lang_id;
    $_SESSION['languages_code'] = $lang_code;

    If I use this locally, the footer-text language used in the email is whatever I have chosen in the shop front but since this is being run from a cron
    lynx --dump blah/blah/emailer.php?lang=en
    I am guessing it is making its language decision on the browser language?

    In any case I seem to regularly come across this issue of trying to force a session language so I would appreciate some insight into this issue or some general guidance on how to control it within Zen Cart as I evidently don’t understand it clearly enough,

    Thanks
    Steve

    ps preview/editing of post not working for me in Chrome or FFox, text field always empty on preview.
    Steve
    github.com/torvista: BackupMySQL, Structured Data, Multiple Copy-Move-Delete, Google reCaptcha, Image Checker, Spanish Language Pack and more...

  2. #2
    Join Date
    Jan 2004
    Posts
    66,444
    Plugin Contributions
    279

    Default Re: controlling/forcing session language

    The language constants are loaded when application_top is run. And, since constants are, well, constant, they can't be altered during the same execution cycle.

    Definitely that will pose problems for batched scripts like you're doing, where the language is not based on the visitor, but rather is constantly changing due to differences in your input data.

    Unfortunately, changing that is a big architectural alteration.

    Perhaps consider rewriting your cron job to accept a language parameter, and use that both to set the language id in the session and filter the db queries to just those orders which used that language? Then have additional cron jobs for the other languages you have on your site?
    .

    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
    Aug 2007
    Location
    Gijón, Asturias, Spain
    Posts
    2,829
    Plugin Contributions
    31

    Default Re: controlling/forcing session language

    Perhaps consider rewriting your cron job to accept a language parameter, and use that both to set the language id in the session and filter the db queries to just those orders which used that language? Then have additional cron jobs for the other languages you have on your site?
    That is exactly what I do have.

    Two cron jobs, one with ...?lang=en and the other with ....?lang=es which work fine to select the orders and get language-dependent custom text ( require('autoemailer_'.$lang_code.'.php'); ) constants used prior to the zen_mail function call.

    If I set the SESSION variable set with the three language variables (belt and braces) before it calls application_top, it gets changed:
    $_GET['lang']=en
    english is set
    Pre application top:
    $_SESSION['language=']=english
    $_SESSION['language_id=']=1
    $_SESSION['languages_code=']=en

    Post application top:
    $_SESSION['language=']=spanish
    $_SESSION['language_id=']=2
    $_SESSION['languages_code=']=es


    Testing locally this change is driven by whatever language is chosen in another tab of the browser. I can understand that, but when there is no other tab open/with the cron job how does it make the decision and how can I override it?
    Steve
    github.com/torvista: BackupMySQL, Structured Data, Multiple Copy-Move-Delete, Google reCaptcha, Image Checker, Spanish Language Pack and more...

  4. #4
    Join Date
    Aug 2007
    Location
    Gijón, Asturias, Spain
    Posts
    2,829
    Plugin Contributions
    31

    Default Re: controlling/forcing session language

    So, I find that the pre-existing $_SESSION values are wiped and replaced in sessions.php at this point:

    $temp = session_start();

    if I set a extra $_SESSION variable in my external script and make the above call conditional, I can maintain the language as previously defined:

    if ($_SESSION['lang_override'] != 'true') $temp = session_start();

    Seems to work fine.

    I did look at setting the sesson_name etc. but didn't make any progress with that.
    Steve
    github.com/torvista: BackupMySQL, Structured Data, Multiple Copy-Move-Delete, Google reCaptcha, Image Checker, Spanish Language Pack and more...

  5. #5
    Join Date
    Jan 2004
    Posts
    66,444
    Plugin Contributions
    279

    Default Re: controlling/forcing session language

    You can't set $_SESSION variables before the session starts, else they'll be wiped out.

    I suppose you could customize the init_languages.php code to read your command-line parameters instead of only responding to $_GET parameters, when setting language during application_top.
    .

    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.

  6. #6
    Join Date
    Aug 2007
    Location
    Gijón, Asturias, Spain
    Posts
    2,829
    Plugin Contributions
    31

    Default Re: controlling/forcing session language

    Well, it seems just adding a full parameter of

    &language=es or en
    sets the session language without changing any code.

    I'm sure I tried that before and it didn't work but looking at init_languages indicates that it should work if the GET is set.

    Another one I'll put down to experience.
    Steve
    github.com/torvista: BackupMySQL, Structured Data, Multiple Copy-Move-Delete, Google reCaptcha, Image Checker, Spanish Language Pack and more...

 

 

Similar Threads

  1. v152 Forcing a script to use constants from a specific language
    By torvista in forum Addon Language Packs
    Replies: 3
    Last Post: 17 Jan 2014, 12:16 AM
  2. Banner displayed according to session language
    By jean-luc in forum Templates, Stylesheets, Page Layout
    Replies: 1
    Last Post: 30 Aug 2009, 07:44 PM
  3. zen_image ADD LANGUAGE SESSION
    By xhidex in forum Templates, Stylesheets, Page Layout
    Replies: 3
    Last Post: 18 Nov 2008, 02:51 PM
  4. controlling shipping
    By whiteboxer in forum Setting Up Categories, Products, Attributes
    Replies: 1
    Last Post: 18 Jul 2006, 07:39 AM

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