Announcement

Collapse
No announcement yet.

MivaScript.com is now LIVE!

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

    MivaScript.com is now LIVE!

    We're very pleased to announce that we've been working the past 3 months with Ray Yates from PCI-Net to have Ray properly document the 5.x Miva Script language from the ground up.

    That work has paid off and is now live at: www.mivascript.com
    Thanks,

    Rick Wilson
    CEO
    Miva, Inc.
    [email protected]
    https://www.miva.com

    #2
    Re: MivaScript.com is now LIVE!

    Super duper cool.
    Best,
    Pamela

    Consultant / Developer / Trainer
    Contributing Editor to Practical Ecommerce
    Author of the Official Guides for Miva Merchant
    pamelahazelton.com

    Comment


      #3
      Re: MivaScript.com is now LIVE!

      Wouldn't you know it. The one function I'm not clear on and cannot find a good working example on is sorting on an element in an array. The miva_array_sort example was blank. I looked at the util_public file and it did not have the example I need either. For example
      product:name
      product:code
      product:price (numeric, not formatted)
      Currently the array is by name.
      So if someone knows how to sort that array by price, it would be nice if it could be added to the blank example. I don't see where you would tell the function you wanted to sort by price. Two hours of experimenting and still nothing. I'm sure it is simple, but stabbing in the dark with no example at all can be frustrating. Maybe this weekend I'll have time to experiment more.
      Bill Weiland - Emporium Plus http://www.emporiumplus.com/store.mvc
      Online Documentation http://www.emporiumplus.com/tk3/v3/doc.htm
      Question http://www.emporiumplus.com/mivamodu...vc?Screen=SPTS
      Facebook http://www.facebook.com/EmporiumPlus
      Twitter http://twitter.com/emporiumplus

      Comment


        #4
        Re: MivaScript.com is now LIVE!

        Bill, unfortunately there are still missing pieces. Once you figure it out please Annotate the command with your findings.

        Somewhere on the forum I saw the subject come up. I would encourage you and everyone to add your findings to the site for the benefit of all.
        Ray Yates
        "If I have seen further, it is by standing on the shoulders of giants."
        --- Sir Isaac Newton

        Comment


          #5
          Re: MivaScript.com is now LIVE!

          All I found on the forum is they could not get it to work. They did not show an example of sorting on one of the elements in any of the several threads I looked at. If I find how to sort on the product:price I will add it. But two hours and I got absolutely nowhere so I am not even in the same ballpark, let alone playing the correct game.
          Bill Weiland - Emporium Plus http://www.emporiumplus.com/store.mvc
          Online Documentation http://www.emporiumplus.com/tk3/v3/doc.htm
          Question http://www.emporiumplus.com/mivamodu...vc?Screen=SPTS
          Facebook http://www.facebook.com/EmporiumPlus
          Twitter http://twitter.com/emporiumplus

          Comment


            #6
            Re: MivaScript.com is now LIVE!

            Yay!!!!!
            Bill Matlock

            Comment


              #7
              Re: MivaScript.com is now LIVE!

              This is VERY good news!
              William Gilligan - Orange Marmalade, Inc.
              www.OrangeMarmaladeinc.com

              Comment


                #8
                Re: MivaScript.com is now LIVE!

                Originally posted by wcw View Post
                Wouldn't you know it. The one function I'm not clear on and cannot find a good working example on is sorting on an element in an array. The miva_array_sort example was blank. I looked at the util_public file and it did not have the example I need either. For example
                product:name
                product:code
                product:price (numeric, not formatted)
                Currently the array is by name.
                So if someone knows how to sort that array by price, it would be nice if it could be added to the blank example. I don't see where you would tell the function you wanted to sort by price. Two hours of experimenting and still nothing. I'm sure it is simple, but stabbing in the dark with no example at all can be frustrating. Maybe this weekend I'll have time to experiment more.
                Oh, you should have just asked. :)

                In my testing, it looks like the miva_array_sort() function will only sort on the alphabetically superior structure name. So if you have an array like:

                g.product[1]:name="apple"
                g.product[1]:price="1.50"
                g.product[1]:color="green"
                g.product[1]:code="grannysmith"

                It will sort on :code.

                So to get around it (and yes it's a PITA) you can do one of two things:
                1) As you load in your array, double assign price; once as ':price' and once as ':a'
                2) Load in your array, loop through it adding a new structure element called ':a' that is a duplicate of ':price'

                Then sort. Version one is quicker as it's one less loop through an array.

                Here is a clunky function to use method 2, including the callback:

                Code:
                <MvFUNCTION NAME = "Miva_Array_Sort_By" PARAMETERS = "element, array var" STANDARDOUTPUTLEVEL = "">
                	<MvASSIGN NAME = "l.max" VALUE = "{ miva_array_max( l.array ) }">
                	<MvASSIGN NAME = "l.pos" VALUE = "{ miva_array_min( l.array ) }">
                
                	<MvWHILE EXPR = "{ l.pos LE l.max }">
                		<MvASSIGN NAME = "l.array" INDEX = "{ l.pos }" MEMBER = "a" VALUE = "{ miva_variable_value( 'l.array[' $ l.pos $ ']:' $ l.element ) }">
                		<MvASSIGN NAME = "l.pos" VALUE = "{ miva_array_next( l.array, l.pos ) }">
                	</MvWHILE>
                
                	<MvASSIGN NAME = "l.sort" VALUE = "{ miva_array_sort( l.array, 'Sort_Callback', l.null ) }">
                
                	<MvASSIGN NAME = "l.pos" VALUE = "{ miva_array_min( l.array ) }">
                	<MvWHILE EXPR = "{ l.pos LE l.max }">
                		<MvASSIGN NAME = "l.array" INDEX = "{ l.pos }" MEMBER = "a" VALUE = "">
                		<MvASSIGN NAME = "l.pos" VALUE = "{ miva_array_next( l.array, l.pos ) }">
                	</MvWHILE>
                
                	<MvFUNCTIONRETURN VALUE = "{ l.sort}">
                </MvFUNCTION>
                <MvFUNCTION NAME = "Sort_Callback" PARAMETERS = "left var, right var, data var" STANDARDOUTPUTLEVEL = "">
                    <MvIF EXPR = "{ l.left LT l.right }">
                        <MvFUNCTIONRETURN VALUE = "-1">
                    <MvELSEIF EXPR = "{ l.left GT l.right }">
                        <MvFUNCTIONRETURN VALUE = "1">
                    <MvELSE>
                        <MvCOMMENT> l.left EQ l.right </MvCOMMENT>
                        <MvFUNCTIONRETURN VALUE = "0">
                    </MvIF>
                </MvFUNCTION>
                You would call it like so:
                Code:
                <MvASSIGN NAME = "l.sort" VALUE = "{ Miva_Array_Sort_By( 'price', l.struct ) }">
                So long as the beginning array doesn't have an element called 'a', it's all good.

                Comment


                  #9
                  Re: MivaScript.com is now LIVE!

                  Scott,

                  This would be a great Annotation to the MivaScript.com site, and you could be the first to post.

                  Go here and click + Add a Note.
                  http://www.mivascript.com/item/miva_array_sort.html
                  Ray Yates
                  "If I have seen further, it is by standing on the shoulders of giants."
                  --- Sir Isaac Newton

                  Comment


                    #10
                    Re: MivaScript.com is now LIVE!

                    To sort a structure / array by element, I use something like this - it's very fast:

                    Code:
                    <MvFUNCTION NAME = "sort_array_by_element" PARAMETERS="array VAR,element" STANDARDOUTPUTLEVEL = "html,text,compresswhitespace"> 
                    
                    	<MvASSIGN NAME = "l.max" VALUE = "{ miva_array_max( l.array ) }">
                    	<MvASSIGN NAME = "l.pos" VALUE = "{ miva_array_min( l.array ) }">
                    
                    	<MvWHILE EXPR = "{ l.pos LE l.max }">
                    		<MvASSIGNARRAY NAME = "l.new"  VALUE = "{ miva_variable_value( 'l.array[' $ l.pos $ ']:' $ l.element ) }" >
                    			<MvMEMBER NAME="{ padl(gettoken( miva_variable_value( 'l.array[' $ l.pos $ ']:' $ l.element ),'.',1),20,'0')$'.'$ padr(gettoken( miva_variable_value( 'l.array[' $ l.pos $ ']:' $ l.element ),'.',2),8,'0')  }">
                    			<MvDIMENSION INDEX="{miva_variable_value( 'new:'$padl(gettoken( miva_variable_value( 'l.array[' $ l.pos $ ']:' $ l.element ),'.',1),15,'0')$'.'$ padr(gettoken( miva_variable_value( 'l.array[' $ l.pos $ ']:' $ l.element ),'.',2),8,'0') )+1}">
                    		<MvASSIGN NAME = "l.pos" VALUE = "{ miva_array_next( l.array, l.pos ) }">
                    	</MvWHILE>
                    <MvFUNCRETURN VALUE="{ miva_array_deserialize(trim(l.new))}">
                    </MvFUNCTION>
                    (this code example is not tested, but it probably shows the "mechanics" behind it. It works for strings (case-insensitive) and positive numbers. I am not sure about negative numbers.)
                    Emerald Media, Trade & Technology USA/Germany
                    Professional Miva Programming since 1998
                    Home of the Emerald Objects Application Server (EOA)
                    Multi-dimensional CRM, CMS & E-Commerce

                    http://www.emeraldobjects.com
                    http://www.sylter-seiten.com

                    Comment


                      #11
                      Re: MivaScript.com is now LIVE!

                      markus. I can't get this to work. I have 5 other sort routines written in MivaScript. Yours looks very promising.

                      I have been using an earlier version of your sort for several years that only sorts simple text arrays in ascending order, but does it 350% faster than miva_array_sort() ; much faster anything else I've found.

                      I've used your older version to create a sorted "index", to act as pointer to the larger structured array, allowing me to display the results ascending or descending without actually sorting the data. This technique is much faster and less complex than Merchants QuickSortArray() function.

                      I updated Scotts excellent sort (using miva_array_sort() ) to allow for sorting ascending, descending and correctly sorting numeric arrays. While not as fast as yours, it is more flexible.

                      I'd love to have a working version of your sort. Sort_Array_by_element()

                      I want to post an article on MivaScript.com showing these sorts.
                      Test results from slowest to fastest. NOTE that in ALL cases after a certain array size is reached, each of these sorts displays significant degradation in sort times. For Qsort() that seems to happen around 75000 items.

                      Bubble_Sort() : 530 elements per sec.
                      Insertion_Sort() : 950 elements per sec.
                      QuickSortArray() : 2550 elements per sec.
                      Miva_Array_Sort_By() : 5300 elements per sec. (uses miva_array_sort() )
                      Qsort() : 19000 elements per sec.

                      NOTE: I reported a bug where the function miva_array_sort() crashes windows Mia when the array exceeds aprox. 39500 elements.
                      Ray Yates
                      "If I have seen further, it is by standing on the shoulders of giants."
                      --- Sir Isaac Newton

                      Comment


                        #12
                        Re: MivaScript.com is now LIVE!

                        Originally posted by Rick Wilson View Post
                        We're very pleased to announce that we've been working the past 3 months with Ray Yates from PCI-Net to have Ray properly document the 5.x Miva Script language from the ground up.

                        That work has paid off and is now live at: www.mivascript.com
                        What a wonderful job you've done :-) Thanks a lot !!!
                        Zen Radio : Relax :) : www.zenradio.fm
                        MivaScript Tutorials & Scripts : www.mivascript.org

                        Comment


                          #13
                          Re: MivaScript.com is now LIVE!

                          Claudiu,

                          It's worth noting that this couldn't have been done without you, thanks for being so accommodating and protecting of that great domain name all this time.
                          Thanks,

                          Rick Wilson
                          CEO
                          Miva, Inc.
                          [email protected]
                          https://www.miva.com

                          Comment


                            #14
                            Re: MivaScript.com is now LIVE!

                            All the pleasure is mine :-)
                            Zen Radio : Relax :) : www.zenradio.fm
                            MivaScript Tutorials & Scripts : www.mivascript.org

                            Comment


                              #15
                              Re: MivaScript.com is now LIVE!

                              Does anyone have a colorize script for MivaScript they would like to contribute?
                              Ray Yates
                              "If I have seen further, it is by standing on the shoulders of giants."
                              --- Sir Isaac Newton

                              Comment

                              Working...
                              X