Controller/CartController.php
public function removeItemAction(Request $request)
    {
        $cart = $this->getCart();
        $item = $this->getDoctrine()
            ->getRepository('EkynaOrderBundle:OrderItem')
            ->findOneBy([
                'id' => $request->attributes->get('itemId'),
                'orderId' => $cart->getId(),
            ]);

        if (null === $item) {
            throw new NotFoundHttpException($this->getTranslator()->trans('ekyna_cart.message.item_not_found'));
        }

        $event = new OrderItemEvent($cart, $item);
        $this->getDispatcher()->dispatch(OrderItemEvents::REMOVE, $event);
        if (!$event->isPropagationStopped()) {
            $message = 'ekyna_cart.message.item_remove.success';
            $type    = 'success';
        } else {
            $message = 'ekyna_cart.message.item_remove.failure';
            $type    = 'danger';
        }
        $this->addFlash($this->getTranslator()->trans($message, [
            '{{ name }}' => $item->getDesignation(),
            '{{ path }}' => $this->generateUrl('ekyna_cart_index'),
        ]), $type);

        if ($request->isXmlHttpRequest()) {
            // TODO
            return new Response();
        }

        return $this->redirectAfterContentChange($request);
    }
public function removeItemAction(Request $request)
    {
        $cart = $this->getCart();
        $item = $this->getDoctrine()
            ->getRepository('EkynaOrderBundle:OrderItem')
            ->findOneBy([
                'id' => $request->attributes->get('itemId'),
                'orderId' => $cart->getId(),
            ]);

        if (null === $item) {
            throw new NotFoundHttpException($this->getTranslator()->trans('ekyna_cart.message.item_not_found'));
        }

        $event = new OrderItemEvent($cart, $item);
        $this->getDispatcher()->dispatch(OrderItemEvents::REMOVE, $event);
        if (!$event->isPropagationStopped()) {
            $message = 'ekyna_cart.message.item_remove.success';
            $type    = 'success';
        } else {
            $message = 'ekyna_cart.message.item_remove.failure';
            $type    = 'danger';
        }
        $this->addFlash($this->getTranslator()->trans($message, [
            '{{ name }}' => $item->getDesignation(),
            '{{ path }}' => $this->generateUrl('ekyna_cart_index'),
        ]), $type);

        if ($request->isXmlHttpRequest()) {
            // TODO
            return new Response();
        }

        return $this->redirectAfterContentChange($request);
    }
public function removeItemAction ( Request $ request ) { $ cart = $ this -> getCart ( ) ; $ item = $ this -> getDoctrine ( ) -> getRepository ( 'EkynaOrderBundle:OrderItem' ) -> findOneBy ( [ 'id' => $ request -> attributes -> get ( 'itemId' ) , 'orderId' => $ cart -> getId ( ) , ] ) ; if ( null === $ item ) { throw new NotFoundHttpException ( $ this -> getTranslator ( ) -> trans ( 'ekyna_cart.message.item_not_found' ) ) ; } $ event = new OrderItemEvent ( $ cart , $ item ) ; $ this -> getDispatcher ( ) -> dispatch ( OrderItemEvents :: REMOVE , $ event ) ; if ( ! $ event -> isPropagationStopped ( ) ) { $ message = 'ekyna_cart.message.item_remove.success' ; $ type = 'success' ; } else { $ message = 'ekyna_cart.message.item_remove.failure' ; $ type = 'danger' ; } $ this -> addFlash ( $ this -> getTranslator ( ) -> trans ( $ message , [ '{{ name }}' => $ item -> getDesignation ( ) , '{{ path }}' => $ this -> generateUrl ( 'ekyna_cart_index' ) , ] ) , $ type ) ; if ( $ request -> isXmlHttpRequest ( ) ) { // TODO return new Response ( ) ; } return $ this -> redirectAfterContentChange ( $ request ) ; }
Remove item action.

@param Request $request
@return \Symfony\Component\HttpFoundation\RedirectResponse|Response
@throws \Symfony\Component\HttpKernel\Exception\NotFoundHttpException
Remove item action .