public static function Shipment::load in Ubercart 8.4
Loads a shipment and its packages.
Parameters
int $shipment_id: The shipment ID.
Return value
\Drupal\uc_fulfillment\Shipment|null The Shipment object, or NULL if there isn't one.
5 calls to Shipment::load()
- PackageCancelForm::submitForm in shipping/
uc_fulfillment/ src/ Form/ PackageCancelForm.php - Form submission handler.
- PackageController::listOrderPackages in shipping/
uc_fulfillment/ src/ Controller/ PackageController.php - Displays a list of an order's packaged products.
- Shipment::loadByOrder in shipping/
uc_fulfillment/ src/ Shipment.php - Loads a shipment and its packages for a given order.
- ShipmentController::viewPackage in shipping/
uc_fulfillment/ src/ Controller/ ShipmentController.php - Displays the details of a package.
- ShipmentConverter::convert in shipping/
uc_fulfillment/ src/ ParamConverter/ ShipmentConverter.php - Converts path variables to their corresponding objects.
File
- shipping/
uc_fulfillment/ src/ Shipment.php, line 394
Class
- Shipment
- Defines the Shipment class.
Namespace
Drupal\uc_fulfillmentCode
public static function load($shipment_id) {
$shipment = NULL;
$result = \Drupal::database()
->query('SELECT * FROM {uc_shipments} WHERE sid = :sid', [
':sid' => $shipment_id,
]);
if ($assoc = $result
->fetchAssoc()) {
$shipment = Shipment::create();
$origin_fields = [];
$destination_fields = [];
foreach ($assoc as $key => $value) {
$subkey = substr($key, 0, 2);
if ($subkey == 'o_') {
$origin_fields[substr($key, 2)] = $value;
}
elseif ($subkey == 'd_') {
$destination_fields[substr($key, 2)] = $value;
}
else {
$shipment->{$key} = $value;
}
}
// Reconstitute Address objects from individual fields.
$shipment
->setOrigin(Address::create($origin_fields));
$shipment
->setDestination(Address::create($destination_fields));
$result2 = \Drupal::database()
->query('SELECT package_id FROM {uc_packages} WHERE sid = :sid', [
':sid' => $shipment_id,
]);
$packages = [];
foreach ($result2 as $package) {
$packages[$package->package_id] = Package::load($package->package_id);
}
$shipment
->setPackages($packages);
$extra = \Drupal::moduleHandler()
->invokeAll('uc_shipment', [
'load',
$shipment,
]);
if (is_array($extra)) {
foreach ($extra as $key => $value) {
$shipment->{$key} = $value;
}
}
}
return $shipment;
}