How to Create and Retrive a product programmatically in Drupal commerce 2.x
To create a product is similar to how you'd create a node:     

use Drupal\commerce_product\Entity\ProductVariation;
use Drupal\commerce_product\Entity\Product;
use Drupal\commerce_price\Price;

$variation1 = ProductVariation::create([
  'type' =&gt; 'default',
   'sku' =&gt; '123',
   'price' =&gt; new Price('14.50', 'USD'),
]);
$variation1-&gt;save();

$variation2 = ProductVariation::create([
  'type' =&gt; 'default',
   'sku' =&gt; '1234',
   'price' =&gt; new Price('10.00', 'USD'),
]);
$variation2-&gt;save();

$product = Product::create([
   'type' =&gt; 'default',
   'title' =&gt; t('Product Title'),
    'variations' =&gt; [$variation1, $variation2],
]);
$product-&gt;save();