I'd like to create a file in the root folder (e.g. test.php) that I'll be able to do functions programmatically like update product attributes or something like that.
Can you show me some sample?
Thanks
I'd like to create a file in the root folder (e.g. test.php) that I'll be able to do functions programmatically like update product attributes or something like that.
Can you show me some sample?
Thanks
You can use something like that like a sample:
<?php
use Magento\Framework\App\Bootstrap;
require __DIR__ . '/app/bootstrap.php';
$params = $_SERVER;
$bootstrap = Bootstrap::create(BP, $params);
$obj = $bootstrap->getObjectManager();
$state = $obj->get('Magento\Framework\App\State');
$state->setAreaCode('frontend');
$productCollection = $obj->create('Magento\Catalog\Model\ResourceModel\Product\CollectionFactory');
$collection = $productCollection->create()
->addAttributeToSelect('*')
->load();
foreach ($collection as $product){
echo 'SKU: '.$product->getSku().'<br>';
echo 'Name: '.$product->getName().'<br>';
echo 'Price: '.$product->getPrice().'<br>';
echo 'Special price: '.$product->getSpecialPrice().'<br>';
echo '----------------------------<br>';
}