I want to add a simple product to a grouped product. I tried a lot of different approaches, including direct database modifications, all without success. I'm guessing it should be something like this.
$objectManager = \Magento\Framework\App\ObjectManager::getInstance(); $product = $objectManager->create('Magento\Catalog\Model\Product')->load($groupedID); // Load Configurable Product $associatedProductIds = array($simpleID); //Product Ids Of Associated Products $product->setAssociatedProductIds($associatedProductIds);// Setting Associated Products $product->save();
the above gives no error. but also does not create a link.