Insert Indian States in Magento Database

Connect to your server’s database using mysql cli or phpmyadmin and use the following query

INSERT INTO `directory_country_region` VALUES 
(NULL,"IN","AP","Andhra Pradesh"),
(NULL,"IN","AR","Arunachal Pradesh"),
(NULL,"IN","AS","Assam"),
(NULL,"IN","BR","Bihar"),
(NULL,"IN","CG","Chhattisgarh"),
(NULL,"IN","GA","Goa"),
(NULL,"IN","GJ","Gujarat"),
(NULL,"IN","HR","Haryana"),
(NULL,"IN","HP","Himachal Pradesh"),
(NULL,"IN","JK","Jammu and Kashmir"),
(NULL,"IN","JH","Jharkhand"),
(NULL,"IN","KA","Karnataka"),
(NULL,"IN","KL","Kerala"),
(NULL,"IN","MP","Madhya Pradesh"),
(NULL,"IN","MH","Maharashtra"),
(NULL,"IN","MN","Manipur"),
(NULL,"IN","ML","Meghalaya"),
(NULL,"IN","MZ","Mizoram"),
(NULL,"IN","NL","Nagaland"),
(NULL,"IN","OD","Odisha"),
(NULL,"IN","PB","Punjab"),
(NULL,"IN","RJ","Rajasthan"),
(NULL,"IN","SK","Sikkim"),
(NULL,"IN","TN","Tamil Nadu"),
(NULL,"IN","TL","Telangana"),
(NULL,"IN","TR","Tripura"),
(NULL,"IN","UK","Uttarakhand"),
(NULL,"IN","UP","Uttar Pradesh"),
(NULL,"IN","WB","West Bengal"),
(NULL,"IN","AN","Andaman and Nicobar Islands"),
(NULL,"IN","CH","Chandigarh"),
(NULL,"IN","DH","Dadra and Nagar Haveli"),
(NULL,"IN","DD","Daman and Diu"),
(NULL,"IN","DL","Delhi"),
(NULL,"IN","LD","Lakshadweep"),
(NULL,"IN","PY","Puducherry");

How to create Magento 2 category programmatically?

Use this code:

<?php
use \Magento\Framework\App\Bootstrap;
echo 'code by harshvardhanmalpani';
include('./app/bootstrap.php');
$bootstrap = Bootstrap::create(BP, $_SERVER);
$objectManager = $bootstrap->getObjectManager();

function createCategory($a='',$b=2,$c=true,$d='',$e='',$f='',$g='') {
        global $objectManager;
        $category = $objectManager->get('\Magento\Catalog\Model\CategoryFactory')->create();
        $category->setName($a);
        $category->setParentId($b); // 1: root category.
        $category->setIsActive($c);
        $category->setCustomAttributes([
'description' => $d,
'meta_title' => $e,
'meta_keywords' => $f,
 'meta_description' => $g,
     ]);
        $objectManager->get('\Magento\Catalog\Api\CategoryRepositoryInterface')->save($category);
}
createCategory("Abc");
createCategory("Xyz",4,false,"description","m title");
?>

Magento 2.1x – Add options in custom product attribute using backend

Go to the attribute edit page using magento 2 admin panel (Stores > Attributes > Product > Edit attribute)
Use console – ctrl + shift + J
Edit the js array mimim and then paste the following code in console.

$jq=new jQuery.noConflict();
var mimim=["Black","Blue","Blue Black"];
$jq.each(mimim,function(a,b){
$jq("#add_new_option_button").click();
$jq("#manage-options-panel tbody tr:last-child td:nth-child(3) input").val(b);

});

How to Update Magento 2.1x to latest version via SSH

composer require magento/product-community-edition 2.1.9 --no-update
composer update
rm -rf var/di/* var/generation/* var/cache/* var/log/* var/page_cache/*
php bin/magento cache:clean
php bin/magento cache:flush
php bin/magento setup:upgrade
php bin/magento setup:di:compile
php bin/magento setup:static-content:deploy
php bin/magento indexer:reindex

Start a magento instance programmatically

This Code:

$mageFilename = 'app/Mage.php';
require_once $mageFilename;
Mage::setIsDeveloperMode(true);
ini_set('display_errors', 1);
error_reporting(E_ALL & ~E_NOTICE);
umask(0);
Mage::app('admin');
Mage::register('isSecureArea', 1);
Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);
//your mage code here