getCartForUser = $getCartForUser; $this->couponManagement = $couponManagement; } /** * @inheritdoc */ public function resolve(Field $field, $context, ResolveInfo $info, array $value = null, array $args = null) { if (!isset($args['input']['cart_id'])) { throw new GraphQlInputException(__('Required parameter "cart_id" is missing')); } $maskedCartId = $args['input']['cart_id']; $currentUserId = $context->getUserId(); $cart = $this->getCartForUser->execute($maskedCartId, $currentUserId); $cartId = $cart->getId(); try { $this->couponManagement->remove($cartId); } catch (NoSuchEntityException $exception) { throw new GraphQlNoSuchEntityException(__($exception->getMessage())); } catch (CouldNotDeleteException $exception) { throw new LocalizedException(__($exception->getMessage())); } $data['cart']['applied_coupon'] = [ 'code' => '', ]; return $data; } }