We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 19872
    • 1,078 Posts
    Hi Bob:

    I went back to modx.com extras and looked up the pdoTools extra, and the change log's most recent change included: - [#108] [pdoFetch] Fixed E_ERROR when using &sortbyTV. That's for version 1.10.1

    Coincidentally, the version I have loaded (1.9.7) is in need of an update. Guess I should have checked that first. Kind of like troubleshooting an internet connection. "Is the modem plugged in?" smiley

    Thanks for you help on this.


      • 3749
      • 24,544 Posts
      I'm pretty sure that was a response to my bug report, so it probably wasn't there until just before you looked. https://github.com/bezumkin/pdoTools/issues/108
        Did I help you? Buy me a beer
        Get my Book: MODX:The Official Guide
        MODX info for everyone: http://bobsguides.com/modx.html
        My MODX Extras
        Bob's Guides is now hosted at A2 MODX Hosting
        • 19872
        • 1,078 Posts
        Still kind of having major sort issues. Nothing I do is working to get pdoResources to sort by dollar amount.

        Sorting DESC by price, I figured out to change the input from Text, to be Number. While I am not typing in a dollar sign, I was entering commas. Now that the input has been changed to number, the field won't allow me to type a comma. Yet a straight number entered then does not output with commas. I need 3,695,000 not 3695000.

        When set to Text input, the sorting seems more alpha. The number 5 places higher than 10,800,000.

        Am I missing something?

        [[!pdoResources?
            &parents=`[[*id]]`
            &tpl=`propsSold-docs-thumbAlt-tpl`
            &limit=`100`
            &includeTVs=`pagetitle,propPrice,propNeighborhood,propTitle,propImage_main`
            &processTVs=`1`
            &TVprefix=``
            &depth=`1`
            &showHidden=`1`
            &sortbyTV=`propPrice`
            &sortdirTV=`DESC`
            ]]
          • 19872
          • 1,078 Posts
          I tried entering &sortbyTVType=`integer`
          That moved the highest price up to the top, but then within the rest of the items, pricing is out of order. It's just plain wacky.

          Is &sortbyTVType=`integer` as an option for pdoResources? I don't actually have documentation for pdoResources. Just kind of guessing for what might be available available by reading the pdoMenu and pdoParser lists of options.

            • 3749
            • 24,544 Posts
            I would try leaving them as text strings with no dollar sign or commas and creating a custom snippet using PHP's money_format() to display them: http://php.net/manual/en/function.money-format.php
              Did I help you? Buy me a beer
              Get my Book: MODX:The Official Guide
              MODX info for everyone: http://bobsguides.com/modx.html
              My MODX Extras
              Bob's Guides is now hosted at A2 MODX Hosting
              • 22427
              • 793 Posts
              From the manual:
              Note:
              The function money_format() is only defined if the system has strfmon capabilities. For example, Windows does not, so money_format() is undefined in Windows.
                • 19872
                • 1,078 Posts
                How about a hack?
                One TV for displaying price — Text input. Default output. Will output for display on screen with a dollar sign.
                Another TV for sorting — Numeral input, no commas no dollar signs, no decimals.
                [ed. note: mmcgee last edited this post 9 years, 2 months ago.]
                  • 19872
                  • 1,078 Posts
                  Sorry, I made a bunch of stream of consciousness posts. I've deleted and reduced to one question: How to I get commas to appear in the price?


                  TV for propPrice
                  Input: Number
                  Input Option Values: No Entry
                  Default Value: No Entry
                  Allow Blank: Yes
                  Allow Decimals: No
                  Allow Negative: No
                  Decimal Precision: 0
                  Decimal Separator: The default . appears regardless of whether I delete or not.
                  Max Value: No Entry
                  Min Value: No Entry

                  TV Output: Default

                  I have gone back to each resource and deleted to contents of the propPrice field and entered only a number (number input only permits numeric entry anyhow).

                  I have the dollar sign in my template html. (i.e. $[[+tv.propPrice]] so the output looks like below.

                  The ordering is sort order is definitely working, which is good! But where are the commas? How do I get the generated source code to include a comma?

                  $3695000
                  $3295000
                  $3272000
                  $3250000
                  $2950000
                  $2750000
                  $2195000
                  $2050000

                  THIS IS MY pdoRESOURCE CALL

                  [[!pdoResources?
                  &parents=`[[*id]]`
                  &tpl=`propsFeatured-docs-thumb-tpl`
                  &limit=`100`
                  &includeTVs=`propPrice,propNeighborhood,propTitle,propImage_main`
                  &processTVs=`1`
                  &TVprefix=``
                  &depth=`1`
                  &showHidden=`1`
                  &sortbyTV=`propPrice`
                  &sortbyTVType=`integer`
                  &sortdirTV=`DESC`
                  ]]
                    • 19872
                    • 1,078 Posts
                    Researching the use of an output modifier on the placeholder.

                    Seems odd. First I am making is so only a number can be entered. pdoResources is then being told to treat it like an integer, and then sort, and then I'm coming back around and trying to call the number something else. Seems like are lot of room for error.

                    I tested the blackjack output filter of :add=`21` and indeed it adds 21 to the source code displays. Just need one that adds a comma thousands separator.
                      • 19872
                      • 1,078 Posts
                      Found something that seems to be working, though I made one tweak to the output filter.

                      Everett had done a post at:

                      I created this snippet. (note: initially it gave me an error about unexpected '<' on line two. I went into my snippet code and put a line space just after the <?php

                      $number = floatval($input);
                      $optionsXpld = @explode('&', $options);
                      $optionsArray = array();
                      foreach ($optionsXpld as $xpld) {
                          $params = @explode('=', $xpld);
                          array_walk($params, create_function('&$v', '$v = trim($v);'));
                          if (isset($params[1])) {
                              $optionsArray[$params[0]] = $params[1];
                          } else {
                              $optionsArray[$params[0]] = '';
                          }
                      }
                      $decimals = isset($optionsArray['decimals']) ? $optionsArray['decimals'] : null;
                      $dec_point = isset($optionsArray['dec_point']) ? $optionsArray['dec_point'] : null;
                      $thousands_sep = isset($optionsArray['thousands_sep']) ? $optionsArray['thousands_sep'] : null;
                      $output = number_format($number, $decimals, $dec_point, $thousands_sep);
                      return $output;


                      Then on my tv placeholder in my output chunk for pdoResources, I did the following.
                      Changed:
                      [[+tv.propPrice`]]

                      To:
                      [[+tv.propPrice:numberformat=`&decimals=0&dec_point=.&thousands_sep=,`]]


                      The one change I made to the string is to swap the dot and the comma. Everett had dec_point=, and thousands_sep=.

                      Not sure whether I can pare down the string or not. I only need commas, and I don't quite understand want is meant by one, two or four in the php manual.

                      Perhaps I can get away with only the one?

                      [[+tv.propPrice:numberformat=`&thousands_sep=,`]]


                      At any rate. Items are sorting correctly based on price, and then getting commas added to the source code output. 2 days and a lot of frustration for numerically sorting items. I was gettin' close to sorting these by house color instead. smiley