X-Cart: shopping cart software

X-Cart forums (https://forum.x-cart.com/index.php)
-   Changing design (https://forum.x-cart.com/forumdisplay.php?f=51)
-   -   Subscription Status If/Then (https://forum.x-cart.com/showthread.php?t=48337)

Momtreprenuer 06-28-2009 12:33 PM

Subscription Status If/Then
 
Hi,
I've read ALL OVER the forum, (including: http://forum.x-cart.com/showthread.php?t=12511, http://forum.x-cart.com/showthread.php?t=8881, and http://forum.x-cart.com/showthread.php?t=46847) and I've seen many versions of if/then statements but I can't get them to work for what I need. All of the "if" membership statements are great but what would I code for a subscription status? For example, I have 3 subscription types: A, B, and C. I have a static page that is for current subscribers only that needs to show different content based upon the type of subscriber.


Is there a way to tweak the following to be able to use it for subscription types instead of membership types:

{if $user_membership eq '1'}
Content for 1
{elseif $user_membership eq '2'}
Content for 2
{else}
sorry, membership needed for access.
{/if}

I've tried every version of subscriptionid, subscription, productid etc. Please help!

Thanks in advance,
Momtrepreneur
X-cart Version 4.1.12

gb2world 06-28-2009 12:57 PM

Re: Subscription Status If/Then
 
Using trial and error with the smarty variables can be frustrating. Why not use this tip so you can see exactly what smarty variables are available and their values? If variables for subscription are not available where you need them, you will have to update the corresponding php files. This thread describes a more convenient method to switch back and forth with the debug popup.

Momtreprenuer 06-28-2009 01:32 PM

Re: Subscription Status If/Then
 
Thanks gb, that tip is neat. I was able to see lots of variables, but it seems like what I've found, I've used already! I must be inputting something wrong, missing a quote or period or something. Ugh! Please, if anyone can shed some light on this for me I would be very appreciative! In the meantime, I'm still trying different options.

carpeperdiem 06-30-2009 09:27 AM

Re: Subscription Status If/Then
 
Quote:

Originally Posted by Momtreprenuer
what would I code for a subscription status? For example, I have 3 subscription types: A, B, and C


What is a "subscription" ? Is this a mod that you installed?

Memberships. yes. But "subscriptions" -- where this set in xcart?

Momtreprenuer 06-30-2009 09:44 AM

Re: Subscription Status If/Then
 
Oh... no it came with my version 4.1.12. It's a module that you can activate by going to xcart > modules and selecting subscriptions. The membership feature would work for me, (and has as posted above) but memberships are not automated so I would have to manually check to make sure that the user had selected the correct membership. If I didn't catch it right away the user could have access to my protected content which are download links for my actual product. So, you can see my dilemma right?

gb2world 06-30-2009 09:46 AM

Re: Subscription Status If/Then
 
I suspect that you are trying to do a simple if-then on variables that do not exist without a mod of the php file.

When you say you think you have the right variable - what variable would that be? Post the code with the variable you are using and we can check your syntax.

Let me try and explain the tip provided a little better.

The debug window that comes up displaying all the variables shows you everything that is available in smarty for that page. If it is not there - it is not available. You would see the variable for subscription that you seek and what it is set to. You would not need to try a bunch of different ones - you would see exactly what you expect.

If it is not there, To make it available - you need to update the php to query the database to make the variables available to you. If you are not familiar with php or writing queries to get the information out of the database - this may be one for you to post in the professional requests forum, if you don't get response here. But you would need to be clearer in what you are doing to get better help.

It is unclear what subscriptions you are referring to - product subscriptions? Newsletter subscriptions? A mod that you had done to your shop?

For newsletter subscriptions - someone would have to be logged in. In the php - you would have to query the database to see if that person is subscribed to a newsletter, then set a variable in smarty to indicate which newslist, then you could do an if-than based on that variable. If the person is not logged in - you don't have a good way of knowing who they are.

For purchased subscriptions - I am not very familiar, but it might be something like this: Again - they would need to be logged in. In the php, you would have to query the database to see if that person has purchased one of the subscriptions and set a variable, which you could use in smarty to do an if/than.

carpeperdiem 06-30-2009 10:07 AM

Re: Subscription Status If/Then
 
Quote:

Originally Posted by Momtreprenuer
Oh... no it came with my version 4.1.12. It's a module that you can activate by going to xcart > modules and selecting subscriptions.


Ah... ok. I know zero about this module and the workings of it.

You will need to be certain that the php is delivering the smarty variables to the page(s). That is beyond my expertise.

At least we know where you need to start looking.

Good luck.

Jeremy

carpeperdiem 06-30-2009 10:32 AM

Re: Subscription Status If/Then
 
Just so happens... someone else is asking about subscriptions... and it appears that few use this, and few know anything about it. Even Eugene, one of the masters from xcart, didn't have specifics. I would join this thread...

http://forum.x-cart.com/showthread.php?t=48321

Momtreprenuer 06-30-2009 07:18 PM

Re: Subscription Status If/Then
 
Thanks you guys for the help!! I'm referring to the subscription module that comes with 4.1.12. It's not an extra mod I purchased or anything, it comes already installed. I use it for access to paid areas of my site. I have subscriber only (static) pages that need to be protected as well as my custom links on the product detail page that allow instant download to a subscriber. I've set the subscriptions up as a product ($productid) that renews on a scheduled basis.

Quote:

I suspect that you are trying to do a simple if-then on variables that do not exist without a mod of the php file.
Yes, I think that this is where the problem is.
Quote:

The debug window that comes up displaying all the variables shows you everything that is available in smarty for that page.
What I found were variables that I had already tried to use for the if/then statement. Here's the last one I tried:

Code:


{if $subscriptionid eq '1'}
please upgrade to download content free!
{elseif $subscriptionid eq '2' or $subscriptionid eq '3'}
download me!
{else}
We're sorry, you don't have the correct subscription type to access this content.  Please make sure you are logged in correctly.
{/if}


In the debug window (from the tip) I saw variables like:
Code:


{$sub_status} Array (3)
0 => "Active"
1 => "Unsubscribed"
2 => "Disabled"
{$subscription_search} Array (3)
search_productid => ""
search_producttitle => ""
search_customerlogin => ""
{$subscriptions_info} Array (3)
0 => Array (10)
  productid => "9"
  pay_period_type => "Monthly"
  product => "Choice Plus Subscription"
  subscribers_num => "0"
  customers => false
1 => Array (10)
  productid => "12"
  pay_period_type => "Annually"
{$subscription} Array (0)
{$user_membership} "Platinum 6"
{$user_subscription} ""
{$users_online} Array (1)
0 => Array (3)
  usertype => "C"
  count => "2"
  is_registered => "Y"
{$usertype} "C"

of course this is a shortened list. So what I meant by seeing variables I had already tried was that the variables shown ie: $subscription, $user_subscription, productid, pay_period_type, $subscriptions_info, $sub_status etc. where what I'd already tried with the code above in blue.

I'm familiar with php and queries, but only when the code is already written, meaning I can understand and move it around once it exists. I don't know how to write a brand new query.

Quote:

you need to update the php to query the database to make the variables available to you

This is EXACTLY what I think is missing in order for the request above to work. However, I don't know how to do so. I've tried imitating some of the membership queries (tags, smarty code or whatever they're called) but have had no luck. Shouldn't there be something I can add to include/check_useraccount.php or another php or tpl file? Something like this?
Code:

$subscription = $user_subscription['subscription'];

Or something similiar?

Thanks so much for the help, I really appreciate it. I'll keep trying. :?

Momtrepreneur

gb2world 07-01-2009 10:49 AM

Re: Subscription Status If/Then
 
Hi again -

I suspect this mod will not be in the "easy" category - you're going to have to dig around. I'll help best I can - but remember - I am speculating a lot - I don't have experience with subscriptions. I also don't have time to run test cases and figure this out, so you will have to do the heavy lifting. If it looks too hairy - you can just write up exactly what you want accomplished and post to the Professional Help Services Request forum or to QT.

First - I doubt there is an equivalent to the membership variable in the database for subscriptions. You can look in the tables in the database to see if something is there. Compare it to how membership id is handled. in the _customers table - you can see that every customer has an entry so you can see what membership id is associated with a customer. Look at the database for how information is stored for subscriptions. See how you can tell how to associate a particular subscription with a particular customer.

Since a subscription is probably not like a membership - it is associated with a product and an order - which is then associated with a customer - you are going to have to understand how all this is organized in the db in order to write a query to get the information. Once you understand how it is organized - write a query that pulls the data that you need. Get the query working independent of XCART.

You also have to consider in your query how you know the identity of the customer. I assume the customer has to be logged in. You will have to look through the php variables in XCART to see how this is done and use that in your query.

Once your query is ready - figure out what pages in the cart you will want this data. Add your query to the php file associated with those pages. You can look at examples from other mods to see how people have added queries to the php files. Store the results of your query to a smarty variable or array. Now - the smarty variable is available to your template for your if/than statements.

Momtreprenuer 07-01-2009 11:16 AM

Re: Subscription Status If/Then
 
Awww gb, thanks!! :D See I knew there was some help out there. :wink: Actually I was just about to post some good news. As is customary to my stubborn, relentless goal orientation, I finally figured out what to do! Here's what works:

I added:
Code:

$smarty->assign("user_subscription",$user_account["subscription"]);
to the end of check_useraccount.php

Then on product.tpl (where I have previously place a hidden instant download link), I wrapped the link like this:

Code:


{if $user_subscription ne ""}
<table width=100%><tr><td align=center><br><a href=my_download.php?f={$product.productcode}.zip>Download me!</a><td></tr></table>
{else}
subscribe to download me free!
{/if}


But then I wasn't satisfied so I kept going. I wanted to be able to check if the member was logged in and had a subscription and the subscription was current. So the final code looks like this:

Code:


{if $login ne "" and $user_subscription ne "" and $sub_status ne "Active"}
<table width=100%><tr><td align=center><br><a href=my_download.php?f={$product.productcode}.zip>Download me!</a><td></tr></table>
{elseif $login ne "" and $user_subscription ne "Unsubscribed"}
<table width=100%><tr><td align=center><br>Renew to download me free!<td></tr></table>
{elseif $login ne ""}
<table width=100%><tr><td align=center><br>Subscribe to download me free!<td></tr></table>
{else}
{/if}


Yay me!!:D/ Take that boys!

I wish that I could've figured out how to distinguish between what subs a user has, but I've already spent too much energy on this so I just dropped one of my subs.

Quote:

Since a subscription is probably not like a membership - it is associated with a product and an order - which is then associated with a customer - you are going to have to understand how all this is organized in the db in order to write a query to get the information.

Yes, this is my next task at hand. I'm trying to figure out how to associate my current subscribers (from another software) with x-cart. I managed to import all of the subscriptions into the database via Mysql but even though the correct number of subs shows, they don't appear within the sub module page. The correct number of subs is there but none of the info. So I suspect that I'm going to have to do something with importing old orders into the database, to get the subs to show. Only thing I keep running into is Mysql doesn't like the repeat sub number (identifier), so I have to figure out something there.

But I wanted to post the remedy that I found so that someone else wouldn't have to spend weeks trying to figure it out like me. Hope it helps!

Momtrepreneur

gb2world 07-01-2009 12:47 PM

Re: Subscription Status If/Then
 
Congrats! - on finding that! The fact that the user_subscription variable already exists is good news for you. There is already a query somewhere that is tying all this together for you. Hopefully - all you need to do is take a look at it and add the subscriptions a user has. Maybe the complication will be if they have more than one?

I did a quick grep for you and the query is here: /modules/Subscriptions/get_subscription_info.php

Now you just need to add your query to get an array with all the associated subscriptionids

Momtreprenuer 07-01-2009 04:48 PM

Re: Subscription Status If/Then
 
Wow, thanks for that! Except I feel stupid again because I don't know what you just said! :lol: Are you saying to insert:

$smarty->assign("user_subscription",$user_account["subscription"]);


into /modules/Subscriptions/get_subscription_info.php in order to be able to distinguish between the 3 available subs a user can have? What would I add to product.tpl? Maybe:


and $productid ne "12" (the product id of my yearly sub) or maybe


and $user_subscription eq "Annually" ?


Can you explain a little bit more for me please?

Thank you!

Momtrepreneur

gb2world 07-01-2009 05:51 PM

Re: Subscription Status If/Then
 
Now you have to dig deeper and know some MySQL and a little about querying the database. (Sorry - I don't know enough about subscriptions to answer you directly - maybe someone else knows the exact query you need.)

I was just pointing you to where the variable that you are using is getting read from the database. The query is what you see in the $query variable. You can study it and the table in the db it is using to see how they match the login with the user information in the database. (You'll need to know some MySQL). You can see that they are not trying to figure out how many subscriptions, or anything else except if the login matched. So - your query will be more complex. You have to write a query (not necessarily here) that pulls the subscription information (types of subscriptions) that you are after after it matches the login. This is where you will need to know how this information is organized in the db. And - you will have to decide how you want to handle the complication of a user having more than one subscription. You may have to add another query unless you know that modifying this one won't mess something else up.

More hints (hopefully helpful?):
When I'm dissecting their code to figure things out - I try things out - making extensive use of print_r and echo in the php, and print out smarty variables in the tpl to see the results of my experiments. (and use the smarty debug console)

I might try to add another function based on the is_user_subscribed, but call it something else like user_subscribed_to - then modify the query to get the other subscription information you want.

If you know exactly what tables all the data you need is stored, but need help with the query, and do not get a response here - I might try posting that to the MySQL forum. I've seen people answer questions there who are really good with the queries. You could make it easy for someone by knowing exactly what tables in the db your info lives. I don't think there are all that many that are associated with subscriptions. It may get complicated if you have to start extracting information from the orders table.


This is where the function is called that sets the variable that you are using:
./postauth.php:171: $smarty->assign("user_subscription", is_user_subscribed($login));

Momtreprenuer 07-01-2009 07:49 PM

Re: Subscription Status If/Then
 
Perfect! My thoughts exactly... although they weren't as organized as that! I've played with quite a bit of echo in the past, don't know why I didn't think of that! Duh! For now, I'll stick with what I have and then later I may dive a little deeper. If I do come up with some valuable working code I'll post it here too.

Thank you so much for all of your input!!

Momtrepreneur


All times are GMT -8. The time now is 05:11 AM.

Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.