We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 41395
    • 8 Posts
    I have a product catalog with a template variable to store the price. I am also running getresources within a snippet and that seems to work no problem as well. The problem occurs when trying to filter the result set using the price. For example, I have a price that is > 0 and < 300. There is no result at all when there should be a result. I can filter by the category tv no problem.

    Here is the snippet call inside the snippet:

    
    output = $modx->runSnippet('getResources',array(
    'parents'=>'8',
    'tpl'=>'grid_detail',
    'includeTVs'=>'1',
    'tvPrefix'=>'',
    'limit'=>'',
    'processTVs'=>'1',
    'showHidden'=>'1',
    'hideContainers'=>'1',
    'tpl_2'=>'grid_detail_middle',
    'tpl_n3'=>'grid_detail_middle',
    'idx'=>'5',
    'depth'=>'0',
    'tvFilters'=>"tv.product_category==$category,tv.product_price > $lowerprice,tv.product_price < $higherprice",
    'sortbyTV'=>'tv.product_price',
    'sortdirTV'=>'ASC',
    'sortbyTVType'=>'decimal'
    ));
    


    Is this a limitation of getresources with regards to evaluating numeric tv values or is there something wrong with my code?
      • 33968
      • 863 Posts
      Try removing the 'tv.' prefix in your filters
        • 41395
        • 8 Posts
        Quote from: okyanet at Nov 18, 2012, 11:33 PM
        Try removing the 'tv.' prefix in your filters

        Thanks for the suggestion. I had some previous issues with the prefix since I discovered that getresources uses "tv." by default in its snippet call. I had fixed that issue already by setting 'tvPrefix'=>'' which you can see is already set as a parameter in my snippet call. Also, I know that the snippet is reading my template variables since I had used tv.product_category==$category as a filter and that worked just fine.
          • 33968
          • 863 Posts
          You might also try removing the space around the operator:
          'tvFilters' => "tv.product_category==$category,tv.product_price>$lowerprice,tv.product_price<$higherprice",
          

          I haven't used getResources for a while, nothing else jumps out at me
            • 11742 ☆ A M B ☆
            • 53 Posts
            According to http://rtfm.modx.com/display/ADDON/getResources (section tvFilters table on bottom of cell) you should use << or >> instead of < or >

            'tvFilters' => "tv.product_category==$category,tv.product_price>>$lowerprice,tv.product_price<<$higherprice",
              Freelance Web Developer who likes MODX, PHP, jQuery, ExtJS, SASS and other cool web things. Currenty doing great stuff at COEX CZ.

              GitHub: https://github.com/hansek
              Follow me: https://twitter.com/jantezner
              Or follow us: https://twitter.com/coexcz

              http://www.modx.cz || http://www.coex.cz
              • 33968
              • 863 Posts
              @Hansek: from what I understood, they are new operators you can use in addition to the existing ones. There's a slight difference in that they cast the TV values as 'numeric' when filtering (instead of 'string'). It would probably help to use those in this case...
                • 41395
                • 8 Posts
                Quote from: okyanet at Nov 19, 2012, 12:22 AM
                You might also try removing the space around the operator:
                'tvFilters' => "tv.product_category==$category,tv.product_price>$lowerprice,tv.product_price<$higherprice",
                

                I haven't used getResources for a while, nothing else jumps out at me

                Thanks. Tried that already. Tried it both ways with no spaces and with spaces. Somehow I have a suspicion that this problem is related to how the data is stored in the modx_site_tmplvar_contentvalues table. Template variable values are stored in a field called value which is of type mediumtext. My hunch is that getresources has no way of casting values from that field as numeric and maybe that is why I keep getting no results. Just a hunch, though.
                  • 11742 ☆ A M B ☆
                  • 53 Posts
                  @Lucas: In getResources code are defined only these operators:
                      
                  $operators = array(
                          '<=>' => '<=>',
                          '===' => '=',
                          '!==' => '!=',
                          '<>' => '<>',
                          '==' => 'LIKE',
                          '!=' => 'NOT LIKE',
                          '<<' => '<',
                          '<=' => '<=',
                          '=<' => '=<',
                          '>>' => '>',
                          '>=' => '>=',
                          '=>' => '=>'
                      );
                  


                  @eldorado2768: try to use syntax with >> or << wink
                    Freelance Web Developer who likes MODX, PHP, jQuery, ExtJS, SASS and other cool web things. Currenty doing great stuff at COEX CZ.

                    GitHub: https://github.com/hansek
                    Follow me: https://twitter.com/jantezner
                    Or follow us: https://twitter.com/coexcz

                    http://www.modx.cz || http://www.coex.cz
                    • 11742 ☆ A M B ☆
                    • 53 Posts
                    Or try to set parameter &debug=`1` it will send the SQL query to the MODx log. Then will be easier to found problem.
                      Freelance Web Developer who likes MODX, PHP, jQuery, ExtJS, SASS and other cool web things. Currenty doing great stuff at COEX CZ.

                      GitHub: https://github.com/hansek
                      Follow me: https://twitter.com/jantezner
                      Or follow us: https://twitter.com/coexcz

                      http://www.modx.cz || http://www.coex.cz
                      • 41395
                      • 8 Posts
                      Quote from: Hansek at Nov 19, 2012, 12:48 AM
                      @Lucas: In getResources code are defined only these operators:
                          
                      $operators = array(
                              '<=>' => '<=>',
                              '===' => '=',
                              '!==' => '!=',
                              '<>' => '<>',
                              '==' => 'LIKE',
                              '!=' => 'NOT LIKE',
                              '<<' => '<',
                              '<=' => '<=',
                              '=<' => '=<',
                              '>>' => '>',
                              '>=' => '>=',
                              '=>' => '=>'
                          );
                      


                      @eldorado2768: try to use syntax with >> or << wink

                      Yep, that was it. Thanks!