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

    If this have been covered before then i apologize but i can’t find a solution anywhere.

    I have a product catalog with multiple TV’s:
    UNIT | SIZE | STOCK CODE | etc....

    I need to add a PRICE TV and only have it visible to web users that are logged on.
    so the public can see the product but cannot see the PRICE unless they log on

    Is this possible??

    thanks
      • 28042 ☆ A M B ☆
      • 24,524 Posts
      Use a snippet to act as a custom TV output widget. Your snippet will check for login status, and only if the user is logged in will the snippet get the TV value and display it.
      <?php
      if(isset($_SESSION['webValidated'])) [
          $tv = $modx->getTemplateVar('tvname');
          // format TV value for display
          $output = '<span>$ ' . $tv . '</span>';
          return $output;
      }
      return;
      }
      


        Studying MODX in the desert - http://sottwell.com
        Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
        Join the Slack Community - http://modx.org
        • 10489
        • 93 Posts
        Thanks Susan,

        But could you pls explain the steps to set this up?
          • 28042 ☆ A M B ☆
          • 24,524 Posts
          Make your TV to hold the price. Then make a new snippet with the (improved) code below; use the snippet tags where you would have put the TV tags.
            Studying MODX in the desert - http://sottwell.com
            Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
            Join the Slack Community - http://modx.org
            • 10489
            • 93 Posts
            ok,

            i created a snippet called ’price_check’ and added the following:
            <?php
            if(isset($_SESSION['webValidated'])) [
                $tv = $modx->getTemplateVar('price');
                // format TV value for display
            
                return $tv;
            }
            return;
            }
            ?>

            Then in my document i removed the TV tag [*price*] and replaced it with [[price_check]]

            It’s not working...:)
              • 28042 ☆ A M B ☆
              • 24,524 Posts
              Well, yeah, there’s a typo there (I really need to cut my fingernails).
              <?php
              if(isset($_SESSION['webValidated'])) {
                  $tv = $modx->getTemplateVar('price');
                  // format TV value for display
              
                  return $tv;
              }
              return;
              
              ?>
                Studying MODX in the desert - http://sottwell.com
                Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
                Join the Slack Community - http://modx.org
                • 10489
                • 93 Posts
                Sorry Susan, not happening here.

                Does it make a difference if i’m logged in as admin?

                I’ve pasted you code below into the price_check snippet and called it in the document using [[price_check]]
                and i have made sure that i have inputted a price in the TV..

                Am i missing something here?
                  • 28042 ☆ A M B ☆
                  • 24,524 Posts
                  Dunno; I shouldn’t be doing this stuff off the top of my head this time of day; let me go test this and see what I’ve got wrong rolleyes
                    Studying MODX in the desert - http://sottwell.com
                    Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
                    Join the Slack Community - http://modx.org
                    • 10489
                    • 93 Posts
                    Thanks Susan,

                    Could it be the access permissions in my document or in my TV or even possibly the way the TV has been created?
                      • 28042 ☆ A M B ☆
                      • 24,524 Posts
                      No, it’s my nap-time stupidity.

                      First, you have to call the snippet uncached (otherwise the page will have the same display it had when it was cached, whether or not the user is logged in)

                      Second, that return value is an array, so the snippet has to be like this:
                      <?php
                      if(isset($_SESSION['webValidated'])) {
                          $tv = $modx->getTemplateVar('price');
                          // format TV value for display
                      
                         return $tv['value'];
                      }
                      return;
                      ?>
                        Studying MODX in the desert - http://sottwell.com
                        Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
                        Join the Slack Community - http://modx.org