Elcodi\Store\GeoBundle\Controller\AddressController::deleteAction PHP Method

deleteAction() public method

Delete address
public deleteAction ( integer $id, string | null $source = null ) : Response
$id integer The address id
$source string | null The form source to redirect back
return Symfony\Component\HttpFoundation\Response Response
    public function deleteAction($id, $source = null)
    {
        $translator = $this->get('translator');
        /**
         * @var CustomerInterface $customer
         */
        $customer = $this->getUser();
        $address = $this->get('elcodi.repository.customer')->findAddress($customer->getId(), $id);
        if (!$address instanceof AddressInterface) {
            throw new NotFoundHttpException('Address not found');
        }
        $customerManager = $this->get('elcodi.object_manager.customer');
        $customer->removeAddress($address);
        $customerManager->flush($customer);
        $message = $translator->trans('store.address.delete.response_ok');
        $this->addFlash('success', $message);
        $redirectUrl = self::CHECKOUT_SOURCE == $source ? 'store_checkout_address' : 'store_address_list';
        return $this->redirect($this->generateUrl($redirectUrl));
    }