Announcement

Collapse
No announcement yet.

IF inside FOREACH for payments

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

    IF inside FOREACH for payments

    Hi! I'm trying to figure out to write an expression to compare the value of the current variable inside a foreach loop, in PHP this is straight forward

    Code:
    foreach($array as $value){
        if ($value=='visa'){
            // do something
        }
    
    }
    if MVT this is sort of what I'm trying to do

    Code:
    <select name="PaymentMethod" id="PaymentMethod">
        <mvt:foreach array="paymentmethods" iterator="method">
            <mvt:if expr="l.settings:paymentmethods:code NE visa">
                <option value="&mvte:method:module;:&mvte:method:code;">&mvt:method:name;</option>
            </mvt:if>
        </mvt:foreach>
    </select>
    The above code doesn't work, i don't get a compiling error but i just don't get any options.

    I basically want to skip a certain payment method if it's not available at the moment, I can't remove them from the backend because it says the payment method is in used by another order...

    Any help would be appreciated!

    #2
    Re: IF inside FOREACH for payments

    Your on the right track, just missing single quotes wrapped around visa since it is a string.

    Try this:
    Code:
    <select name="PaymentMethod" id="PaymentMethod">
        <mvt:foreach array="paymentmethods" iterator="method">
            <mvt:if expr="l.settings:paymentmethods:code NE 'visa' ">
                <option value="&mvte:method:module;:&mvte:method:code;">&mvt:method:name;</option>
            </mvt:if>
        </mvt:foreach>
    </select>
    ALso you have NE which is Not Equal. If you need Equal it would be EQ
    Brennan Heyde
    VP Product
    Miva, Inc.
    [email protected]
    https://www.miva.com

    Comment


      #3
      Re: IF inside FOREACH for payments

      Thank you for the answer! that worked!

      Comment

      Working...
      X