You are here

function uc_file_uc_order_product_can_ship in Ubercart 8.4

Same name and namespace in other branches
  1. 7.3 uc_file/uc_file.module \uc_file_uc_order_product_can_ship()

Implements hook_uc_order_product_can_ship().

File

uc_file/uc_file.module, line 168
Allows products to be associated with downloadable files.

Code

function uc_file_uc_order_product_can_ship($product) {

  // Check if this model is shippable as well as a file.
  $connection = \Drupal::database();
  $files = $connection
    ->query('SELECT shippable, model FROM {uc_file_products} fp INNER JOIN {uc_product_features} pf ON pf.pfid = fp.pfid WHERE nid = :nid', [
    ':nid' => $product->nid->target_id,
  ]);
  foreach ($files as $file) {

    // If the model is 'any' then return.
    if (empty($file->model)) {
      return $file->shippable;
    }
    else {

      // Use the adjusted SKU, or node SKU if there's none.
      $sku = empty($product->data['model']) ? $product->model->value : $product->data['model'];
      if ($sku == $file->model) {
        return $file->shippable;
      }
    }
  }
}