You are here

function UcOrderController::attachLoad in Ubercart 7.3

Attaches data to entities upon loading.

This will attach fields, if the entity is fieldable. It calls hook_entity_load() for modules which need to add data to all entities. It also calls hook_TYPE_load() on the loaded entities. For example hook_node_load() or hook_user_load(). If your hook_TYPE_load() expects special parameters apart from the queried entities, you can set $this->hookLoadArguments prior to calling the method. See NodeController::attachLoad() for an example.

Parameters

$queried_entities: Associative array of query results, keyed on the entity ID.

$revision_id: ID of the revision that was loaded, or FALSE if the most current revision was loaded.

Overrides DrupalDefaultEntityController::attachLoad

File

uc_order/uc_order.controller.inc, line 13
Contains controller classes for uc_order and uc_order_product entities.

Class

UcOrderController
Controller class for uc_order entity.

Code

function attachLoad(&$orders, $revision_id = FALSE) {
  foreach ($orders as &$order) {
    $order->data = unserialize($order->data);
    $efq = new EntityFieldQuery();
    $result = $efq
      ->entityCondition('entity_type', 'uc_order_product')
      ->propertyCondition('order_id', $order->order_id)
      ->propertyOrderBy('order_product_id', 'ASC')
      ->execute();
    if (!empty($result['uc_order_product'])) {
      $order->products = uc_order_product_load_multiple(array_keys($result['uc_order_product']), TRUE);
      foreach ($order->products as $product) {
        $product->order = $order;
        $product->order_uid = $order->uid;
      }
    }
    else {
      $order->products = array();
    }
    uc_order_module_invoke('load', $order, NULL);

    // Load line items... has to be last after everything has been loaded.
    $order->line_items = uc_order_load_line_items($order);
    $fields = array();

    // Make sure the total still matches up...
    if (($total = uc_order_get_total($order)) !== $order->order_total) {
      $fields['order_total'] = $total;
      $order->order_total = $total;
    }
    if (($count = uc_order_get_product_count($order)) !== $order->product_count) {
      $fields['product_count'] = $count;
      $order->product_count = $count;
    }
    if (count($fields)) {
      $query = db_update('uc_orders')
        ->fields($fields)
        ->condition('order_id', $order->order_id)
        ->execute();
    }
  }
  parent::attachLoad($orders, $revision_id);
}