Programmatically create a product using Craft Commerce 2?
You probably have it figured by now, but for anyone wondering, here's a complete working example.

use craft\commerce\elements\Product;
use craft\commerce\elements\Variant;

// Create product
$product = new Product();
$product-&gt;title = 'Hello world';
$product-&gt;typeId = 2;
$product-&gt;enabled = true;

// Create variant
$variant = new Variant();
$variant-&gt;title = 'hey';
$variant-&gt;sku = 'hey';
$variant-&gt;price = 123;
$variant-&gt;stock = 5;

// Save product with variant
$product-&gt;setVariants([$variant]);
Craft::$app-&gt;elements-&gt;saveElement($product);