$customerId =
$order->
getOrderCustomer()->
getCustomerId();
$customerGroupId = null;
if ($customerId) { /** @var CustomerEntity|null $customer */
$customer =
$this->customerRepository->
search(new Criteria([$customerId]),
$context)->
get($customerId);
if ($customer !== null
) { $customerGroupId =
$customer->
getGroupId();
} } $billingAddressId =
$order->
getBillingAddressId();
$billingAddress =
$this->orderAddressRepository->
search(new Criteria([$billingAddressId]),
$context)->
get($billingAddressId);
if (!
$billingAddress instanceof OrderAddressEntity
) { throw CartException::
addressNotFound($billingAddressId);
} $options =
[ SalesChannelContextService::CURRENCY_ID =>
$order->
getCurrencyId(),
SalesChannelContextService::LANGUAGE_ID =>
$order->
getLanguageId(),
SalesChannelContextService::CUSTOMER_ID =>
$customerId,
SalesChannelContextService::COUNTRY_STATE_ID =>
$billingAddress->
getCountryStateId(),
SalesChannelContextService::CUSTOMER_GROUP_ID =>
$customerGroupId,