We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 3186 ☆ A M B ☆
    • 279 Posts
    Hi All,

    I can understand this topic title is a little confusing; I hope I could explain it here a little more.

    I have an product overview, build with getResources. For every product I have made a TV named ’productBrand’. Where the value of this TV always is a resource id. (every brand is a resource). Now I want to filter the results on this brand. So I parse a multiple select value (eq. array) in the URL like:

    ...?brand[]=204&brand[]=312

    A simple snippet of my own builds a string like:

    productBrand==204||productBrand==312

    This one is parsed into the getResources ’tvFilters’ option. So far, so good.

    When I had one brand selected, so one brand to filter, the result is as expected. Only products with that brand are shown. But when I had multiple brands selected, as above, the result shows me every product, also products with a different brand.

    Could anyone help me out? Thanks in advance

    Regards, Bert
      MODX Ambassador (NL) & Professional MODX developer
      Follow me on Twitter | Visit my page on Facebook | View my code on Github | View my script posts
      MODX e-commerce solution SimpleCart
      • 18463
      • 121 Posts
      Martijn van Turnhout Reply #2, 15 years, 5 months ago
      Have you used wildcards? I’ve once used a TV before to select multiple categories. http://modxcms.com/forums/index.php/topic,62876.msg356481.html#msg356481
        • 3186 ☆ A M B ☆
        • 279 Posts
        No I don’t; because the ID’s could be 1 or 100 or 10.. I don’t know, so a wildcard isn’t an option.

        I read that topic and there was suggest to use the alias (a name) instead of ids, but with a little 600/700 products it isn’t easy to change this :-( no other options for me?
          MODX Ambassador (NL) & Professional MODX developer
          Follow me on Twitter | Visit my page on Facebook | View my code on Github | View my script posts
          MODX e-commerce solution SimpleCart
          • 4172
          • 5,888 Posts
          you can try this (not tested, maybe buggy):
          <?php
          //[[!getRequested? &param=`brand` &tvname=`productBrand` ]] 
          //[[+requestedIds]] 
          
          $tvname = $modx->getOption('tvname',$scriptProperties,'');
          $toPlaceholder = $modx->getOption('toPlaceholder',$scriptProperties,1);  
          
          
          if (! empty($tvname))
          {
              $tvObject = $modx->getObject('modTemplateVar', array ('name'=>$tvname));
              $tmplvarid = $tvObject->get('id');
              $values = $_GET[$param];
              $c = $modx->newQuery('modTemplateVarResource');
              $c->where( array ('tmplvarid'=>$tmplvarid, 'value:IN'=>$values));
              //$c->prepare();echo $c->toSql();
              if ($resources = $modx->getCollection('modTemplateVarResource', $c))
              {
                  foreach ($resources as $resource)
                  {
                      $ids[] = $resource->get('contentid');
                  }
                  $ids=implode(',', $ids);
          		if (!empty($toPlaceholder)){
                      $modx->setPlaceholder('requestedIds',$ids);
                      return '';		
          		}
          		return $ids;
              }
          }
          $ids = '0';
          if (! empty($toPlaceholder))
          {
              $modx->setPlaceholder('requestedIds', $ids);
              return '';
          }
          return $ids;


          call ist like this:

          [[!getRequested? &param=`brand` &tvname=`productBrand` ]] 
          [[+requestedIds]] 


          if it works you can use getResources with
          &resources=`[[+requestedIds]]`


            -------------------------------

            you can buy me a beer, if you like MIGX

            http://webcmsolutions.de/migx.html

            Thanks!
            • 3186 ☆ A M B ☆
            • 279 Posts
            Hi Bruno,

            Your snippet works like a charm! But when I pass the placholder into ’resources’ parameter of getResources, I just get strange results again.

            could it be the combination of getPage and getResources? :$ I forgot to say that smiley

            This is my complete tag

            [[!getPage@defaultPaging?
                  &element=`getResources`
                  &parents=`[[*id]]`
                  &resources=`[[+requestedIds]]`
                  &includeTVs=`1`
                  &tpl=`productOverviewItem`
                 
                  &where=`{"template:=":3}`
                  &cache=`0`
                  
                  &sortbyTV=`productPrice`
                  &sortdirTV=`[[!getReqParam:eq=`price-desc`:then=`DESC`:else=`ASC`? name=`sort`]]`
                  &sortbyTVType=`decimal`
                  &limit=`[[!getReqParam:default=`9`? &name=`pp`]]`
            ]]
              MODX Ambassador (NL) & Professional MODX developer
              Follow me on Twitter | Visit my page on Facebook | View my code on Github | View my script posts
              MODX e-commerce solution SimpleCart
              • 4172
              • 5,888 Posts
              did you try it with getResources alone?
                -------------------------------

                you can buy me a beer, if you like MIGX

                http://webcmsolutions.de/migx.html

                Thanks!
                • 34712
                • 3 Posts
                Hello,

                I am working on the same kind of filtering and I have noticed that the "resources" parameter of getResources is adding products to a current list.

                I dont want the "resources" parameter to add things to a list of products.

                Is that possible that the "ressources" parameter only shows the products that are defined in ?

                For example, I have a folder "products (id = 5)" in which I have 10 products and only want to display products with id 8 and 9 of that folder.

                So the call will be :

                [[!getResources? &parents=`5` &tpl=`product` &processTVs=`1` &resources=`8,9` &includeTVs=`1` &tvPrefix=``]]

                But it’s not only showing the products 8 and 9.

                Any solution ?

                Thanks

                Sam
                  • 3186 ☆ A M B ☆
                  • 279 Posts
                  For as far I know, the parents parameter doesnt need to be given then. Only ’resources’ is required then.. correct me if I’m wrong
                    MODX Ambassador (NL) & Professional MODX developer
                    Follow me on Twitter | Visit my page on Facebook | View my code on Github | View my script posts
                    MODX e-commerce solution SimpleCart
                    • 22303 MODX Staff
                    • 10,725 Posts
                    Try setting the &parents property to -1 — otherwise, it will assume the current Resource as the parent and include it’s children in addition to the specific Resources you include via the &resources property.
                      • 34712
                      • 3 Posts
                      bertoost,

                      the problem is not solved by removing the "&parents" parameter.


                      OpenGeek,

                      It’s working with your solution by putting " &parents=`-1` ".


                      Thanks guys smiley