Announcement

Collapse
No announcement yet.

New API function -- any documentation?

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

    New API function -- any documentation?

    I just recently learned that there is a new function, CurrencyModule_Output_CurrencyFormat_JavaScript, that currency modules must provide. There's an example in the LSK, but no other documentation anywhere that I've been able to find. Did I miss a release note? Can someone give me some details on what this function does and how to write it? What api_ver do I need to use with this?

    Thanks --
    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

    #2
    api_ver needs to be 9.07 or higher.

    This function lets you output your own currency formatter in javascript.
    The function return values are either:
    1: You have output the MMCurrencyFormatter javascript function and are handling the output format yourself (we will not output any fallback code)
    0: You have not output the MMCurrencyFormatter javascript function and expect the fallback code to be output instead

    In your case, (assuming this is for your Currency Magic module), you will want to return 1 and handle it yourself. The gencurr.mv module shows an example of a more complex use case (in the LSK), while usmoney.mv is a simpler example. The MMCurrencyFormatter function takes two parameters: value and show_whole_numbers_only. "value" is the unformatted value that you are expected to convert and output. show_whole_numbers_only is a flag the caller can pass when they want to display only whole numbers (facets uses this in the slider).
    Ryan Guisewite
    Lead UI Developer / Miva, Inc.
    www.miva.com

    Comment


      #3
      Hi Ryan, thanks for the info. I just downloaded a fresh copy of the LSK on June 1, and the gencurr.mv file doesn't contain the CurrencyModule_Output_CurrencyFormat_JavaScript function. I'd like to see that before I start writing code, if it's possible?

      Also, what is the fallbkac code that gets generated if theCurrencyModule_Output_CurrencyFormat_JavaScript function returns zero?

      Thanks --
      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


        #4
        Ah, that is unfortunate. I'll look into getting an updated LSK released.

        The fallback code looks like this:

        Code:
        <script type="text/javascript">
            function MMCurrencyFormatter( value, show_whole_numbers_only )
            {
                if ( show_whole_numbers_only )    return stoi_def( value, 0 );
                else                              return stod_def( value, 0 );
            }
        </script>
        gencurr is much larger, outputting all sorts of different string values based on what the settings for the module are configured to display. Basically, this function should just replicate what CurrencyModule_AddFormatting is doing, but with javascript (you can use inline MivaScript to check settings and the output javascript that matches those settings). As an example:

        Code:
        <script type="text/javascript">
            function MMCurrencyFormatter( value, show_whole_numbers_only )
            {
                <MvIF EXPR = "{ l.settings:currency_symbol EQ 'us_dollar' }">        return '$' + ( show_whole_numbers_only ? stoi_def( value, 0 ) : stoi_def( value, 0 ) );
                <MvELSEIF EXPR = "{ l.settings:currency_symbol EQ '...' }">          return ...;
                ...
                </MvIF>
            }
        </script>
        Ryan Guisewite
        Lead UI Developer / Miva, Inc.
        www.miva.com

        Comment


          #5
          Thanks, that helps.

          What about the stoi_def and stod_def functions? What do they do, or can I get source code?
          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
            Ack, sorry Kent. I meant to reply to this and completely lost track of it. stoi_def and stod_def are part of our admin/ui.js (and the runtime_ui.js file) and are helper functions that will make sure the value is actually an integer (or double). If it is not, it will use the default value you pass. It stands for "string-to-integer or default"/"string-to-double or default".
            Ryan Guisewite
            Lead UI Developer / Miva, Inc.
            www.miva.com

            Comment


              #7
              Hi Ryan, I'm just about ready to test an update for my currency module, and I have another question -- two, actually. When does CurrencyModule_Output_CurrencyFormat_JavaScript get called? Where does the generated Javascript show up on the page? Will it be contained in an l.settings variable?

              Thanks --
              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


                #8
                Hey Kent,

                CurrencyModule_Output_CurrencyFormat_JavaScript is currently pulled in by two locations: The runtime product list (via standard facets module) when a facet of display type "Range Slider", and the canvas chart reports display page.

                In runtime product list, the MMCurrencyFormatter function you created will be output in the head tag (not available in any sort of l.settings variable. It is javascript, output to the page). For the report module, it is also output to the page in the head tag.

                To view/test the runtime product list, enable the Standard Facets module and make sure the Price checkbox is checked on the Standard Facet Settings screen (Utilities). Go to Catalog > Facet Rules and edit the Price facet rule. Change the Facet Display Type dropdown to "Range Slider". You'll have to have a few products with prices in a wide enough range to actually show the slider (I'd make at least $1, $10, $50, $100, $200, and $500 products with similar name so you can search and all will show up). In runtime, search for something that will match those products in the range you set up. You should now see a range slider in the facets section on the SRCH page. The price displayed in the low and high fields have been formatted via the js you generated in CurrencyModule_Output_CurrencyFormat_JavaScript. If it is working correctly, you should not have any JavaScript errors, and when you drag the sliders, the low/high fields should be updated and formatted correctly via your MMCurrencyFormatter.

                To test the reporting stuff, you can open one of the reports like Recent Sales that uses the newer HTML Canvas chart. The labels showing you the currency value (price, cost) when you hover over a point in the chart itself will be generated using MMCurrencyFormatter.
                Ryan Guisewite
                Lead UI Developer / Miva, Inc.
                www.miva.com

                Comment

                Working...
                X