How Can I Update Magento 2 Product Programmatically

I would like to update Magento 2 product’s detail by sku. What method and steps should I use

You will need to load Magento 2 product by sku first and then use set method to update the Magento 2 product’s info

$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$product_id = 1;
$productFactory = $objectManager->get('\Magento\Catalog\Model\ProductFactory');
$product = $productFactory->create()->load($product_id);
$product->setPrice("1.00");
$product->setName("Test");
$product->setSku("test");
$product->setWebsiteIds(1);
$product->setTypeId(\Magento\Catalog\Model\Product\Type::TYPE_SIMPLE);
$product->save();

0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments