You are here

function uc_recurring_product_get_recurring_products_in_order in UC Recurring Payments and Subscriptions 7.2

Same name and namespace in other branches
  1. 6.2 modules/uc_recurring_product/uc_recurring_product.module \uc_recurring_product_get_recurring_products_in_order()

Get an array of recurring products that should be created for an order.

Unlike uc_recurring_get_fees(), this functions checks for products in an order that might not be submitted, thus a recurring fee record hasn't been created yet.

Parameters

$order: The order object.

Return value

An array with the products and their product fee objects.

7 calls to uc_recurring_product_get_recurring_products_in_order()
uc_recurring_hosted_form_uc_paypal_wps_form_alter in modules/uc_recurring_hosted/uc_recurring_hosted.module
Paypal website payments standard process
uc_recurring_order_checkout_pane_message in modules/uc_recurring_product/uc_recurring_product.module
Checkout Pane callback function.
uc_recurring_order_pane_checkout in modules/uc_recurring_order/uc_recurring_order.module
Checkout Pane callback function.
uc_recurring_product_form_uc_cart_checkout_form_alter in modules/uc_recurring_product/uc_recurring_product.module
Implements hook_form_FORM-ID_alter().
uc_recurring_product_form_uc_order_view_update_form_alter in modules/uc_recurring_product/uc_recurring_product.module
Implements hook_form_FORM-ID_alter().

... See full list

File

modules/uc_recurring_product/uc_recurring_product.module, line 600
Add recurring payments/fees to a product. This is imlpemented through Ubercarts product features.

Code

function uc_recurring_product_get_recurring_products_in_order($order) {
  $return = array();
  $products = array();

  // The product node IDs that might be reccuring products.
  $nids = array();
  if (!empty($order->products)) {
    $fees = uc_recurring_get_fees($order);
    foreach ($order->products as $value) {
      $processed = FALSE;
      foreach ($fees as $fee) {
        if ($fee->order_product_id == $value->order_product_id) {
          $processed = TRUE;
        }
      }
      if ($processed) {
        continue;
      }

      // Don't process new orders that were created by uc_recurring_renew().
      if (empty($value->data['recurring_fee'])) {

        // Get all the models of all products.
        $products[$value->nid][] = array(
          'model' => $value->model,
          'product' => $value,
        );
        $nids[] = $value->nid;
      }
    }
    if ($products) {

      // Get recurring products according to the products node IDs in the order.
      $query = db_select('uc_recurring_product', 'p');
      $query
        ->leftjoin('uc_product_features', 'f', 'p.pfid = f.pfid');
      $result = $query
        ->fields('p', array(
        'pfid',
        'model',
        'fee_amount',
        'initial_charge',
        'regular_interval',
        'number_intervals',
      ))
        ->fields('f', array(
        'nid',
      ))
        ->condition('f.nid', $nids, 'IN')
        ->execute();
      foreach ($result as $row) {
        foreach ($products[$row->nid] as $key => $product) {

          // No model name indicates we should work for all models.
          // However, we still need to have the sku of the recurring product,
          // otherwise recurring orders will show products without a sku.
          if ($row->model == '') {
            $row->model = $product['model'];
          }
          if ($row->model == $product['model']) {
            $return[] = $product + array(
              'recurring product' => $row,
            );
          }
        }
      }
    }
  }
  return $return;
}