Announcement

Collapse
No announcement yet.

Creating a single global variable from the results of a foreach loop

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Creating a single global variable from the results of a foreach loop

    Hello All,

    I'm trying to output all coupons used in an order into one global variable. Something like this:

    <mvt:foreach iterator="coupon" array="basket:coupons">&mvt:coupon:code; </mvt:foreach>

    ...then create a global variable from the resultant output, e.g. coupon1 coupon2 coupon3

    How do I do this? I've looked through Toolkit for some ideas but none seem to cater to this need.


    thanks,
    Michael


    #2
    You will need to create a new global variable and append (using the $) the coupon codes to that variable:

    Code:
    <mvt:foreach iterator="coupon" array="basket:coupons">
        <mvt:assign value="g.all_coupons" value="g.all_coupons $ ' ' $ l.settings:coupon:code" />
    </mvt:foreach>
    
    &mvt:global:all_coupons;
    Brennan Heyde
    VP Product
    Miva, Inc.
    [email protected]
    https://www.miva.com

    Comment


      #3
      Thanks Brennan!

      Just to correct the code a bit ("value" was twice):

      Code:
      <mvt:foreach iterator="coupon" array="basket:coupons">
          <mvt:assign name="g.all_coupons" value="g.all_coupons $' ' $ l.settings:coupon:code" />
      </mvt:foreach>
      cheers,
      Michael

      Comment

      Working...
      X