Announcement

Collapse
No announcement yet.

Help with modularization for new Miva dev

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

    Help with modularization for new Miva dev

    Hello,

    I’m looking to make my Miva codebase more modular and maintainable. Currently, my code is quite linear and repeatedly embedded directly in templates, which works, but isn’t ideal for larger projects.

    Ive looked at using items and templates but can't seem to find exactly what I need. These were my ideas:
    Creating reusable functions within items or including templates within other templates. Ultimately I want something like reusable functions I can access within a template.

    Any tips are appreciated, and so far I am just using the admin panel.

    Also, feel free to share any Miva advice for a JavaScript/PHP webdev.
    Would love to hear your insights and experiences on this!

    Cheers,
    David

    #2
    davdg75 I just DM'd you with some more information but here are some good resources:

    https://www.miva.com/mivalearn
    https://github.com/mivaecommerce/
    https://docs.miva.com/template-language/mvtassign
    https://docs.miva.com/api-functions

    Nicholas Adkins
    Technical Training Specialist / Miva, Inc.
    [email protected]
    https://www.miva.com/mivalearn

    Comment


      #3
      Nick
      Appreciate the reply, I've primarily been using the https://docs.miva.com/developers for learning including the mvt documentation: https://docs.miva.com/template-language/mvtassign

      Is there any specific recommended way to modularize template code? In my example I have this chunk of code repeated 20+ times. Only difference is productcode is sometimes a different named variable

      Code:
      <mvt:item name="toolkit" param="productincategory|typecount|productcode|'first'" />
      <mvt:if expr="typecount GT 0">
      "templatetype":"1",
      <mvt:else>
          <mvt:item name="toolkit" param="productincategory|typecount|productcode|'second'" />
          <mvt:if expr="typecount GT 0">
               "templatetype":"2",
          <mvt:else>
               <mvt:item name="toolkit" param="productincategory|typecount|productcode|'third'" />
               <mvt:if expr="typecount GT 0">
                    "templatetype":"3",
               <mvt:else>
                    "templatetype":"4",
               </mvt:if>
          </mvt:if>
      </mvt:if>

      Comment


        #4
        Originally posted by davdg75 View Post
        Nick
        Appreciate the reply, I've primarily been using the https://docs.miva.com/developers for learning including the mvt documentation: https://docs.miva.com/template-language/mvtassign

        Is there any specific recommended way to modularize template code? In my example I have this chunk of code repeated 20+ times. Only difference is productcode is sometimes a different named variable
        I think the first suggestion would be to remove the use of toolkit. The Toolkit module functions can been replaced by default template code. Removing Toolkit from your store will help overall performance of the store.

        It is hard to say the best way to optimize the code because I am not sure the use case. Here is a snippet that will replace the code above using Miva Template Language: https://snippets.cacher.io/snippet/d1821665bbfa68c0968c

        The snippet is using Product_Load_Code, Category_Load_Code and CategoryXProduct_Load functions to replicate the snippet you provided.

        That being said there may be a better way to get the result intended using CategoryXProduct_Load_Category
        Nicholas Adkins
        Technical Training Specialist / Miva, Inc.
        [email protected]
        https://www.miva.com/mivalearn

        Comment


          #5
          You can put a chunk of code in a ReadyTheme content section, and then "call" it from multiple pages. For the above snippet, you'll have to do a little extra coding to make sure that the product code is passed with the same variable name in every case.

          I think you can also use the "content" Item to create multiple components with different Item codes and different snippets.

          And as Nick says, Yes, it's time to stop using Toolkit. :^.
          Kent Multer
          Magic Metal Productions
          http://TheMagicM.com
          * Web developer/designer
          * E-commerce and Miva
          * Author, The Official Miva Web Scripting Book -- available on-line:
          http://www.amazon.com/exec/obidos/IS...icmetalproducA

          Comment


            #6
            Originally posted by Kent Multer View Post
            You can put a chunk of code in a ReadyTheme content section, and then "call" it from multiple pages. For the above snippet, you'll have to do a little extra coding to make sure that the product code is passed with the same variable name in every case.

            I think you can also use the "content" Item to create multiple components with different Item codes and different snippets.

            And as Nick says, Yes, it's time to stop using Toolkit. :^.
            Yes, this is the way. You can almost create custom 'functions' by using readytheme content sections for code that is repeated over and over again. Just make sure you pass the required variables.
            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


              #7
              Thank you for all of the responses. I will look into using readytheme content sections and removing toolkit.

              Also I noticed in the documentation there is a page about replacing toolkit (https://docs.miva.com/template-langu...ement-examples), which has a lot of good code samples to use. So it seems like toolkit is currently a non best practice third party module. Is there any documentation on toolkit (like toolkit's implementation or available functions) that I can reference, as it would be helpful to know what toolkit is doing before replacing it? (I am currently the sole developer on a pre existing project)

              Comment


                #8
                davdg75 Here is a link to Toolkit's documentation page: https://www.emporiumplus.com/v5/toolkit.htm

                You can also find the functions available in Toolkit here (scroll to the bottom): https://apps.miva.com/emporium-plus-...tml#devInfoTab
                Last edited by Nick; 10-28-23, 07:10 AM.
                Nicholas Adkins
                Technical Training Specialist / Miva, Inc.
                [email protected]
                https://www.miva.com/mivalearn

                Comment

                Working...
                X