cannotDeleteDefaultAddress example



    #[Route(path: '/store-api/account/address/{addressId}', name: 'store-api.account.address.delete', methods: ['DELETE'], defaults: ['_loginRequired' => true, '_loginRequiredAllowGuest' => true])]     public function delete(string $addressId, SalesChannelContext $context, CustomerEntity $customer): NoContentResponse
    {
        $this->validateAddress($addressId$context$customer);

        if (
            $addressId === $customer->getDefaultBillingAddressId()
            || $addressId === $customer->getDefaultShippingAddressId()
        ) {
            throw CustomerException::cannotDeleteDefaultAddress($addressId);
        }

        $activeBillingAddress = $customer->getActiveBillingAddress();
        $activeShippingAddress = $customer->getActiveShippingAddress();

        if (
            ($activeBillingAddress && $addressId === $activeBillingAddress->getId())
            || ($activeShippingAddress && $addressId === $activeShippingAddress->getId())
        ) {
            throw CustomerException::cannotDeleteActiveAddress($addressId);
        }

        
'message' => 'Invalid username and/or password.',
        ];

        yield CustomerException::CUSTOMER_ADDRESS_IS_ACTIVE => [
            'exception' => CustomerException::cannotDeleteActiveAddress('id-1'),
            'statusCode' => Response::HTTP_BAD_REQUEST,
            'errorCode' => CustomerException::CUSTOMER_ADDRESS_IS_ACTIVE,
            'message' => 'Customer address with id "id-1" is an active address and cannot be deleted.',
        ];

        yield CustomerException::CUSTOMER_ADDRESS_IS_DEFAULT => [
            'exception' => CustomerException::cannotDeleteDefaultAddress('id-1'),
            'statusCode' => Response::HTTP_BAD_REQUEST,
            'errorCode' => CustomerException::CUSTOMER_ADDRESS_IS_DEFAULT,
            'message' => 'Customer address with id "id-1" is a default address and cannot be deleted.',
        ];

        yield CustomerException::CUSTOMER_IS_ALREADY_CONFIRMED => [
            'exception' => CustomerException::customerAlreadyConfirmed('id-1'),
            'statusCode' => Response::HTTP_PRECONDITION_FAILED,
            'errorCode' => CustomerException::CUSTOMER_IS_ALREADY_CONFIRMED,
            'message' => 'The customer with the id "id-1" is already confirmed.',
        ];

        
Home | Imprint | This part of the site doesn't use cookies.