function uc_fulfillment_uc_order_can_delete in Ubercart 8.4
Implements hook_uc_order_can_delete().
Prevent users from deleting orders with a shipment or package that has a tracking number, unless the user has administrative privileges or the "Unconditionally delete orders" permission.
File
- shipping/
uc_fulfillment/ uc_fulfillment.module, line 137 - Organizes ordered products into packages and sets them up for shipment.
Code
function uc_fulfillment_uc_order_can_delete(OrderInterface $order) {
// Find and check the shipments for tracking numbers.
// {uc_shipments}.tracking_number is NOT NULL.
$connection = \Drupal::database();
$shipment_count = $connection
->select('uc_shipments')
->condition('order_id', $order
->id())
->condition('tracking_number', '', '<>')
->countQuery()
->execute()
->fetchField();
if ($shipment_count > 0) {
return FALSE;
}
// Find and check the packages.
$package_count = $connection
->select('uc_packages')
->condition('order_id', $order
->id())
->isNotNull('tracking_number')
->condition('tracking_number', '', '<>')
->countQuery()
->execute()
->fetchField();
if ($package_count > 0) {
return FALSE;
}
}