Results 1 to 7 of 7
  1. #1
    Join Date
    Oct 2012
    Posts
    52
    Plugin Contributions
    0

    help question Get max value from attributes values

    hello
    in checkout_confirmation file, i find the code nl2br(zen_output_string_protected($order->products[$i]['attributes'][$j]['value']))
    i want to use max() for my attributes values (all my attributes avlues are numbers)
    i tried echo max(zen_output_string_protected($order->products[$i]['attributes'][$j]['value']))
    and echo max(array(zen_output_string_protected($order->products[$i]['attributes'][$j]['value'])))
    they don't work
    any ideas?
    Last edited by tips007; 14 Oct 2012 at 11:55 AM.

  2. #2
    Join Date
    Oct 2012
    Posts
    52
    Plugin Contributions
    0

    Default Re: Get max value from attributes values

    each product has only one attribute, all the attribute values are numbers

    ex.
    product A with attribute value 6
    product B with attribute value 3
    product C with attribute value 8

    if i add <? php echo zen_output_string_protected($order->products[$i]['attributes'][$j]['value']); ?> to tpl_checkout_confirmation_default
    it displays
    638

    if i add <? php echo zen_output_string_protected($order->products[$i]['attributes'][$j]['value']) . '<p>'; ?>
    it displays
    6
    3
    8

    now i want to get the max number from 6, 3, 8

    the code below doesn't work
    max(array(zen_output_string_protected($order->products[$i]['attributes'][$j]['value'])))
    max(zen_output_string_protected($order->products[$i]['attributes'][$j]['value']))

    is there anyone could help? thanks

  3. #3
    Join Date
    Oct 2012
    Posts
    52
    Plugin Contributions
    0

    Default Re: Get max value from attributes values

    use the code below
    PHP Code:
    <? php 
    for ($i=0, $n=sizeof($order->products); $i<$n; $i++) { 
       for ($j=0, $n2=sizeof($order->products[$i]['attributes']); $j<$n2; $j++) {
          echo zen_output_string_protected($order->products[$i]['attributes'][$j]['value']);
       }
    }
    ?>
    you'll get the result
    638

    if you add the <p> to it, such as echo zen_output_string_protected($order->products[$i]['attributes'][$j]['value']) . '<p>';
    you'll get
    6
    3
    8

    now i want to get the max number from 6, 3, 8
    any one could help?

  4. #4
    Join Date
    Oct 2012
    Posts
    52
    Plugin Contributions
    0

    Default Re: Get max value from attributes values

    anyone?

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

    Default Re: Get max value from attributes values

    PHP Code:
    $attrib_max 0;
    for (
    $i=0$n=sizeof($order->products); $i<$n$i++) { 
       for (
    $j=0$n2=sizeof($order->products[$i]['attributes']); $j<$n2$j++) {
          
    $attrib_max = ($attrib_max $order->products[$i]['attributes'][$j]['value'])? $attrib_max$order->products[$i]['attributes'][$j]['value'];
       }

    $attrib_max will end up as the max of the attribute values.

  6. #6
    Join Date
    Oct 2012
    Posts
    52
    Plugin Contributions
    0

    Default Re: Get max value from attributes values

    you are a genius!
    thank you

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

    Default Re: Get max value from attributes values

    A simpler version of the comparison uses the PHP max() function:
    PHP Code:
          $attrib_max max($attrib_max$order->products[$i]['attributes'][$j]['value']); 

 

 

Similar Threads

  1. v151 How to get the customer country value from checkout_shipping page?
    By kapsolas in forum General Questions
    Replies: 7
    Last Post: 11 Jan 2013, 07:06 PM
  2. v139h change to other attributes and values from first attribute
    By Dremote in forum General Questions
    Replies: 2
    Last Post: 21 Nov 2012, 07:28 PM
  3. attributes value from database
    By dubnium in forum Setting Up Categories, Products, Attributes
    Replies: 1
    Last Post: 13 Dec 2010, 04:27 PM
  4. Cross sell max values
    By Parafanaylya in forum All Other Contributions/Addons
    Replies: 0
    Last Post: 19 Jul 2006, 06:10 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