Domanda

How to get customer group id into graphql magento2

Note: Only in GraphQL

È stato utile?

Soluzione

Not much clear what you are looking for. If you want to get the customer group_id in customer graphql query you can directly provide the output variable as below.

{
  customer {
    firstname
    lastname
    suffix
    email
    group_id
  }
}

Altri suggerimenti

Note: This only you'll get if customer is logged in in your Model Resolver file:

protected $_customerSession;

public function __construct(
    \Magento\Customer\Model\Session $customerSession,
) {
    $this->_customerSession = $customerSession;
}

public function getGroupId(){
if($this->_customerSession->isLoggedIn()):
    $customerGroupId = $this->_customerSession->getCustomer()->getGroupId();
endif;
}

After this you can set $customerGroupId variable as a array of your module.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a magento.stackexchange
scroll top