You are here

function uc_quote_node_load in Ubercart 7.3

Same name and namespace in other branches
  1. 8.4 shipping/uc_quote/uc_quote.module \uc_quote_node_load()

Implements hook_node_load().

File

shipping/uc_quote/uc_quote.module, line 124
The controller module for fulfillment modules that process physical goods.

Code

function uc_quote_node_load($nodes, $types) {
  $product_types = array_intersect(uc_product_types(), $types);
  if (empty($product_types)) {
    return;
  }
  $shipping_type = variable_get('uc_store_shipping_type', 'small_package');
  $shipping_types = db_query("SELECT id, shipping_type FROM {uc_quote_shipping_types} WHERE id_type = :type AND id IN (:ids)", array(
    ':type' => 'product',
    ':ids' => array_keys($nodes),
  ))
    ->fetchAllKeyed();
  $addresses = db_query("SELECT nid, first_name, last_name, company, street1, street2, city, zone, postal_code, country, phone FROM {uc_quote_product_locations} WHERE nid IN (:nids)", array(
    ':nids' => array_keys($nodes),
  ), array(
    'fetch' => 'UcAddress',
  ))
    ->fetchAllAssoc('nid');
  foreach ($nodes as $nid => &$node) {
    if (!in_array($node->type, $product_types)) {
      continue;
    }
    if (isset($shipping_types[$nid])) {
      $node->shipping_type = $shipping_types[$nid];
    }
    else {
      $node->shipping_type = $shipping_type;
    }
    if (isset($addresses[$nid])) {
      $node->shipping_address = (array) $addresses[$nid];
      unset($node->shipping_address['nid']);
    }
    else {
      $node->shipping_address = (array) variable_get('uc_quote_store_default_address', new UcAddress());
    }
  }
}