Modify Plug In for akeeba Subscriptions

  • Posts: 184
  • Thank you received: 4
12 years 3 months ago #59378

We sell normal products and also subscriptions.
The subscriptions give the opportunity to buy the products (without a valid subscription it is no possible to buy the products).
With have different subscriptions with different duration.
To enable on my web site this feature I am using AkeebaSubscreption and the relative HikaShop Plug In.

I tested your plug-in with akeeba subscriptions and it works fine :cheer: , but we have a different method to start the subscription period depending on when the customer buy the subscrition.

For example
Customer A: buys the subscription of one month as the 25th of April, the subscription period has to start the 20th of MAY and continue for 30 days.
Customer B: buys the subscription of one month as the 5th of May, the subscription period has to start the 20th of MAY and continue for 30 days.
Customer C: buys the subscription of one month as the 6th of May, the subscription period has to start the 20th of JUNE and continue for 30 days.

In practice, if a customer buys from the 20th of April to the 5th of May, the subscription has to start the 20th of May.
if a customer buys from the 6th of May to the 19th of May, the subscription has to start the 20th of June.

To obtain this behaviour is necessary modify the plug in?
Could you give me some help to do that?

Thanks in advance.

Please Log in or Create an account to join the conversation.

  • Posts: 82863
  • Thank you received: 13372
  • MODERATOR
12 years 3 months ago #59433

It will indeed be necessary that you change the code of the plugin.

These lines are what calculates the date when the subscription has to start and the date when it has to stop:
$date = date('Y-m-d H:i:s', $timestamp);
$publish_up = $date;
$publish_down = date("Y-m-d H:i:s", $timestamp+(86400*$level_duration*$result->order_product_quantity));
You will need to change them in order to accomodate with what you want to do.
Maybe something like that:
$day = date('d',$timestamp);
$month = date('m',$timestamp);
if($day>=6 AND $day <=19)$new_month=$month+1;
elseif($day>19)$new_month=$month+2;
else $new_month=$month;
$date = str_replace('-'.$month.'-','-'.$new_month.'-',date('Y-m-d H:i:s', $timestamp));
$publish_up = $date;
$publish_down = date("Y-m-d H:i:s", $timestamp+(86400*$level_duration*$result->order_product_quantity));

Please Log in or Create an account to join the conversation.

  • Posts: 184
  • Thank you received: 4
12 years 3 months ago #59518

Thank you nicolas

I am trying to modify the plug in but I have some problem because unfortunately I am not an expert of PHP

I found the code you indicated

$timestamp = time();
if(!$old){
//New sub
//$date = date('Y-m-d H:i:s', $timestamp);
//$publish_up = $date;
//$publish_down = date("Y-m-d H:i:s", $timestamp+(86400*$level_duration*$result->order_product_quantity));

$publish_up = date(DATE_ATOM, mktime(0, 0, 0, date('m',$timestamp), 20, date('y',$timestamp)));
$publish_down = date("Y-m-d H:i:s", $publish_up+(86400*$level_duration*$result->order_product_quantity));

if (date('d',$timestamp)>= 6) {
$publish_up = strtotime("+1 month", $publish_up);
$publish_down = strtotime("+1 month", $publish_down);
}
}
else{
//add sub after the old sub
$publish_up = $old->publish_down;
$publish_down = hikashop_getTime($old->publish_down);
$publish_down = date("Y-m-d H:i:s", $publish_down+(86400*$level_duration*$result->order_product_quantity));

}

Unfortunately it doesn't work fine.

I would like to set the $publish_up to start the 20th of the month at the time 00:00 and the $publish_down equal to $publish_up plus the duration.
If the day is equal or greater than 6, I would like to add a month to both the variables ($publish_up and $publish_down).

I have also modifyed this code

//$query = 'SELECT * FROM '.hikashop_table('akeebasubs_subscriptions',false).'
//WHERE state = '.$db->quote('C').'
//AND user_id = '.(int)$user_id.' AND enabled = 1 AND akeebasubs_level_id = '.(int)$level_id.' ORDER BY akeebasubs_subscription_id DESC';
$query = 'SELECT * FROM '.hikashop_table('akeebasubs_subscriptions',false).'
WHERE state = '.$db->quote('C').'
AND user_id = '.(int)$user_id.' AND enabled = 1 ORDER BY akeebasubs_subscription_id DESC';

Because I would like to contiue with the prevoius date also if the subscription level is different.
Is it correct?

Could you help to find the errors.

Thank you!

Last edit: 12 years 3 months ago by Teto.

Please Log in or Create an account to join the conversation.

  • Posts: 184
  • Thank you received: 4
12 years 3 months ago #59538

Probably i found the reason

I have to change there rows

$publish_up = date(DATE_ATOM, mktime(0, 0, 0, date('m',$timestamp), 20, date('y',$timestamp)));
$publish_down = date("Y-m-d H:i:s", $publish_up+(86400*$level_duration*$result->order_product_quantity));

With

$publish_up = mktime(0, 0, 0, date('m',$timestamp), 20, date('y',$timestamp));

$publish_down = strtotime("+".$level_duration*$result->order_product_quantity." day", $publish_up);
Or
$publish_down = mktime(0, 0, 0, date('m',$timestamp), 20+($level_duration*$result->order_product_quantit),date('y',$timestamp));

Is it correct? I cannot test it until tomorrow.

Last edit: 12 years 3 months ago by Teto.

Please Log in or Create an account to join the conversation.

  • Posts: 82863
  • Thank you received: 13372
  • MODERATOR
12 years 3 months ago #59580

I don't know.
I can guide but if you want us to develop and test a modified version of the plugin for you, I'm afraid that we would have to charge you for that. I already gave a solution I think could work. That's already a great pointer if you know a bit of PHP.

Please Log in or Create an account to join the conversation.

  • Posts: 184
  • Thank you received: 4
12 years 3 months ago #59628

Dear Nicolas

you are right, I have to learn at least a bit of PHP (and CSS).
After many many tests I finally found the solution to obtain what I need

$month = date('m',$timestamp);
$year = date('Y',$timestamp);
$publish_up = $year.'-'.$month.'-20 00:00:00';

// controllo se il giorno è maggiore o uguale a 6 allora l'abbonamento parte il mese successivo
if (date('d',$timestamp)>= '06') {
$date_apg = strtotime('+1 month', strtotime($publish_up));
$month = date('m',$date_apg);
$year = date('Y',$date_apg);
$publish_up = $year.'-'.$month.'-20 00:00:00';
}

// aggiongo i giorni alla data di fine abbonamento
$date_apg = strtotime('+'.$level_duration*$result->order_product_quantity.' day', strtotime($publish_up));
$day = date('d',$date_apg);
$month = date('m',$date_apg);
$year = date('Y',$date_apg);
$publish_down = $year.'-'.$month.'-'.$day.' 00:00:00';

Probably it is not the most elegant way to do that, but considering I am not an expert of PHP I am really sodisfied about it.
If someone have some suggestion, please you are more than welcome!.

I hope this Topic can help someone else in the future.

Last edit: 12 years 3 months ago by Teto.

Please Log in or Create an account to join the conversation.

  • Posts: 82863
  • Thank you received: 13372
  • MODERATOR
12 years 3 months ago #59683

Great !

Thank you for sharing back your modifications. It'll probably help someone else in the future.

Last edit: 12 years 3 months ago by nicolas.

Please Log in or Create an account to join the conversation.

Time to create page: 0.059 seconds
Powered by Kunena Forum