Follow us on Twitter X-Cart on Facebook Wiki
Shopping cart software Solutions for online shops and malls
 

Subscription Status If/Then

 
Reply
   X-Cart forums > X-Cart 4 > Dev Questions > Changing design
 
Thread Tools Search this Thread
  #11  
Old 07-01-2009, 11:16 AM
 
Momtreprenuer Momtreprenuer is offline
 

Member
  
Join Date: Jan 2008
Posts: 19
 

Smile Re: Subscription Status If/Then

Awww gb, thanks!! See I knew there was some help out there. 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!! 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
__________________
Version 4.1.12
Reply With Quote

The following 2 users thank Momtreprenuer for this useful post:
carpeperdiem (07-01-2009), gb2world (07-01-2009)
  #12  
Old 07-01-2009, 12:47 PM
  gb2world's Avatar 
gb2world gb2world is offline
 

X-Wizard
  
Join Date: May 2006
Location: Austin, TX
Posts: 1,970
 

Default 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
__________________
X-CART (4.1.9,12/4.2.2-3/4.3.1-2/4.4.1-5)-Gold
(CDSEO, Altered-Cart On Sale, BCSE Preorder Backorder, QuickOrder, X-Payments, BCSE DPM Module)
Reply With Quote
  #13  
Old 07-01-2009, 04:48 PM
 
Momtreprenuer Momtreprenuer is offline
 

Member
  
Join Date: Jan 2008
Posts: 19
 

Default Re: Subscription Status If/Then

Wow, thanks for that! Except I feel stupid again because I don't know what you just said! 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
__________________
Version 4.1.12
Reply With Quote
  #14  
Old 07-01-2009, 05:51 PM
  gb2world's Avatar 
gb2world gb2world is offline
 

X-Wizard
  
Join Date: May 2006
Location: Austin, TX
Posts: 1,970
 

Default 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));
__________________
X-CART (4.1.9,12/4.2.2-3/4.3.1-2/4.4.1-5)-Gold
(CDSEO, Altered-Cart On Sale, BCSE Preorder Backorder, QuickOrder, X-Payments, BCSE DPM Module)
Reply With Quote

The following user thanks gb2world for this useful post:
Momtreprenuer (07-01-2009)
  #15  
Old 07-01-2009, 07:49 PM
 
Momtreprenuer Momtreprenuer is offline
 

Member
  
Join Date: Jan 2008
Posts: 19
 

Default 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
__________________
Version 4.1.12
Reply With Quote
Reply
   X-Cart forums > X-Cart 4 > Dev Questions > Changing design



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -8. The time now is 01:53 PM.

   

 
X-Cart forums © 2001-2020