How can I display or format a custom product field price like this $??.??

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • blubbert
    Mivite

    • Mar 2006
    • 113

    #1

    How can I display or format a custom product field price like this $??.??

    I am just wondering how I can display a custom product field like a currency if at all possible.

    We actually have three prices for some of our products and I am using a custom product field for the third price. I already am using the cost and price field. Sometimes it gets import like 91.5. I would love for it to display properly without having to go in and fix it each time.

    Here is the code I current use to display this:

    Code:
            <mvt:if expr="NOT ISNULL l.settings:product:customfield_values:customfields:SLPrice">
            <div class="custom-field" id="customfields-SLPrice">&mvt:customfield_names:customfields:SLPrice;: <span class="bold">$&mvt:product:customfield_values:customfields:SLPrice;</span></div>
            </mvt:if>
    Any ideas how this might be done?
    Brandon Lubbert
    Library and Educational Services

    A wholesale company for churches, day care providers,
    homeschools, libraries, missionaries, resellers and schools!


    www.libraryanded.com
  • chrisb
    Mini Mivite

    • Nov 2010
    • 34

    #2
    Re: How can I display or format a custom product field price like this $??.??

    If you're using Weiland's Tool Kit in your store, you can pull this off with a mildly scary-looking mveval.

    Code:
    <mvt:if expr="NOT ISNULL l.settings:product:customfield_values:customfields:SLPrice">
        <div class="custom-field" id="customfields-SLPrice">&mvt:customfield_names:customfields:SLPrice;:
            <span class="bold">
                    $<mvt:item name="toolkit" param="mveval|padl( gettoken( l.settings:product:customfield_values:customfields:SLPrice, '.', 1 ), 1, '0' ) $ '.' $ padr( gettoken( l.settings:product:customfield_values:customfields:SLPrice, '.', 2 ), 2, '0' )" />
            </span>
        </div>
    </mvt:if>
    Within the mveval, dollar signs not wrapped in single-quotes tell the scripting engine to combine two strings ('abc' $ 'def' results in 'abcdef'). So, that mveval says to combine these three things:
    1. ​The numbers to the left of the decimal, if any. If there is no number it'll slap a zero in there.
    2. A period.
    3. The numbers to the right of the decimal, if any, adding zeroes to the right side of this number to make it a two-digit number.
    If you want a better understanding of the MivaScript functions I used, look here:
    Last edited by chrisb; 07-11-12, 06:11 AM.

    Comment

    • blubbert
      Mivite

      • Mar 2006
      • 113

      #3
      Re: How can I display or format a custom product field price like this $??.??

      Thanks so much Chris, I will look further into this. Great information and thanks for helping! I do have the toolkit.
      Brandon Lubbert
      Library and Educational Services

      A wholesale company for churches, day care providers,
      homeschools, libraries, missionaries, resellers and schools!


      www.libraryanded.com

      Comment

      • nottheusual1
        Mega Mivite


        • Jul 2008
        • 1124

        #4
        Re: How can I display or format a custom product field price like this $??.??

        There's always the old JavaScript standby:

        Comment

        • Brandon MUS
          Mega Mivite

          • Mar 2006
          • 1956

          #5
          Re: How can I display or format a custom product field price like this $??.??

          Wouldn't <mvt:item name="toolkit" param="currencyformat|formatted_yourvar|yourvar" /> do it?

          Comment

          • chrisb
            Mini Mivite

            • Nov 2010
            • 34

            #6
            Re: How can I display or format a custom product field price like this $??.??

            Originally posted by Brandon MUS View Post
            Wouldn't <mvt:item name="toolkit" param="currencyformat|formatted_yourvar|yourvar" /> do it?
            ...

            Yes... that'd do it.

            As I've said elsewhere, I love to overthink things when I don't know there's a simple solution. Hnng.
            Last edited by chrisb; 07-12-12, 10:12 AM.

            Comment

            • RayYates
              Developer Partner



              • Dec 2006
              • 1517

              #7
              Re: How can I display or format a custom product field price like this $??.??

              For Toolbelt users...

              <mvt:item name="ry_toolbelt" param="CurrencyFormat|g.SLPrice|l.all_settings:pro duct:customfield_values:customfields:SLPrice" />
              &mvt:global:SLPrice;
              Ray Yates
              "If I have seen further, it is by standing on the shoulders of giants."
              --- Sir Isaac Newton

              Comment

              Working...
              X