You are here

function uc_shipping_package_load in Ubercart 5

Same name and namespace in other branches
  1. 6.2 shipping/uc_shipping/uc_shipping.module \uc_shipping_package_load()
  2. 7.3 shipping/uc_shipping/uc_shipping.module \uc_shipping_package_load()

Load a package and its products.

9 calls to uc_shipping_package_load()
uc_shipping_make_shipment in shipping/uc_shipping/uc_shipping.module
Default method to send packages on a shipment.
uc_shipping_package_cancel_confirm_submit in shipping/uc_shipping/uc_shipping.module
uc_shipping_package_edit in shipping/uc_shipping/uc_shipping.module
Rearrange the products in or out of a package.
uc_shipping_package_edit_submit in shipping/uc_shipping/uc_shipping.module
Submit handler for uc_shipping_package_edit().
uc_shipping_package_view in shipping/uc_shipping/uc_shipping.module
Display the details of a package.

... See full list

File

shipping/uc_shipping/uc_shipping.module, line 1137
Organizes ordered products into packages and sets them up for shipment. Shipping method modules may add functionality to generate shipping labels and tracking numbers.

Code

function uc_shipping_package_load($package_id) {
  static $packages = array();
  if (!isset($packages[$package_id])) {
    $products = array();
    $descripion = '';
    $weight = 0;
    $units = variable_get('uc_weight_unit', 'lb');
    $addresses = array();
    $result = db_query("SELECT op.order_product_id, pp.qty, pp.qty * op.weight AS weight, p.weight_units, op.nid, op.title, op.model, op.price FROM {uc_packaged_products} AS pp LEFT JOIN {uc_order_products} AS op ON op.order_product_id = pp.order_product_id LEFT JOIN {uc_products} AS p ON op.nid = p.nid WHERE pp.package_id = %d", $package_id);
    while ($product = db_fetch_object($result)) {
      $address = uc_quote_get_default_shipping_address($product->nid);

      // TODO: Lodge complaint that array_unique() compares as strings.
      if (!in_array($address, $addresses)) {
        $addresses[] = $address;
      }
      $description .= ', ' . $product->qty . ' x ' . $product->model;

      // Normalize all weights to default units.
      $weight += $product->weight * uc_weight_conversion($product->weight_units, $units);
      $products[$product->order_product_id] = $product;
    }
    $result = db_query("SELECT * FROM {uc_packages} WHERE package_id = %d", $package_id);
    $packages[$package_id] = db_fetch_object($result);
    $packages[$package_id]->addresses = $addresses;
    $packages[$package_id]->description = substr($description, 2);
    $packages[$package_id]->weight = $weight;
    $packages[$package_id]->weight_units = $units;
    $packages[$package_id]->products = $products;
  }
  return $packages[$package_id];
}