Skip to content

Update price progrmmatically

I’m trying to update the price for configurable product programmatically. But the price is not updating.

Also I’m getting integrity constrain error when the sku is not assigned.

if($proType == 'configurable')
                {
                    $conf_product = $this->productRepository->get($sku);
                    //echo  $conf_product->getId(); exit;
                    $conf_product = $this->_objectManager->create('MagentoCatalogModelProduct');
                    //$conf_product->setSku($sku);
                    $conf_product->setPrice($mapPrice); 
                    $conf_product->setStockData($is_in_stock);
                    try {
                        $conf_product->save();
                        $childIds = $this->updateConfigProduct($sku, $stock);
                        $logger->info('Stock updated for Config - Simple product:'.$sku);
                    } catch (Exception $ex) {
                        $logger->info('Stock update failed for:'.$sku.'-'. $ex->getMessage());
                        //continue;
                    }
                    
                }