You are here

function uc_recurring_get_fees in UC Recurring Payments and Subscriptions 7.2

Same name and namespace in other branches
  1. 6.2 uc_recurring.module \uc_recurring_get_fees()

Get an array of recurring fees associated with any product on an order.

Parameters

$order: The order object in question.

$reset: TRUE if the fees cache should be reset.

Return value

An array of recurring fee objects containing all their data from the DB.

8 calls to uc_recurring_get_fees()
ucRecurringAPITestCase::testRecurringAdminFunctions in ./uc_recurring.test
Test administrator functions.
ucRecurringTestCase::getSingleRecurringFeeFromOrder in ./uc_recurring.test
Get a single recurring fee from the order ID.
uc_recurring_admin in ./uc_recurring.admin.inc
Displays a table for the administration of recurring fees.
uc_recurring_hosted_paypal_ipn in modules/uc_recurring_hosted/uc_recurring_hosted.paypal_ipn.inc
Handle IPN callbacks for PayPal recurring payments
uc_recurring_order_information in ./uc_recurring.admin.inc
Display recurring information about this order.

... See full list

File

./uc_recurring.module, line 850
Allows you to add a recurring fee to a product/SKU to handle subscription type services.

Code

function uc_recurring_get_fees($order, $reset = FALSE) {
  static $fees = array();

  // New orders will not have any recurring fees to get so get out now.
  if (empty($order->order_id)) {
    return array();
  }
  if ($reset || empty($fees[$order->order_id])) {
    if (!empty($order->products)) {
      $products = array();
      foreach ($order->products as $value) {
        if (isset($value->order_product_id)) {
          $products[$value->order_product_id] = $value->order_product_id;
        }
      }

      // Because of the way this works if we don't have any products we need to
      // make sure no fees show up in the results. We can't send an empty array.
      if (empty($products)) {
        $products[] = -1;
      }
      $query = db_select('uc_recurring_users', 'ru');
      $query
        ->leftjoin('users', 'u', 'u.uid = ru.uid');
      $result = $query
        ->fields('ru')
        ->fields('u', array(
        'name',
      ))
        ->condition('ru.order_product_id', $products, 'IN')
        ->execute();
      foreach ($result as $fee) {
        $fee->data = unserialize($fee->data);
        $fees[$order->order_id][] = $fee;
      }
    }
  }
  return !empty($fees[$order->order_id]) ? $fees[$order->order_id] : array();
}