I would like to see if it's possible to set up a simple custom PHP fieldset to pass an argument in order to calculate the interval. In my case the number of days until the 1st of the month since I need to make ALL recurring fees start on a specific day of the following month. (I'm also prorating the subscription order at checkout) If I can simply pass in a PHP variable into each of the existing uc_range parameters, problem for me is solved if the date function would get called when the order gets placed. Is it possible?
So altering this line in the module to read:
'#options' => drupal_map_assoc(uc_range(date('t') - date('d'), date('t') - date('d'))),
and then setting the $form['interval']['initial']['initial_charge_unit'] to just show day(s).
here is the code in the module I'm referring to. It's in the fieldset titled 'Initial charge':
$form['interval']['initial']['initial_charge_value'] = array(
'#type' => 'select',
'#options' => drupal_map_assoc(uc_range(0, 52)),
'#default_value' => $product->initial_charge_value,
);
$form['interval']['initial']['initial_charge_unit'] = array(
'#type' => 'select',
'#options' => array(
'days' => t('day(s)'),
'weeks' => t('week(s)'),
'months' => t('month(s)'),
'years' => t('year(s)'),
),
'#default_value' => $product->initial_charge_unit,
);
thanks for your help!
-wil
Comments
Comment #1
univate commentedUnless I am missunderstanding your request, what you what to do I think is all possible to achieve with hooks.
If you want to change the uc_recurring feature form this can be done via standard drupal hook_form_alter() and/or there are uc_recurring hooks to alter the recurring fee before it is actually charged - which would allow you to calculate the number of days to the initial charge.
One problem I have with adding custom PHP directly via the site in any module is you are effectively giving anyone with that permission full administrative access. Plus code should be stored in files not in your database.
Comment #2
blasthaus commentedthanks for the reply. i'll give it a whirl although i could use any pointers on which handler to consider here to make this happen before any tables get set.
Comment #3
univate commentedMost of the uc_recurring hooks are documented in uc_recurring.api.php
uc_recurring also uses drupal_alter() function to allow other modules to alter data/records as they are created.
There is one for when the recurring fee is created:
Comment #4
blasthaus commentedaha great, i didn't see this one in the api. will have a look.
i'm a bit confused however on initial_charge vs. next_charge. If i use the hook above, that sets the initial charge correct?
i see this in the uc_recurring_process_order($order, $data = array())
and then after the $fee is built, i see
drupal_alter('recurring_fee_user_create', $fee);i just want to make sure my hook would get called here first and i can alter this built $fee before it gets stored in the database.
thx again for the pointers, as you can tell i'm a bit green on how hooks work. hopefully i'll get this working and post up a solution.
-wil
Comment #5
univate commentedYou probably just need to set the next_charge field, that is the field that says when the next/first payment will be triggered. The initial_charge is really just used for setting this next_charge field for the first payment, then it reverts to the regular_intervals.
Comment #6
univate commented