Page 1 of 2 12 LastLast
Results 1 to 10 of 13
  1. #1
    Join Date
    Jul 2007
    Posts
    342
    Plugin Contributions
    7

    Default please explain this php code

    Hi
    Can someone please explain to me what is happening here with this code:
    <?php echo (isset($sInfo->products_name)) ? $sInfo->products_name . ' <small>(' . $currencies->format($sInfo->products_price) . ')</small>' : zen_draw_products_pull_down('products_id', 'size="5" style="font-size:10px"', $customprice_array, true, $_GET['add_products_id'], true); echo zen_draw_hidden_field('products_price', (isset($sInfo->products_price) ? $sInfo->products_price : '')); ?>

    Thanks
    Ian

  2. #2
    Join Date
    Jul 2005
    Location
    Upstate NY
    Posts
    22,010
    Plugin Contributions
    25

    Default Re: please explain php code

    This code uses two instances of a compact form of "if/then/else" test.

    The general form is

    [php code which can be true or false] ? [code to be executed if true] : [code to be executed if false] ;

    I'll leave you the exercise of deciphering it given the form.

  3. #3
    Join Date
    Jul 2005
    Location
    Upstate NY
    Posts
    22,010
    Plugin Contributions
    25

    Default Re: please explain php code

    The second part of this looks incorrectly written.

    echo zen_draw_hidden_field('products_price', (isset($sInfo->products_price) ? $sInfo->products_price : ''));

    ? $sInfo->products_price : ''));

    should be

    ? $sInfo->products_price)) : ''));

    so that both close parentheses are output in either case.

  4. #4
    Join Date
    Jul 2007
    Posts
    342
    Plugin Contributions
    7

    Default Re: please explain php code

    Thanks for the help.
    'zen_draw_products_pull_down ' I understand that this produces a box but is this set somewhere else in files? Hope I have explained what I mean --
    Have a Happy, Healthy and Prosperous New Year

  5. #5
    Join Date
    Jul 2005
    Location
    Upstate NY
    Posts
    22,010
    Plugin Contributions
    25

    Default Re: please explain php code

    Anything like that which is followed by parentheses () is a function, which will probably be in one of the /includes/functions/ folders.

    Search in Tools > Developers Toolkit for zen_draw_products_pull_down and you will find the file where it is created.

  6. #6
    Join Date
    Jan 2004
    Posts
    66,443
    Plugin Contributions
    279

    Default Re: please explain php code

    Quote Originally Posted by gjh42 View Post
    The second part of this looks incorrectly written.

    echo zen_draw_hidden_field('products_price', (isset($sInfo->products_price) ? $sInfo->products_price : ''));

    ? $sInfo->products_price : ''));

    should be

    ? $sInfo->products_price)) : ''));

    so that both close parentheses are output in either case.
    I'm not sure I agree. The parenthesis in the original post are correct.
    .

    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.

  7. #7
    Join Date
    Jan 2004
    Posts
    66,443
    Plugin Contributions
    279

    Default Re: please explain php code

    Quote Originally Posted by ianhg View Post
    Hi
    Can someone please explain to me what is happening here with this code:
    <?php echo (isset($sInfo->products_name)) ? $sInfo->products_name . ' <small>(' . $currencies->format($sInfo->products_price) . ')</small>' : zen_draw_products_pull_down('products_id', 'size="5" style="font-size:10px"', $customprice_array, true, $_GET['add_products_id'], true); echo zen_draw_hidden_field('products_price', (isset($sInfo->products_price) ? $sInfo->products_price : '')); ?>
    In english:
    If the product name is known, display it, followed by its price in small font.
    Otherwise, draw a pulldown menu containing a list of products, excluding the products in $customprice_array, defaulting to the selected add_products_id from the browser URL, and the display is to include the product ID and model number.
    Then it draws a hidden field for products_price using the product price if known, or blank if not known.
    That's the way it works in the admin. If it was used in the storefront, there would be fewer parameters used.

    As gjh42 said, locate the function and you can study what each of the parameters do if you're trying to customize it somehow.
    .

    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
    Jul 2005
    Location
    Upstate NY
    Posts
    22,010
    Plugin Contributions
    25

    Default Re: please explain php code

    If it's part of ZC core, I would expect it to be correct... What I know of that form comes from looking at ZC code. I've never been able to find mention of it in books or online resources (that would probably be easier if I knew what to call it.)

    So does the
    ? $sInfo->products_price : ''));
    end its alternate output at the first parenthesis? It must be so, unless it's ok for the
    zen_draw_hidden_field('products_price', (
    to never close.

    What is the rule for ending the alternate? Or better yet, what is this form called, so I can look it up and learn more about it?

  9. #9
    Join Date
    Jan 2004
    Posts
    66,443
    Plugin Contributions
    279

    Default Re: please explain php code

    Quote Originally Posted by gjh42 View Post
    What I know of that form comes from looking at ZC code. I've never been able to find mention of it in books or online resources (that would probably be easier if I knew what to call it.)

    So does the
    ? $sInfo->products_price : ''));
    end its alternate output at the first parenthesis? It must be so, unless it's ok for the
    zen_draw_hidden_field('products_price', (
    to never close.

    What is the rule for ending the alternate? Or better yet, what is this form called, so I can look it up and learn more about it?
    That's the syntax of the "Ternary Operator" comparison/condition expressions.
    http://www.php.net/manual/en/language.expressions.php
    http://www.php.net/manual/en/languag...comparison.php
    .

    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.

  10. #10
    Join Date
    Jul 2005
    Location
    Upstate NY
    Posts
    22,010
    Plugin Contributions
    25

    Default Re: please explain php code

    So the parenthesis has a higher precedence than the ternary operator, and will close it out (or limit the beginning) if appropriate. Actually, I think I've used it that way, but didn't remember that when looking at the code above...

    Thanks, DrByte!

 

 
Page 1 of 2 12 LastLast

Similar Threads

  1. Can someone please explain how I should setup shipping modules for this situation?
    By kjl1975 in forum Built-in Shipping and Payment Modules
    Replies: 0
    Last Post: 2 Dec 2010, 12:08 AM
  2. Please explain this -- changed text and now alignment is off
    By lexcor in forum Templates, Stylesheets, Page Layout
    Replies: 7
    Last Post: 4 Oct 2007, 04:22 AM
  3. Please Help. I can't explain this
    By Kimberl in forum Installing on a Linux/Unix Server
    Replies: 9
    Last Post: 20 Jul 2007, 02:00 PM

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