Db select product id, variation id by sku in Commerce 2, Drupal 8

Public

</> CopyGet raw version
php
  1. $query = \Drupal::database()->select('commerce_product_variation_field_data', 'pv');
  2. $query->addField('pv', 'variation_id');
  3. $query->addField('pv', 'product_id');
  4. $query->condition('pv.sku', $inv_id);
  5. $result = $query->execute()->fetchAll();
  6.  
  7. foreach ($result AS $row) {
  8. dpm($row->product_id);
  9. dpm($row->variation_id);
  10. }