0

How to add Tier Price programatically for all customer group

Tried below not working.

As ALL GROUP id is 32000;

$sku = "test";
$customerGroupId = 32000;
$price = 5.5;
$qty = 2;

$tierPrice = $obj->create('Magento\Catalog\Api\ProductTierPriceManagementInterface')->add($sku, $customerGroupId, $price, $qty);
echo "done";
  • You forgot to add $tierPrice->save(); – Rohan Hapani Feb 13 at 12:04
  • @RohanHapani above code is working for other ids only 32000 has the no such entity error – Tirth Patel Feb 13 at 12:31
  • it might not be present in customer group. please make sure that id is available or not – Vishnunath Feb 13 at 13:33
0

Check the below code for set tier prices.

class Product extends \Magento\Framework\View\Element\Template
{
    protected $_productloader;  

    public function __construct(
        \Magento\Framework\View\Element\Template\Context $context,
        \Magento\Catalog\Model\ProductFactory $_productloader

    ) {


        $this->_productloader = $_productloader;
        parent::__construct($context);
    }
    public function getLoadProduct($id)
    {
        return $this->_productloader->create()->load($id);
    }

    public function setTierPriceForGroup(){
        $tierPrices[] = array(
             'website_id'  => 0,
             'cust_group'  => 32000,
             'price_qty'   => 2,
             'price'       => 5.5
        );

        $product_id = 1; //PASS YOUR PRODUCT ID HERE   
        $product = $this->getLoadProduct($product_id);
        $product->setTierPrice($tierPrices);
        $product->save();
    }
}
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.