I want to add parent product to cart using child product id, it's configurable options in. Do like this
Get child id & using child id we can get parent product id.
Load the Configurable Attributes names of a product with it's(parent id). Then use In
$childid='15';$rep= $obj->create('Magento\Catalog\Model\ProductRepository'); $childObj=$rep->getById($childid); $aray[$att['attribute_id']]=$childObj->getData($attr->getData('attribute_code')); now we have only child product configurableoptions $params2=array();$params2['selected_configurable_option'] = $childid;$params2['super_attribute'] = $aray;$params2['qty'] = 1; $this->cart->addProduct($parentid,$params2); $this->cart->save();
Note : Added the content from the comments to clear information