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

    I’m not a programmer. I’m trying to display a catalog view with images. Prices are only to be displayed to web users logged in to the "Retailers" group. I’m using Ditto with pagination. I have one template for normal view and a different one with the prices. What is the best way to accomplish this?

    I’m using Evo 1.0.1

    Any advice is much appreciated.
      illegitimati non carborundum
      • 5340
      • 1,624 Posts
      You can use 2 different Ditto calls
        • 15022
        • 31 Posts
        Thanks for your reply. How do I add the logic to choose between one call or the other?
          illegitimati non carborundum
          • 5340
          • 1,624 Posts
          I am not familiar with how you could test if a user is logged in or not but here’s how I think you should do it

          create a snippet called showProducts and call it uncached


          <?php
          if( put here a way to check if a web user is logged in  ){
          	
          	$dittoOutput = $modx->runSnippet("Ditto", array('parents' => 33, 'tpl' => 'loggedInTpl'));
          	
          }else{
          
          	$dittoOutput = $modx->runSnippet("Ditto", array('parents' => 33, 'tpl' => 'notLoggedInTpl'));
          	
          }
          
          return $wayfinderOutput;
          ?>
          


          This just the basic so you will need to modify your ditto calls

            • 4310
            • 2,310 Posts
            Untested but try :

            <?php
            if($modx->getLoginUserID()){
            	
            	$dittoOutput = $modx->runSnippet("Ditto", array('parents' => 33, 'tpl' => 'loggedInTpl'));
            	
            }else{
            
            	$dittoOutput = $modx->runSnippet("Ditto", array('parents' => 33, 'tpl' => 'notLoggedInTpl'));
            	
            }
            
            return $dittoOutput;
            ?>
              • 4041
              • 788 Posts
              Expanding on the above snippets, to denote specific web groups I think this would work better.

              <?php
              /*  showProducts
                  usage: [!showProducts!]
              */
              
              if($modx->isMemberOfWebGroup( array('Retailers'))){
              
              	$dittoOutput = $modx->runSnippet("Ditto", array('parents' => 33, 'tpl' => 'loggedInTpl'));
              	
              }else{
              
              	$dittoOutput = $modx->runSnippet("Ditto", array('parents' => 33, 'tpl' => 'notLoggedInTpl'));
              	
              }
              
              return $dittoOutput;
              ?>
                xforum
                http://frsbuilders.net (under construction) forum for evolution
                • 15022
                • 31 Posts
                Breezer: THANK YOU, THANK YOU!

                I was unsure of what arguments to pass to isMemberOfWebGroup() function.. it’s not listed on the documentation yet. It is now working as it should except for one pretty big detail: pagination. I have to call the [[showPrices]] snippet uncached to get Ditto to paginate.

                I’m using a Ditto call that requires pagination... there are 72 products spread over 5 pages. The prices now toggle on and off based on my login group status BUT... I lose the pagination because Ditto needs to be called cached and I uncached my page to accommodate that.

                Help! I’m sure there is someone out there who understands this better than I do.

                Here is my code:
                <?php
                if($modx->isMemberOfWebGroup(array('Retailers'))){
                  $dittoOutput = $modx->runSnippet("Ditto", array('parents' => 5, 'tpl' => 'tpl-catalog-ws', 'display' => 15, 'paginate' => 1, 'showInMenuOnly' => 0, 'paginateAlwaysShowLinks' => 1, 'orderBy' => 'menuindex asc', 'filter' => 'type,reference,2'));
                } else { 
                // Page visitor is not logged in as a Retailer.
                   $dittoOutput = $modx->runSnippet("Ditto", array('parents' => 5, 'tpl' => 'tpl-catalog-noe', 'display' => 15, 'paginate' => 1, 'showInMenuOnly' => 0, 'paginateAlwaysShowLinks' => 1, 'orderBy' => 'menuindex asc', 'filter' => 'type,reference,2'));
                }
                return $dittoOutput;
                ?>
                


                Again, many thanks.
                  illegitimati non carborundum
                  • 15022
                  • 31 Posts
                  SOLVED

                  That was my bad. I tested using [!showPrices!] instead of [[showPrices]] and that was what caused the problem. It is fixed now.

                  So to recap, I have the document Resource uncached, the snippet call cached and the pagination is working in Ditto as is the user group detection. Very clever. Thank you to everyone who replied! This community is great.

                  Here is the website, should be live later today (please excuse some yucky styling that I’ve yet to fix):
                  http://www.jsfreeman.com
                    illegitimati non carborundum