function uc_recurring_create_renewal_order in UC Recurring Payments and Subscriptions 7.2
Same name and namespace in other branches
- 6.2 uc_recurring.module \uc_recurring_create_renewal_order()
Create a new order to be renewed via a recurring profile.
2 calls to uc_recurring_create_renewal_order()
- uc_recurring_charge_profile in ./
uc_recurring.module - Process a charge on a recurring profile.
- uc_recurring_renew in ./
uc_recurring.module - Process a renewal, either from the cron job or manually from a fee handler.
File
- ./
uc_recurring.module, line 450 - Allows you to add a recurring fee to a product/SKU to handle subscription type services.
Code
function uc_recurring_create_renewal_order($fee) {
global $user;
// Clear CC cache so that correct info is loaded (if any)
if (module_exists('uc_credit')) {
uc_credit_cache('clear');
}
$order = uc_order_load($fee->order_id);
$old_id = $order->order_id;
// Create a new order by cloning the current order and replacing order ID.
$new_order = uc_order_new($order->uid, 'post_checkout');
$new_id = $new_order->order_id;
// Add a comment in the new and original order history.
uc_order_comment_save($old_id, $user->uid, t('New recurring fee processed, new order is <a href="@store-orders">@order_id</a>.', array(
'@store-orders' => url('admin/store/orders/' . $new_id),
'@order_id' => $new_id,
)));
uc_order_comment_save($new_id, $user->uid, t('Order created as a recurring fee for order <a href="@store-orders">@order_id</a>.', array(
'@store-orders' => url('admin/store/orders/' . $old_id),
'@order_id' => $old_id,
)));
$new_order = $order;
$new_order->order_id = $new_id;
$new_order->created = time();
$new_order->order_status = 'processing';
// @todo we need a better way of tracking the relationship between orders.
$new_order->data['recurring_fee'] = TRUE;
$new_order->data['old_order_id'] = $old_id;
$new_order->products = array();
// We want the line items to be regenerated.
unset($new_order->line_items);
// Give other modules a chance to modify the new order before processing
uc_recurring_renewal_module_invoke('recurring_renewal_pending', $new_order, $fee);
$new_order->line_items = uc_order_load_line_items($new_order, TRUE);
uc_order_save($new_order);
uc_order_update_status($new_id, 'pending');
// We load the order to pick up the 'pending' state.
$new_order = uc_order_load($new_id);
return $new_order;
}