I'm trying to programmatically create a bundled product using the following link as a reference: https://github.com/magento/magento2/blob/develop/dev/tests/api-functional/testsuite/Magento/Bundle/Api/ProductServiceTest.php
I'm adding the bundle product first, without any options, then loading it out of the database in order to add the linked products.
Here's an example of the array I'm using:
Array (  => Array ( [title] => Test option [required] => 1 [type] => radio [position] => 0 [product_links] => Array (  => Array ( [sku] => test-simple [qty] => 1 [position] => 0 [is_default] => [price] => 0 [price_type] => 1 [can_change_quantity] => 0 ) ) ) )
And here's my code to add the relation:
$bundleProduct = $this->objectManager->get('Magento\Catalog\Model\Product')->load($productID); $bundleProduct->getExtensionAttributes()->setBundleProductOptions($bundleOptions); $bundleProduct->save();
However, this does not add any linked product to the bundle product. Doesn't anyone have an idea what I'm missing? As the documentation for Magento2 is very limited at the moment.