The following code works on Magento 2.1. It allows you to set the tier pricing for the multiple groups:
<?php
use \Magento\Framework\App\Bootstrap;
require '/www/mag2.local/app/bootstrap.php';
$bootstrap = Bootstrap::create(BP, $_SERVER);
$objectManager = $bootstrap->getObjectManager();
### Setting area code
### NOTE: for more info http://devdocs.magento.com/guides/v2.1/architecture/archi_perspectives/components/modules/mod_and_areas.html
$state = $objectManager->get('\Magento\Framework\App\State');
$state->setAreaCode('base');
$tierPriceFactory = $objectManager->get('\Magento\Catalog\Api\Data\ProductTierPriceInterfaceFactory');
$tierPrices = [
// All groups
$tierPriceFactory->create()->setCustomerGroupId(32000)->setQty(4)->setValue(10.0),
$tierPriceFactory->create()->setCustomerGroupId(32000)->setQty(9)->setValue(9.0),
// Not logged in
$tierPriceFactory->create()->setCustomerGroupId(0)->setQty(5)->setValue(10.1),
$tierPriceFactory->create()->setCustomerGroupId(0)->setQty(10)->setValue(9.1),
// Wholesale
$tierPriceFactory->create()->setCustomerGroupId(2)->setQty(6)->setValue(10.2),
$tierPriceFactory->create()->setCustomerGroupId(2)->setQty(11)->setValue(9.2),
];
$prodInfoArr = [
['AttributeSetId' => 4, 'TypeId' => 'simple', 'Name' => 'My Product 20', 'Price' => 99, 'Sku' => 'MP20', 'Weight' => 10, 'TierPrices' => $tierPrices],
];
foreach ($prodInfoArr as $prodInfo) {
createProduct($prodInfo);
}
function createProduct($prodInfo = []) {
global $objectManager;
#$product = $objectManager->get('\Magento\Catalog\Model\ProductFactory')->create();
$product = $objectManager->get('\Magento\Catalog\Api\Data\ProductInterfaceFactory')->create();
$product->setAttributeSetId($prodInfo['AttributeSetId']); // importatnt
$product->setTypeId($prodInfo['TypeId']); // important
$product->setName($prodInfo['Name']);
$product->setPrice($prodInfo['Price']);
$product->setTierPrices($prodInfo['TierPrices']);
$product->setSku($prodInfo['Sku']);
#$product->setQty($prodInfo['Qty']); // will not work. Use "set stock data" instead.
$product->setWeight($prodInfo['Weight']);
$product->setTaxClassId(0); // (0: none, 1: default, 2: taxable, 4: shipping)
$product->setStatus(1);
$product->setVisibility(4);
$objectManager->get('\Magento\Catalog\Api\ProductRepositoryInterface')->save($product);
}