0

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();
?>
1

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
| improve this answer | |
0

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

| improve this answer | |
  • Note: Make sure your directory and file have proper permissions and ownership. – MagentoUser Jan 29 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.