Modify CartWeaver functionality based on customer login
A CartWeaver user asked the question:
"I want to have viewers Register (or, log in if they've already registered) before they can see anything in the cart. How would I do this?"
Here's my quick answer:
In Cartweaver, the trigger for whether someone is logged in can be found in the "client.customerID" variable.
So, any logic that you want to base on 'if a customer is logged in', might look like this:
<cfif isDefined('client.customerID') AND client.customerID gt 0>
THE USER IS LOGGED IN
<cfelse>
THE USER IS NOT LOGGED IN, SHOW THE LOGIN FORM, HIDE THE CART CONTENT
(or redirect to login page.. whatever)
</cfif>
When someone logs in, their 'ID' gets stored in the 'client' scope.
(Simply put, a variable that follows them around during their session on the site).
If they have a clientID defined and it is greater than '0', we can assume they have logged in already.
( I use isDefined() as a safeguard, but actually the default for this variable, if not logged in, is simply 0. )
You can safely wrap this line around anything you want to show ONLY if somebody is logged in
<cfif isDefined('client.customerID') AND client.customerID gt 0>
STUFF HERE
</cfif>
And if you only want stuff to show when the person is NOT logged in
<cfif (isDefined('client.customerID') AND client.customerID eq 0) OR not isDefined('client.customerID')>
STUFF HERE
</cfif>
Again, simpler version would be just:
<cfif client.customerID eq 0>
but I like to make sure the var exists when giving code examples,
so you can put that code anywhere in your site you like.


Request.ThisPage NEQ "Login.cfm"