문제

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;
    parent::__construct($context);
  }

    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);

다른 팁

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);
    $result=$_salesRulecollectionByCustomerGroup->getData();
    foreach ($result as $res) {
        print_r($res['rule_id']);

    }

And Customize it according to your code.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 magento.stackexchange
scroll top