We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 37015
    • 21 Posts
    Hello

    Rather quick question - in regards to the package CatalogSearch 1.0.

    It seems to be common knowledge that the original dev. for this package isn't contactable, so I'm trying to customize this myself (with my very basic knowledge).

    I want to edit the CatalogSearch snippet - this controls what TV's are shown as filters for a search.

    For example, this is how the form currently looks:



    It has pulled back all the TV's that are of the "List Box (Single Select)" type - using the following code:

    foreach($tvids as $tvid){
      $q = $modx->newQuery("modTemplateVar");
      $q->where(array("id"=>$tvid->get("tmplvarid")));
      $tvs = $modx->getCollection("modTemplateVar",$q);
      foreach($tvs as $tv) {
        if($tv->get("type") == "listbox")
          $TVars[] = array(
    	  "name" => $tv->get("name"),
    	  "caption" => $tv->get("caption"),
    	  "type" => $tv->get("type"),
    	  "id" => $tv->get("id")
          );
      }
    }


    I have some TV's which are of the "List Box (Multi Select)" format, which I would like the snippet to pull back, and display as a filter.

    I think the code needs to be edited to look like this:

    foreach($tvids as $tvid){
      $q = $modx->newQuery("modTemplateVar");
      $q->where(array("id"=>$tvid->get("tmplvarid")));
      $tvs = $modx->getCollection("modTemplateVar",$q);
      foreach($tvs as $tv) {
        if($tv->get("type") == "listbox" || $tv->get("type") == "??NEED_TO_KNOW_TYPE_NAME??")
          $TVars[] = array(
    	  "name" => $tv->get("name"),
    	  "caption" => $tv->get("caption"),
    	  "type" => $tv->get("type"),
    	  "id" => $tv->get("id")
          );
      }
    }


    As you can see I don't know what the variable name / identifier is for the List Box (Multi Select) TV type.

    Does anyone else know?

    It would be greatly appreciated.

    Thanks
    Dan
      • 3749
      • 24,544 Posts
      Try this:

      listbox-multiple


      You could also do this:

      if (strpos($tv->get('type'), 'listbox')) 
        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
        • 37015
        • 21 Posts
        Hi

        Thanks - the first one worked perfectly.

        To note you also have to change this code for it to work:

            $ranges[] = array("name" => $TVars[$i]["name"], "max" => $max);
          }
           if($TVars[$i]["type"]=="listbox") {
             $sRaw = $modx->getObject("modTemplateVar", $TVars[$i]["id"]);
             $sValue = $sRaw->get('elements');