In this blog post, you will know about how to add Custom Script in Magento Root Directory. For example, if you want to get the product details and print them, you need to create a file cusom_script.php at the root of the Magento and add the code given below.
Here we know about how to get sku, name, price and qunatiy of a specific product id using a custom php script in magento root directory.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
<?php ini_set('display_errors', 1); ini_set('display_startup_errors', 1); ini_set('memory_limit', '5G'); error_reporting(E_ALL); use Magento\Framework\App\Bootstrap; require 'app/bootstrap.php'; $bootstrap = Bootstrap::create(BP, $_SERVER); $objectManager = $bootstrap->getObjectManager(); $state = $objectManager->get('Magento\Framework\App\State'); $state->setAreaCode('frontend'); $id = 5; $product = $objectManager->create('\Magento\Catalog\Model\Product')->load($id); echo $product->getSku();echo "</br>"; echo $product->getName();echo "</br>"; echo $product->getQty();echo "</br>"; echo $product->getPrice();echo "</br>"; |
We hope this blog is very helpful for you.
Thank You! 😉
People Also Searched For:
How to Add Multiple Products to Cart programmatically In Magento 2