I am trying to get Product price by customer group. Used below code.
$sku = 123;
$customerGroup = $this->getCustomerGroupId();
$currentProduct = $this->loadProduct($sku);
$productPrice = $currentProduct->getPrice();
public function loadProduct($sku)
{
return $this->productRepository->get($sku);
}
public function getCustomerGroupId(){
if ($this->customerSession->isLoggedIn()) {
$customerGroup = $this->customerSession->getCustomer()->getGroupId();
return $customerGroup;
}
return;
}
Above code returning the product final price.
Can we get product price by customer Group code?
$customerGroup
is returing the current customer group that is id = 5 in my case. How to get the product price from customer group?
Can anyone look into this and update me your ideas. Thanks
Best Answer
Try this one but don't use ObjectManager, you can inject Magento\Catalog\Model\Product & \Magento\Customer\Api\GroupRepositoryInterface class in constructor: