You are here

function commerce_pricelist_file_download in Commerce Pricelist 8.2

Implements hook_file_download().

File

./commerce_pricelist.module, line 123
Allows defining prices for specific stores, customers, quantities.

Code

function commerce_pricelist_file_download($uri) {

  // Check if the file being downloaded is a price list CSV export.
  $scheme = StreamWrapperManager::getScheme($uri);
  $target = StreamWrapperManager::getTarget($uri);
  if ($scheme == 'temporary' && strpos($target, 'pricelist-') === 0) {
    $current_user = \Drupal::currentUser();
    if (!$current_user
      ->hasPermission('administer commerce_pricelist')) {
      return -1;
    }
    return [
      'Content-disposition' => 'attachment; filename="' . $target . '"',
      'Content-type' => 'text/csv;charset=utf-8',
    ];
  }
}