public static function Package::load in Ubercart 8.4
Loads a package and its products.
Parameters
int $package_id: The package ID.
Return value
\Drupal\uc_fulfillment\Package|null The Package object, or NULL if there isn't one with the given ID.
5 calls to Package::load()
- Manual::fulfillOrder in shipping/
uc_fulfillment/ src/ Plugin/ Ubercart/ FulfillmentMethod/ Manual.php - Fulfills the order using this method.
- Package::loadByOrder in shipping/
uc_fulfillment/ src/ Package.php - Loads packages for a given order.
- PackageConverter::convert in shipping/
uc_fulfillment/ src/ ParamConverter/ PackageConverter.php - Converts path variables to their corresponding objects.
- Shipment::load in shipping/
uc_fulfillment/ src/ Shipment.php - Loads a shipment and its packages.
- ShipmentEditForm::submitForm in shipping/
uc_fulfillment/ src/ Form/ ShipmentEditForm.php - Form submission handler.
File
- shipping/
uc_fulfillment/ src/ Package.php, line 480
Class
- Package
- Defines the Package class.
Namespace
Drupal\uc_fulfillmentCode
public static function load($package_id) {
if (!isset(self::$packages[$package_id])) {
$result = \Drupal::database()
->query('SELECT * FROM {uc_packages} WHERE package_id = :id', [
':id' => $package_id,
]);
if ($assoc = $result
->fetchAssoc()) {
$package = Package::create($assoc);
$products = [];
$description = [];
$addresses = [];
$result = \Drupal::database()
->query('SELECT op.order_product_id, pp.qty, op.weight__value AS weight, op.weight__units as weight_units, op.nid, op.title, op.model, op.price, op.data FROM {uc_packaged_products} pp LEFT JOIN {uc_order_products} op ON op.order_product_id = pp.order_product_id WHERE pp.package_id = :id ORDER BY op.order_product_id', [
':id' => $package->package_id,
]);
foreach ($result as $product) {
$address = uc_quote_get_default_shipping_address($product->nid);
if (!in_array($address, $addresses)) {
$addresses[] = $address;
}
$description[] = $product->qty . ' x ' . $product->model;
$product->data = unserialize($product->data);
$products[$product->order_product_id] = $product;
}
$package->addresses = $addresses;
$package->description = implode(', ', $description);
$package->products = $products;
if ($package->label_image && ($image = file_load($package->label_image))) {
$package->label_image = $image;
}
self::$packages[$package_id] = $package;
return $package;
}
else {
return NULL;
}
}
// Return package from cache.
return self::$packages[$package_id];
}