You are here

public function Reports::product_get_skus in Ubercart 8.4

Gets the SKUs on a product, including adjustments and past orders.

Parameters

$nid: The product's node ID.

Return value

A unique sorted array of all skus.

2 calls to Reports::product_get_skus()
Reports::customProducts in uc_report/src/Controller/Reports.php
Displays the custom product report.
Reports::products in uc_report/src/Controller/Reports.php
Displays the product reports.

File

uc_report/src/Controller/Reports.php, line 342

Class

Reports
Provides reports for Ubercart.

Namespace

Drupal\uc_report\Controller

Code

public function product_get_skus($nid) {

  // Product SKU.
  $models = [
    $this->database
      ->query("SELECT model FROM {uc_products} WHERE nid = :nid", [
      ':nid' => $nid,
    ])
      ->fetchField(),
  ];

  // Adjustment SKUs.
  $models = array_merge($models, $this->database
    ->query("SELECT model FROM {uc_product_adjustments} WHERE nid = :nid", [
    ':nid' => $nid,
  ])
    ->fetchCol());

  // SKUs from orders.
  $models = array_merge($models, $this->database
    ->query("SELECT DISTINCT model FROM {uc_order_products} WHERE nid = :nid", [
    ':nid' => $nid,
  ])
    ->fetchCol());

  // Unique, sorted.
  $models = array_unique($models);
  asort($models);
  return $models;
}