billingAddressManagement = $billingAddressManagement; $this->addressRepository = $addressRepository; $this->addressModel = $addressModel; $this->checkCustomerAccount = $checkCustomerAccount; $this->getCustomerAddress = $getCustomerAddress; } /** * Set billing address for a specified shopping cart * * @param ContextInterface $context * @param CartInterface $cart * @param array $billingAddress * @return void * @throws GraphQlInputException */ public function execute(ContextInterface $context, CartInterface $cart, array $billingAddress): void { $customerAddressId = $billingAddress['customer_address_id'] ?? null; $addressInput = $billingAddress['address'] ?? null; $useForShipping = $billingAddress['use_for_shipping'] ?? false; if (null === $customerAddressId && null === $addressInput) { throw new GraphQlInputException( __('The billing address must contain either "customer_address_id" or "address".') ); } if ($customerAddressId && $addressInput) { throw new GraphQlInputException( __('The billing address cannot contain "customer_address_id" and "address" at the same time.') ); } $addresses = $cart->getAllShippingAddresses(); if ($useForShipping && count($addresses) > 1) { throw new GraphQlInputException( __('Using the "use_for_shipping" option with multishipping is not possible.') ); } if (null === $customerAddressId) { $billingAddress = $this->addressModel->addData($addressInput); } else { $this->checkCustomerAccount->execute($context->getUserId(), $context->getUserType()); $customerAddress = $this->getCustomerAddress->execute((int)$customerAddressId, (int)$context->getUserId()); $billingAddress = $this->addressModel->importCustomerAddressData($customerAddress); } $this->billingAddressManagement->assign($cart->getId(), $billingAddress, $useForShipping); } }