public function removeAction($id)
    {
        $em = $this->getDoctrine()->getManager();
        $cart = $this->getCurrentCart();
        $repository = $em->getRepository('EcommerceBundle:CartItem');
        $item = $repository->find($id);

        if (!$item || false === $cart->hasItem($item)) {
            // Write flash message
            return $this->redirect($this->generateUrl('ecommerce_checkout_detail'));
        }

        // Update models
        $cart->removeItem($item);
        $cart->setTotalItems(count($cart->getItems()));
        $em->flush();
        // Write flash message

        return $this->redirect($this->generateUrl('ecommerce_checkout_detail'));
    }
public function removeAction($id)
    {
        $em = $this->getDoctrine()->getManager();
        $cart = $this->getCurrentCart();
        $repository = $em->getRepository('EcommerceBundle:CartItem');
        $item = $repository->find($id);

        if (!$item || false === $cart->hasItem($item)) {
            // Write flash message
            return $this->redirect($this->generateUrl('ecommerce_checkout_detail'));
        }

        // Update models
        $cart->removeItem($item);
        $cart->setTotalItems(count($cart->getItems()));
        $em->flush();
        // Write flash message

        return $this->redirect($this->generateUrl('ecommerce_checkout_detail'));
    }
public function removeAction ( $ id ) { $ em = $ this -> getDoctrine ( ) -> getManager ( ) ; $ cart = $ this -> getCurrentCart ( ) ; $ repository = $ em -> getRepository ( 'EcommerceBundle:CartItem' ) ; $ item = $ repository -> find ( $ id ) ; if ( ! $ item || false === $ cart -> hasItem ( $ item ) ) { // Write flash message return $ this -> redirect ( $ this -> generateUrl ( 'ecommerce_checkout_detail' ) ) ; } // Update models $ cart -> removeItem ( $ item ) ; $ cart -> setTotalItems ( count ( $ cart -> getItems ( ) ) ) ; $ em -> flush ( ) ; // Write flash message return $ this -> redirect ( $ this -> generateUrl ( 'ecommerce_checkout_detail' ) ) ; }
Removes item from cart.
It takes an item id as an argument.

If the item is found and the current user cart contains that item,
it will be removed and the cart - refreshed and saved.

@param mixed $id
@return Response

@Route("/cart/remove/{id}")
Removes item from cart . It takes an item id as an argument .