11 replies [Last post]
quixote's picture
Offline
Joined: 08/08/2008
Juice: 20
Was this information Helpful?

I am setting up a subscription-membership site and would like to use Ubercart for this system. I have everything set up great but came to one issue — I can only send 1 reminder email to the user when their account is about to expire. My client would like reminders sent at 30 days & 14 days before, and again one day before expiration.

Is there a way to alter Ubercart to allow for multiple reminder emails? I realize this is not a prebuilt function and some php trickery would be involved. Anyone got a solution? I have delved into the source for uc_notify and uc_roles, just not sure what I should change or if it's even possible.

Any help is greatly appreciated!

** Oh yeah, I'm using Drupal 5.7 and Ubercart 1.0 (the latest release). **

quixote's picture
Offline
Joined: 08/08/2008
Juice: 20
Re: Multiple reminder emails

Anyone have any thoughts on this? (Perhaps the wise and beneficient Ryan?) I need to make an "executive decision" if I can't get this to work. Thanks!

Ryan's picture
Offline
Joined: 08/07/2007
Juice: 15438
Re: Re: Multiple reminder emails

Sorry, I don't have a fix-all solution, but I can show the way. Eye-wink

Check out the function uc_roles_cron() in uc_roles.module. This function gets called every cron run, so you can copy/paste this code into a custom module (and rename the function according to your module's name) and add your own timed e-mails.

You'll probably have to do some custom tracking to make sure you don't send out too many reminder e-mails to the same person.

torgosPizza's picture
Offline
Bug FinderEarly adopter... addicted to alphas.Getting busy with the Ubercode.
Joined: 08/14/2007
Juice: 4110
Re: Re: Re: Multiple reminder emails

Might be a cool feature to patch later on. The ability to include a "pre=warning notice" that is dispatched after a certain threshold. Ah, ideas! I can't wait until this major development I'm in right now is over so I can just start coding cool stuff like that Smiling

--
Help directly fund development: Donate via PayPal!

quixote's picture
Offline
Joined: 08/08/2008
Juice: 20
Thanks!

Thanks for the guidance, Ryan! All I needed was a little shove in the right direction. Smiling

amit's picture
Offline
Joined: 07/27/2009
Juice: 12
Multiple Notification

Can any one share the code which works ?
I want to send Subscription Renewal Reminder mails.

zeezhao's picture
Offline
Joined: 04/23/2008
Juice: 969
Re: Multiple Notification

You can also explore simplenews and it associated simplenews_scheduler + simplenews_sub_manager to do something like this. You will have to fake the email as a kind of "newsletter"...

See: http://drupal.org/project/simplenews

Also see: http://drupal.org/project/mailout [but no drupal 6 version]

amitkarpe's picture
Offline
Joined: 08/03/2009
Juice: 9
Thank you.

Thank you.
I will test and let you update.

acushla's picture
Offline
Joined: 06/10/2011
Juice: 3
Found a solution

Hi,I found a solution to the multiple reminder issue which  ensures- there are no duplicate reminders sent- you can send as many reminders as you likeI have used a rule which executes on cron run to execute my custom php code. since my site may need to run several times in a day I have included a check by using the user_variable module. I set the variable attached with the user when the reminder is sent. The same variable prevents multiple mail sending on the same day. The user_variable module provides an option to expire the variable after predefined time thus clearing the variable automatically after the day on which the reminder is set is over.The following code sends a reminder on 7 days and 2 days before the date of expiry. I am sorry I have not been able to find the time to make the code clean and highly intuitive. Nevertheless, thought that posting here may help someone.Taking  this opportunity to thank the developers and the users of Ubercary who have evolved excellent modules and community supporting it.

<?php
  $datenow
= getdate();
 
$day = 24 * 60 * 60;
 
$result = db_query("SELECT * FROM {uc_roles_expirations}");
  while (
$expiration = db_fetch_object($result)) {
   
$account = user_load($expiration->uid);
    
// User has to contain roles to manage.
   
if (!is_array($account->roles) || !count($account->roles)) {
    continue;
    }
    if ((((
$expiration->expiration-$day*7)<=time()) && (time()<($expiration->expiration-$day*6))) || ((($expiration->expiration-$day*2)<=time()) && (time()<($expiration->expiration-$day*1)))){
      if (!
user_variable_check('ReminderSentToday', $common = FALSE, $uid = $account->uid)){
       
user_variable_set('ReminderSentToday', TRUE, $common = FALSE, $uid = $account->uid, $expired = 1*$day, $session = FALSE);
       
ca_pull_trigger('uc_roles_notify_reminder', $account, $expiration);    
      }
    }
  }
?>
xaris.tsimpouris's picture
Offline
Joined: 01/03/2011
Juice: 28
After some small changes

I made some small changes so as to be more easy to set the days you want, before expiration.

For example, the follwing is set for 30, 15 7 and two days before role expiration

  $dates_to_remind = array(-30, -15, -7, -2);

  $datenow = getdate();
  $day = 24 * 60 * 60;
  $result = db_query("SELECT * FROM {uc_roles_expirations}");
  while ($expiration = db_fetch_object($result)) {
    $account = user_load($expiration->uid);
  // User has to contain roles to manage.
    if (!is_array($account->roles) || !count($account->roles)) {
      continue;
    }
 
    $must_remind = FALSE;
    foreach($dates_to_remind as $cur_date) {
      if ((($expiration->expiration + $day * $cur_date) <= time()) && (time() < ($expiration->expiration + $day * ($cur_date + 1)))) {
        $must_remind = TRUE;
        break;
      }
    }
 
    if ($must_remind) {
      if (!user_variable_check('ReminderSentToday', $common = FALSE, $uid = $account->uid)){
        user_variable_set('ReminderSentToday', TRUE, $common = FALSE, $uid = $account->uid, $expired = 1 * $day, $session = FALSE);
        ca_pull_trigger('uc_roles_notify_reminder', $account, $expiration);
      }
    }
  }

Liliplanet's picture
Offline
Joined: 06/14/2008
Juice: 29
Trying to get property of non-object in uc_roles_cron

Hi,

Sorry for my ignorance, but where do I add the function, to the uc_roles.module?

The reason is that I'm also have the error on cron run:

Notice: Trying to get property of non-object in uc_roles_cron() (line 42 of /home/public_html/sites/all/modules/ubercart/uc_roles/uc_roles.module)

and hoping that the patch will fix this ..

Most appreciate any reply, and thank you Smiling

schtink's picture
Offline
Joined: 09/19/2011
Juice: 18
Thanks!

Your code helped me with an entirely different issue.

I was getting an error when running cron:
Notice: Trying to get property of non-object in uc_roles_cron() (line 42 uc_roles.module).

I patched my module with your code and the problem was solved! Great for me since I'm not really an expert at PHP.

Thanks again!