Announcement

Collapse
No announcement yet.

Inexperienced person question

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

    Inexperienced person question

    Hello,

    If I have a custom field "customfield" which is assigned a text string "product1, product2, product3" where product1 etc. are product codes,
    a) Can I put them into an array?
    b) If so - how do I define an array (either local or global)
    c) Now I know how to iterate through the array, but what if I wanted to go to a certain index?

    Sorry - if someone can point me to the documentation that would be sufficient as well.

    I do have toolkit - but never used it personally.

    Thanks
    Sam

    #2
    Re: Inexperienced person question

    Yes. But should you? Depends on what you are doing with them.
    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: Inexperienced person question

      I want to create a multi add product page that is generic and takes its content from a custom field for a product.
      SO if I have
      SHOES as the main product
      I could also have them simultaneously look at
      SOCKS
      SHOE POLISH
      etc.

      Shoes is the lead product

      I could go into related products and search for all that exist and show them in sequence, but I thought it would be simpler if I just had the products that I want to show immediately in a custom field.

      Many retailers do this by the way - where they have a whole array of things that are in a photograph available for sale with a certain lead product.

      Comment


        #4
        Re: Inexperienced person question

        i'd just create a category for each "image" and assign the products to that category while using the image as a category title image...there, you've got your array already built.
        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


          #5
          Re: Inexperienced person question

          Hi Sam,
          Here are a couple of things that can help you in general. You mention being inexperienced, so I'll try to be thorough.

          1 - You can create an array from any comma-delimited string using the miva_array_deserialize function, like so:
          Code:
          <mvt:assign name="g.productcodes" value="miva_array_deserialize(g.customfield)"/>
          You can find documentation for MivaScript functions at http://www.mivascript.com/topic/miva...functions.html. Note that mivascript.com provides documentation for MivaScript, which is a server-side programming language, and is different from the template language used for your store pages. However, MivaScript functions can be run within mvt:assign or mvt:eval statements.

          2 - You can iterate through an array with a foreach loop, or you can reference a specific array element by adding brackets with the index position when referencing the array, like g.productcodes[1]. Indexes in Miva are 1-based, unlike other programming languages you may have used where they're 0-based. At the moment, there's a limitation where you can't use a variable to define the index within the template language, so g.productcodes[g.index] would throw an error.

          3 - It sounds like you need an array of product data, not just of the product codes themselves. Miva Merchant has a lot of functions within the software that you can call with an mvt:do statement, including loading product data. (These are different from the MivaScript functions I mentioned before.) You'll find mvt:do documentation and examples here:
          http://www.miva.com/videos/articles/...-documentation

          If you want to see all the available Miva Merchant functions, you'd really need to download the Limited Source Kit and just look around and see what things do and how they all connect: http://www.miva.com/support/downloads

          In your situation, you would need to loop through your array of product codes and load the product data for each code into a new array. That might look something like this:

          Code:
          <mvt:assign name="g.productcodes" value="miva_array_deserialize(g.customfield)"/>
          <mvt:foreach array="global:productcodes" iterator="code">
              <mvt:do name="l.return" file="g.Module_Library_DB" value="Runtime_Product_Load_Code( l.settings:code, l.product )" />
              <mvt:eval expr="miva_array_insert(g.productarray, l.product, l.pos1"/>
          </mvt:foreach>
          Several things are happening here. The mvt:do statement is calling the Runtime_Product_Load_Code function, which loads all of the product data into the l.product variable as an array. Next, the mvt:eval statement is using a MivaScript function, miva_array_insert, to add the array content from l.product as a new element in g.productarray, which is going to be your final output. the l.pos1 variable holds the number of the current iteration through the loop, and is something Miva makes available any time you run a loop, which is handy. We're using that to define the array index, so each time the loop runs, the product data is put into the next position in the array.

          At this point, you can just loop through g.productarray to list all of your product data on the page however you need it.

          On a side note, your question mentioned defining local or global variables, so I want to clarify that there's no functional difference between those when you're working within the template code. MivaScript (the server-side language) uses local vs global variable scope, but everything defined within the templates is global within the scope of the template.

          Hopefully this answers your questions. I haven't actually executed the code examples I provided, so I encourage anyone to correct me if something doesn't work. It all seems like it should, but it's fast approaching midnight here so I could be wrong :). Anyways, I hope this helps, and I'm happy to help further if anything doesn't make sense or if you have other questions.


          Josh

          Comment


            #6
            Re: Inexperienced person question

            Josh,

            Thank you so much or yoru detailed reply. It is extremely helpful.

            I will play around until I get experienced. But I think you have pointed me in the right direction.


            Thanks again,
            Sam

            Comment

            Working...
            X