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
-
☆ 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;
}
Thanks Susan,
But could you pls explain the steps to set this up?
-
☆ 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.
-
☆ 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;
?>
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?
-
☆ 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
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?
-
☆ 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;
?>