I have below snippet which I am using to update tier prices programaticaly:
$tierPricenew[0] = array('website_id' => 2,'cust_group' => $groupId, 'price_qty' => 1 , 'price' => floatval($price) );
$productObj->setTierPrice($tierPricenew);
$prices = $productObj->getTierPrice();
$productObj->unsetData('media_gallery');
$productObj->save();
This however takes very long with lots of products and so want to just update the tier_price
attribute alone as suggested elsewhere on stack exchange to quicken the whole process rather than saving the whole product object.
I have tried below methods saveAttribute:
$tierPricenew[0] = array('website_id' => 2,'cust_group' => $groupId, 'price_qty' => 1 , 'price' => floatval($price) );
$productObj->setTierPrice($tierPricenew);
$prices = $productObj->getTierPrice();
$productObj->setData('tier_price', $prices);
$this->productResource->saveAttribute($productObj, 'tier_price');
And this method updateAttributes:
$tierPricenew[0] = array('website_id' => 2,'cust_group' => $groupId, 'price_qty' => 1 , 'price' => floatval($price) );
$productObj->setTierPrice($tierPricenew);
$prices = $productObj->getTierPrice();
$this->productResourceModel->updateAttributes([$productObj->getId()], ['tier_price' => $prices]);
None of the above however seem to work for me. No errors are thrown however tier prices are not set. They work with other attributes like name etc but not tier_prices
. Is there a way to update these quickly with methods like above?
I have looked into the Magento\Catalog\Api\ProductTierPriceManagementInterface
class and tried with the remove method here however looking at this just seems to do very similar to my first method and saves the complete product object.
$this->tierPrice->remove($product->getSku(), $groupId, '1');
Import seems to do this so fast so feel there must be a quicker method to use here.