Magento 2 : Programmatically creating Magento product

In a development process, you need some testing data you can use. Magento supplies you with it’s default Sample Data that contains products. $objectManager = \Magento\Framework\App\ObjectManager::getInstance(); // instance of object manager $product = $objectManager->create(‘\Magento\Catalog\Model\Product’); $product->setSku(‘mysku’); // Set your sku here $product->setName(‘Sample Product’); // Name of Product $product->setAttributeSetId(4); // Attribute set id $product->setStatus(1); // Status on […]

Magento 2: Add category programmatically

In this article, I am going to show, how to create multiple categories programmatically. It is useful to import number of categories data from API, CSV and XML file. Here is a code: use \Magento\Framework\App\Bootstrap; include(‘../app/bootstrap.php’); $bootstrap = Bootstrap::create(BP, $_SERVER); $objectManager = $bootstrap->getObjectManager(); $url = \Magento\Framework\App\ObjectManager::getInstance(); $storeManager = $url->get(‘\Magento\Store\Model\StoreManagerInterface’); $mediaurl= $storeManager->getStore()->getBaseUrl(\Magento\Framework\UrlInterface::URL_TYPE_MEDIA); $state = $objectManager->get(‘\Magento\Framework\App\State’);   // if […]