class CouponCode extends \Magento\Framework\View\Element\Template

  protected $_customerSession;

  protected $_customerGroupCollection;

  public function __construct(
  \Magento\Customer\Model\Session $customerSession,
  \Magento\Customer\Model\Group $customerGroupCollection,
  \Magento\Framework\View\Element\Template\Context $context) 

    $this->_customerSession = $customerSession;
    $this->_customerGroupCollection = $customerGroupCollection;

    public function getCouponCodes()

        $currentGroupId = $this->_customerSession->getCustomer()->getGroupId(); //Get customer group Id , you have already this so directly get name
        $collection = $this->_customerGroupCollection->load($currentGroupId); 

        return $collection->getCustomerGroupCode();//Get group name



In your block constructor inject

\Magento\SalesRule\Model\ResourceModel\Rule\CollectionFactory $salesRuleCollectionFactory,

and then filter the sales rules collection by customer group id

$_salesRulecollectionByCustomerGroup = $this->_salesRuleCollectionFactory->create()->addCustomerGroupFilter($currentGroupId);
  • Thanks for your response,but after injecting this dependency ,nothing is shown on the screen, addAttributeInConditionFilteraddCustomerGroupFilter do you think this line is properly defined? Jan 14 '20 at 14:39
  • 1
    to debug this, you can enable the developer mode to print the error on the screen or check the logs....BTW check your Magento version to confirm whether this method is present in this file \Magento\SalesRule\Model\ResourceModel\Rule\Collection
    – Haijerome
    Jan 14 '20 at 15:53
  • Yes ,there are two method found in the file \Magento\SalesRule\Model\ResourceModel\Rule\Collection 'public function addAttributeInConditionFilter($attributeCode)' 'public function addCustomerGroupFilter($customerGroupId)' but from which one of above we have to used?for my solution and in which way? Jan 15 '20 at 6:11
  • Thanks alot,addCustomerGroupFilter($customerGroupId) function work for me Jan 15 '20 at 7:14
  • Can you have any idea about this question magento.stackexchange.com/questions/305896/… Mar 2 '20 at 16:14

Please add this code in your file. Youo will get what you want

$currentGroupId = $this->_customerSession->getCustomer()->getGroupId(); 
    $_salesRulecollectionByCustomerGroup = $this->_salesRuleCollectionFactory->create()->addCustomerGroupFilter($currentGroupId);
    $collection = $this->_customerGroupCollection->load($currentGroupId);
    foreach ($result as $res) {


And Customize it according to your code.

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.