Announcement

Collapse
No announcement yet.

Can't access data from shippingmethods array

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

    Can't access data from shippingmethods array

    I am trying to write some code to conditionally display some text on OSEL if Priority Mail Flat Rate Box is one of the shipping options presented to the customer. Using Toolbelt varlist I see:


    Code:
    l.all_settings:shippingmethods[1]:code     &mvt:shippingmethods[1]:code;    PARCEL
    l.all_settings:shippingmethods[1]:formatted_price     &mvt:shippingmethods[1]:formatted_price;    $12.09
    l.all_settings:shippingmethods[1]:module     &mvt:shippingmethods[1]:module;    mvusps
    l.all_settings:shippingmethods[1]:name     &mvt:shippingmethods[1]:name;    U.S.P.S. Parcel Post
    l.all_settings:shippingmethods[1]:price     &mvt:shippingmethods[1]:price;    12.09
    l.all_settings:shippingmethods[2]:code     &mvt:shippingmethods[2]:code;    PRIORITY
    l.all_settings:shippingmethods[2]:formatted_price     &mvt:shippingmethods[2]:formatted_price;    $16.70
    l.all_settings:shippingmethods[2]:module     &mvt:shippingmethods[2]:module;    mvusps
    l.all_settings:shippingmethods[2]:name     &mvt:shippingmethods[2]:name;    U.S.P.S. Priority Mail
    l.all_settings:shippingmethods[2]:price     &mvt:shippingmethods[2]:price;    16.7
    l.all_settings:shippingmethods[3]:code     &mvt:shippingmethods[3]:code;    PRIORITYFL
    l.all_settings:shippingmethods[3]:formatted_price     &mvt:shippingmethods[3]:formatted_price;    $15.45
    l.all_settings:shippingmethods[3]:module     &mvt:shippingmethods[3]:module;    mvusps
    l.all_settings:shippingmethods[3]:name     &mvt:shippingmethods[3]:name;    U.S.P.S. Priority Mail Large Flat Rate Box
    l.all_settings:shippingmethods[3]:price     &mvt:shippingmethods[3]:price;    15.45
    OK, so I should be able to iterate over the array to test for the presence of the Flat Rate Box. For instance, code = PRIORITYFL.


    I have tried every combination I can think of, but cannot get it to return the list of codes, names, etc.


    Code:
    <mvt:foreach iterator="shippingmethods" array="l.all_settings:shippingmethods">
            Test: &mvt:shippingmethods:code; <br>
    </mvt:foreach>
    ...yields nothing. Same for:


    Code:
    <mvt:foreach iterator="shippingmethods" array="shippingmethods">
        
    <mvt:foreach iterator="code" array="shippingmethods:code">
    
    <mvt:foreach iterator="code" array="l.all_settings:shippingmethods:code">
    And a whole host of other attempts.


    Oddly, this retrieves something -- I think the shipping method selected on page submittal:


    Code:
    <mvt:foreach iterator="method" array="shippingmethods">
    
     Test: &mvt:method:name; <br>
    
    </mvt:foreach>
    But I can get nothing else out of it. Any ideas how to do this? Thanks.

    Kevin Garrett

    #2
    Re: Can't access data from shippingmethods array

    when in store templates, the array values are in "l.settings:" not l.all_settings", all_settings is the var array used inside modules...not SMT templates.
    Bruce Golub
    Phosphor Media - "Your Success is our Business"

    Improve Your Customer Service | Get MORE Customers | Edit CSS/Javascript/HTML Easily | Make Your Site Faster | Get Indexed by Google | Free Modules | Follow Us on Facebook
    phosphormedia.com

    Comment


      #3
      Re: Can't access data from shippingmethods array

      Hrm. I think that's one I tried too, but I'll give it another go. Thanks.

      I sure wish there was some decent documentation for SMT coders / store owners. I've been mucking with this since 2005 and I've never found anything. What you just said is news to me. I never understood the difference between
      "l.settings:" and l.all_settings." I appreciate the enlightenment.

      Kevin Garrett

      Comment


        #4
        Re: Can't access data from shippingmethods array

        OK, still nowhere. I guess I need more hand-holding. What's wrong with this?

        Code:
           
        <mvt:foreach iterator="shippingmethods" array="l.settings:shippingmethods">
        
            test: &mvt:shippingmethods:name; <br>        
                        
        </mvt:foreach>
        I've tried a variety of strings for the iterator (shippingmethod, l.settings.shippingmethods, etc.). What should it be? Even if &mvt:shippingmethods:name; is wrong, if it is iterating over the array, I should still see "test:" (3 of them!) but I don't.

        Comment


          #5
          Re: Can't access data from shippingmethods array

          If this is the standard foreach loop, the "array" is shippingmethods...you can't arbitrarily change that value. (You can change the iterator, and that's the 'label' of the array items).

          So you want:
          Code:
          <mvt:foreach array="shippingmethods" iterator="method">
          
          <mvt:if expr="'PRIORITYFL' CIN l.settings:shippingmethods:code">
          This is Priority Mail
          </mvt:if>
          
          </mvt:foreach>
          Bruce Golub
          Phosphor Media - "Your Success is our Business"

          Improve Your Customer Service | Get MORE Customers | Edit CSS/Javascript/HTML Easily | Make Your Site Faster | Get Indexed by Google | Free Modules | Follow Us on Facebook
          phosphormedia.com

          Comment


            #6
            Re: Can't access data from shippingmethods array

            Thanks for the info. It still didn't work so I began looking around. Turns out it needs the "shipment" item to be active (which it was not). Finally working after beating my head for hours.

            Kevin

            Comment


              #7
              Re: Can't access data from shippingmethods array

              Does anyone know where I can find the other method codes for the usps module?

              Comment

              Working...
              X