You are here

function uc_usps_node_load in Ubercart 7.3

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

Implements hook_node_load().

File

shipping/uc_usps/uc_usps.module, line 109
United States Postal Service (USPS) shipping quote module.

Code

function uc_usps_node_load($nodes, $types) {
  $product_types = array_intersect(uc_product_types(), $types);
  if (empty($product_types)) {
    return;
  }
  $vids = array();
  $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();
  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 ($node->shipping_type == 'small_package') {
      $vids[$nid] = $node->vid;
    }
  }
  if ($vids) {
    $result = db_query("SELECT * FROM {uc_usps_products} WHERE vid IN (:vids)", array(
      ':vids' => $vids,
    ), array(
      'fetch' => PDO::FETCH_ASSOC,
    ));
    foreach ($result as $usps) {
      $nodes[$usps['nid']]->usps = $usps;
    }
  }
}