I am having issues setting tier prices in Magento 2.2.1, I have looked at setting the tier prices and used below to get myself started:
Magento 2: How to set Tier Pricing Programatically Group Wise
This seemed to work sometimes but am getting the below error which seems to suggest that something has changed since the update to 2.2.x. Upon some research the old method is depreciated and suggests to use another interface:
Warning: Invalid argument supplied for foreach() in /var/www/mage2/public_html/vendor/magento/module-catalog/Model/Product/TierPriceManagement.php on line 103
https://github.com/magento/magento2/issues/10884
But cannot work out quite how to fix am currently using the below:
\Magento\Catalog\Api\ProductTierPriceManagementInterface $tierInterface
$this->tierInterface = $tierInterface;
$this->tierInterface->add($sku,$groupId,$price, '1');
From the github issue i have changed: \Magento\Catalog\Api\ProductTierPriceManagementInterface $tierInterface
to \Magento\Catalog\Api\ScopedProductTierPriceManagementInterface $tierInterface
Update
Ok so i injected that class into my construct and use like below:
$tierPrice = $this->tierPrice;
$tierPrice->setQty(floatval(1));
$tierPrice->setValue(floatval($price));
$tierPrice->setCustomerGroupId($groupId);
$this->tierInterface->add($sku,$tierPrice);
I was getting errors about values not being valid so used floatval to fix this. Still errors occur for a lot of products however always the same products but others work fine everytime. New error:
Exception #0 (Magento\Framework\Exception\CouldNotSaveException): Could not save group price
Not sure why this happens will keep working on it but seems similar to what i was experiencing with the previous method. These seem to be products that i got to work previously as have prices set bet they cannot be set again. I have tried removing the old price and it works after that but need it to just update programaticaly.
Still unsure how to set these prices for a specific website however but may ask this in a separate question.