create('Magento\Customer\Api\CustomerRepositoryInterface'); /** @var CustomerRegistry $registry */ $registry = Bootstrap::getObjectManager()->create('Magento\Customer\Model\CustomerRegistry'); $customer = $repository->getById($registry->retrieveByEmail('customer@example.com')->getId()); /** @var Quote $quote */ $quote = Bootstrap::getObjectManager()->create('Magento\Quote\Model\Quote'); $quote->load('test01', 'reserved_order_id'); $quote->setCustomerIsGuest(false)->setCustomerId($customer->getId()) ->setCustomerGroupId($customer->getGroupId()) ->save(); $this->assertNotNull($customer->getGroupId(), "Precondition failed: Customer group is not set."); $this->assertEquals( $customer->getGroupId(), $quote->getCustomerGroupId(), "Precondition failed: Customer group in quote is invalid." ); /** * 'customer_save_after_data_object' event is expected to be dispatched when customer save is invoked. * \Magento\Sales\Model\Observer\Backend\CustomerQuote::dispatch() is an observer of this event. */ $newCustomerGroupId = 2; $customer->setGroupId($newCustomerGroupId); $repository->save($customer); $quote->load('test01', 'reserved_order_id'); $this->assertEquals( $newCustomerGroupId, $quote->getCustomerGroupId(), 'Customer group in quote was not updated on "customer_save_after_data_object" event ' . 'by Magento\Sales\Model\Observer\Backend\CustomerQuote::dispatch().' ); } }