Question

where i put file of programatically create product

<?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');


$_product = $objectManager->create('Magento\Catalog\Model\Product');
$_product->setName('Test Product');
$_product->setTypeId('simple');
$_product->setAttributeSetId(4);
$_product->setSku('test-SKU');
$_product->setWebsiteIds(array(1));
$_product->setVisibility(4);
$_product->setPrice(array(1));
$_product->setImage('/testimg/test.jpg');
$_product->setSmallImage('/testimg/test.jpg');
$_product->setThumbnail('/testimg/test.jpg');
$_product->setStockData(array(
        '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
        )
    );

$_product->save();
?>
Was it helpful?

Solution

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

example http://127.0.0.1/magesmpl233/createproduct.php

OTHER TIPS

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

Example: www.yourdomain.com/your_file_name.php

OR

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

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top