Announcement

Collapse
No announcement yet.

Coding > iterate thru prod codes, compare code prefix, print message if found

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

    Coding > iterate thru prod codes, compare code prefix, print message if found

    We have a quote system by Miva which is scheduled for update I understand. I need to add a message to the page (request-quote) if any products with a specific prefix are in the order. So the customer adds items which include the prefix PROG- and when they click 'Request Quote and get the quote page they would see my message. I looked at the token list and various code blocks and worked up this, but don't get the message. I'm hoping someone can help move me in the right direction.

    So in the request-quote page I added

    Code:
    <!-- load prefix exception(s) //-->
    <mvt:assign name="g.product_exception_1" value="'PROG-'" />
    
    <!-- flush variables //-->
    <mvt:assign name="g.product_exception_check_1" value="''" />       
    <mvt:assign name="g.product_exception_flag_1" value="''" />
    
    <!-- load product code //-->
    <mvt:assign name="g.product_exception_check_1" value="substring(l.settings:item:product:code, 0, 5)" />
    
    <!-- loop through product codes, compare 1st 5 code to exception //-->
    <mvt:foreach iterator="product" array="products">
    <mvt:assign name="g.product_exception_check_1" value="substring(l.settings:item:product:code, 0, 5)" />
    
    <mvt:if expr="g.product_exception_check_1 CIN g.product_exception_1">
    <mvt:assign name="g.product_exception_flag_1" value="1" />
    <mvt:else>
    <!-- do nothing //-->
    </mvt:if>
    
    <!-- if we get a match print a message//-->
    <mvt:if expr="NOT ISNULL g.product_exception_flag_1">
    Test Message
    </mvt:if>
    </mvt:foreach>
    and here are the relevant items from Token List that show on that page

    Code:
    Local Variables
    
    l.settings:global_minibasket:groups[1]:code            &mvt:global_minibasket:groups[1]:code;            PROG-GE-SEAMSEAL2
    l.settings:global_minibasket:groups[1]:product:code    &mvt:global_minibasket:groups[1]:product:code;    PROG-GE-SEAMSEAL2
    l.settings:global_minibasket:items[1]:code             &mvt:global_minibasket:items[1]:code;             PROG-GE-SEAMSEAL2
    l.settings:global_minibasket:items[1]:product:code     &mvt:global_minibasket:items[1]:product:code;     PROG-GE-SEAMSEAL2
    l.settings:item:code                                   &mvt:item:code;                                   PROG-GE-SEAMSEAL2
    l.settings:item:product:code                           &mvt:item:product:code;                           PROG-GE-SEAMSEAL2
    
    Global Variables
    
    g.product_exception_1                                  &mvt:global:product_exception_1;                  PROG-
    g.product_exception_check_1                            &mvt:global:product_exception_check_1;            PROG-

    Thanks.

    Burt

    #2
    Should be able to do this with:

    Code:
    <mvt:assign name="g.lookForProg" value="gettoken(l.settings:product:code, '-', 1)"/>
    <mvt:if expr="g.lookForProg EQ 'PROG'">
    Display Message
    </mvt:if>
    <mvt:assign name="g.lookForProg" value="''"/>
    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
      Thanks a million Bruce. That put me most of the way there. Just have to sort out a few things related to the page itself and I should be set.

      I also love that you did this with only a few lines. :)

      Comment


        #4
        Hmmm... I'm stumped. I tried this a dozen different ways.

        Code:
        <mvt:assign name="g.lookForProg" value="gettoken(l.settings:item:code, '-', 1)"/>
        <mvt:if expr="g.lookForProg EQ 'PROG'">
        <mvt:assign name="g.exception_flag_1" value="1" />
        <mvt:else>
        </mvt:if>
        <mvt:if expr="g.exception_flag_1 EQ 1">
        -- message content goes here ---
        </mvt:if>
        <mvt:assign name="g.lookForProg" value="''"/>
        with your example, but using l.settings:item:code (not sure whyl.settings:product:code didn't work)I see my message. However if I add a second product to the cart, that doesn't start with PROG- I lose my message. So after I check if PROG is in there I set a flag g.exception_flag_1 and print the message. Still the message only prints when I add that first PROG item, but then if I add another item the message goes away. When I look in tokenlist though I can see that g.exception_flag_1 still has the value of 1 so I assumed this g.exception_flag_1 EQ 1 should still be TRUE ye the message doesn't print.

        Comment


          #5
          If you only need to look for one instance, then you simply remove the
          <mvt:assign name="g.lookForProg" value="''"/> line. This means, that if ANY product in the list (and yes, items: would be correct if this is a basket type array--more on that below) it will set the flag to 1. A word about variables and iterated arrays: A foreach loop has two part: the Array which contains all the data, and an Iterator, which is basically a "local" label for the variables picked apart from the array. For example if you have a list of products in the array "someProductList", you can chose whatever you want as the iterator. <mvt:foreach iterator="item" array="someproductlist"> You'd find the product code as l.settings:item:code <mvt:foreach iterator="apples" array="someproductlist"> l.settings:apples:code
          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

          Working...
          X