2

I want to get customer group from sales order item collection. How do i get that?

In Magento 1 it is like this

$customer_group = Mage::getModel('customer/group')->load($order->getCustomerGroupId());

how can i get it in magento 2.

I have item collection and i want customer group for each item.

How to get please answer.

2 Answers 2

0

You can fetch customer group using below code.

public function __construct(
    \Magento\Customer\Api\GroupRepositoryInterface $groupRepository        
) {
    $this->groupRepository = $groupRepository;
}

public function getCustomerGroup()
{  
   $customerGroup = $this->groupRepository->getById($order->getCustomerGroupId());
   echo $customerGroup->getCode(); // 
}

I hope it'll work, let me know if you need further assistance. Happy Coding :)

0

You need to join two collections or tables to get customer group

I had joined two tables order table and order item table

refer the following solution to join two collections

Join two colections

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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