Announcement

Collapse
No announcement yet.

Get assigned categories

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

  • You're almost right but you mangled the display of the vars.

    This code won't get you anywhere:
    Code:
    &mvt:l.settings:_catproduct:cat_id;  <br> &mvt:l.settings:_catproduct:product_id;  <br> &mvt:l.settings:_catproduct:disp_order;  <br>
    Either use mvt:eval if you're gonna use l.settings, or get rid of l.settings and use page entities.
    Code:
    &mvt:_catproduct:cat_id;
    <br>
    &mvt:_catproduct:product_id;
    <br>
    &mvt:_catproduct:disp_order;
    <br>
    or

    Code:
    <mvt:eval expr="l.settings:_catproduct:cat_id" />
    etc...
    Take a look at this post, it explains things like the difference between l.settings and &mvt and similar stuff:

    https://www.scotsscripts.com/blog/mi...-use-them.html
    M.A.D.* since 1997

    http://www.scotsscripts.com

    *miva application developers

    Comment


    • Also, don't know if this is a typo but this won't work either:

      Code:
       
       <mvt:assign name="l.product_code" value="'atopcat17'" /> <mvt:do file="g.Module_Library_DB" name="l.success" value="Product_Load_Code( l.product_code, l.settings:product )" />  <mvt:assign name="l.category_code" value="'atopica-cats'" /> <mvt:do file="g.Module_Library_DB" name="l.success" value="Product_Load_Code(l.category_code, l.settings:category)" />
      The second function should be Category_Load_Code. Also, you don't need to assign it to a variable. You can use literals in functions, just use single quotes.
      Code:
       <mvt:do file="g.Module_Library_DB" name="l.success" value="Category_Load_Code('atopica-cats', l.settings:category)" />
      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


      • Yeah, that's a typo in my blog post, forgot to make that change thanks..
        M.A.D.* since 1997

        http://www.scotsscripts.com

        *miva application developers

        Comment


        • Alright! This is the beginning of progress.

          My deepest thanks and appreciation to you both, Scot - ScotsScripts.com & @bruce-phosphormedia for being the helpful and patient mentors of MivaScritpt noobs like me. I know this is hard work, I know we can wear on the patience. I see your hard work, I recognize what you both do for this community. I hope others see it too.

          Comment


          • Every single miva developer started knowing nothing about miva, so we know how it goes :) Glad you're making progress!
            M.A.D.* since 1997

            http://www.scotsscripts.com

            *miva application developers

            Comment


            • Slightly more general question, but related to this.

              What's the best way to 'craft' an array? I have read the docs on arrays --> https://docs.miva.com/template-language/arrays

              But that feels rather cumbersome. Is there a more straight forward way? Should I pass in a JSON object, which contains an array?

              Comment


              • That example is a simplistic way of doing it, kind of cumbersome as you said since you gotta load up each element manually. How you craft the array is based on the situation.

                Where are you getting your list of objects for the array? That will probably determine the best way of going about it. You could pass a json object and then use the
                miva_json_decode( data, output var ) function to create a structure out of the json you passed in. I've done this quite a bit and it's the way you to if you already have the data in json format. http://www.mivascript.com/item/mivas...on_decode.htmlAnother way to make an array is my using miva_array_insert which will let you add a structure to the end of the array if you use -1 for the "pos" parameter. http://www.mivascript.com/item/mivas...ay_insert.html
                M.A.D.* since 1997

                http://www.scotsscripts.com

                *miva application developers

                Comment


                • Originally posted by Scot - ScotsScripts.com View Post
                  Where are you getting your list of objects for the array? That will probably determine the best way of going about it.
                  I'm getting the array items from a list of product lines (categories in Miva parlance) provided to us from the manufacturer so the usual "loop" method might be a bit much for this. Basically I know what I want the items in the array to be, I'm looking for the best way to give it to MivaScript functions.

                  Originally posted by Scot - ScotsScripts.com View Post
                  You could pass a json object and then use the
                  miva_json_decode( data, output var ) function to create a structure out of the json you passed in. I've done this quite a bit and it's the way you to if you already have the data in json format. http://www.mivascript.com/item/mivascript-functions/miva_json_decode.html Another way to make an array is my using miva_array_insert which will let you add a structure to the end of the array if you use -1 for the "pos" parameter. http://www.mivascript.com/item/mivas...ay_insert.html
                  I know how to construct an array that JavaScript understands, but that's probably not helpful when I want to send it to MivaScript.

                  Comment


                  • Yeah, so if you have it in json you can use mvt:call to get the json from somewhere (url) or use the file_Read functions to get it if it's in a file, then use the miva_json_decode to give you an array of structures that will have all the data that you had in the json string.
                    M.A.D.* since 1997

                    http://www.scotsscripts.com

                    *miva application developers

                    Comment


                    • Weirdo question:

                      Can we mix JavaScript into MVT stuff? As in have MVT check for info/verify then have it call a piece of JavaScript for the bit of functionality?

                      Comment


                      • In some ways, but you have to keep in mind how it all works. JS is rendered clientside in the browser whereas mvt is rendered server side. So you can put js inside mvt:if conditionals that executes upon loading, and you can have js interact with various clicks, hovers and all the other basic ways to trigger js in the browser, but you can't really "call" a js function using mvt since mvt and js are processed at different times. I'm not being as clear as I could be, but hopefully this makes sense.
                        M.A.D.* since 1997

                        http://www.scotsscripts.com

                        *miva application developers

                        Comment


                        • maybe a better way to phrase it would be: You can use SMT to WRITE js...but that's about it.

                          $('#&mvte:some:variable;').val()

                          works.

                          (and yes, i know that's jQuery)
                          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


                          • Scot - ScotsScripts.com I actually understood what you said. Looks like some knowledge is rubbing off.
                            Bruce - PhosphorMedia I think I understand what you're getting at but I can't quite parse the example. But I'm also rushing to get something productive today so ... that's probably also not helping.

                            Comment


                            • Code:
                              <mvt:foreach iterator="group" array="basket:groups">
                              
                              <mvt:assign name="g.assigned_categories" value="''" />
                              <mvt:do name="l.result" file="g.Module_Library_DB" value="CategoryList_Load_Offset_Product_Assigned(l .settings:group:product:id,0,'','',0,l.null, g.assigned_categories )" />
                              
                              <mvt:foreach iterator="category" array="global:assigned_categories">
                              
                              <mvt:if expr="l.settings:category:code EQ 'Capstar-tablets'">
                              
                              <mvt:do file="g.Module_Feature_PGR_RT" name="l.success" value="Action_ApplyCouponToBasket('Capstar-Special')" />
                              
                              </mvt:if>
                              </mvt:foreach>
                              
                              <mvt:comment>end of your main basket loop</mvt:comment>
                              </mvt:foreach>
                              Most of the above is correct. But the apply coupon action doesn't seem to trigger
                              Last edited by cpp-dev; 05-17-19, 01:45 PM.

                              Comment


                              • Is there a typo? Or did you mean to spell the coupon code 'Capstar-Speical' instead of 'Capstar-Special' ?

                                "Action_ApplyCouponToBasket('Capstar-Speical')"
                                M.A.D.* since 1997

                                http://www.scotsscripts.com

                                *miva application developers

                                Comment

                                Working...
                                X

                                This website uses cookies to identify visitors, track visitors to our website, store login session information and to remember your user preferences. By continuing to use this site you agree to our use of cookies. Learn More.

                                This website uses cookies. By continuing to use this site you agree to our use of cookies. Learn More.

                                Accept