0

How to update product using the custom file from Magento root.?

https://www.domain.com/update.php

1

For update product using the custom file from Magento root, first of all, you need to create update.php a file at your Magento root.

And then paste following code into your file and then run `https://www.domain.com/update.php

<?php

use Magento\Framework\App\Bootstrap;

include 'app/bootstrap.php';

$bootstrap = Bootstrap::create(BP, $_SERVER);
$objectManager = $bootstrap->getObjectManager();

$state = $objectManager->get('Magento\Framework\App\State');
$state->setAreaCode('frontend');

$productId = 1;
$product = $objectManager->create('Magento\Catalog\Model\Product');
$product->load($productId);
$product->setName('Enter Your Product Name Here');
$product->save();

On above example, we have just update product name.

After running this script if you cache is enabled then you need to refresh your cache using the following command.

php bin/magento cache:clean

Hope that'll help you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.