where i put file of programatically create product

use Magento\Framework\App\Bootstrap;
$bootstrap = Bootstrap::create(BP, $_SERVER);

$objectManager = $bootstrap->getObjectManager();

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

$_product = $objectManager->create('Magento\Catalog\Model\Product');
$_product->setName('Test Product');
        'use_config_manage_stock' => 0, //'Use config settings' checkbox
        'manage_stock' => 1, //manage stock
        'min_sale_qty' => 1, //Minimum Qty Allowed in Shopping Cart
        'max_sale_qty' => 2, //Maximum Qty Allowed in Shopping Cart
        'is_in_stock' => 1, //Stock Availability
        'qty' => 100 //qty


2 Answers 2


programmatically create product file put in Magento root directory and run

example in localhost go to var/www/html/magentosmpl233/ and put your file and run


Method - 1: Put your file in a Magento root directory and run your url in browser.

Example: www.yourdomain.com/your_file_name.php


Method - 2: Create your custom directory on root and keep your custom file in that directory and run url with your custom directory path in browser.

Example: www.yourdomain.com/your_directorty_name/your_file_name.php

  • Note: Make sure your directory and file have proper permissions and ownership. Jan 29, 2020 at 9:58

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.