original_string: public function addAction(Request $request)
      {
          $em = $this->getDoctrine()->getManager();
          $coreManager = $this->get('core_manager');
          $checkoutManager = $this->get('checkout_manager');
          $cart = $this->getCurrentCart();
          $emptyItem = new CartItem();
          
          try {
              $item = $checkoutManager->resolve($emptyItem, $request);
          } catch (\Exception $exception) {
              // Write flash message
              print_r($exception->getMessage());die();
              return $this->redirect($this->generateUrl('ecommerce_checkout_detail'));
          }
  
          $price = $item->getProduct()->getPrice();
          $item->setUnitPrice($price);
          $freeTransport = $item->getProduct()->isFreeTransport();
          $item->setFreeTransport($freeTransport);
          //add
          $cart->addItem($item);
          //refresh
          $cart->calculateTotal();
          $cart->setTotalItems($cart->countItems());
          //save
          $em->persist($cart);
          $em->flush();
         
          // Write flash message
          $referer = $coreManager->getRefererPath($request);
          return $this->redirect($this->generateUrl('ecommerce_checkout_detail').'?referer='.$referer);
      }
code: public function addAction(Request $request)
      {
          $em = $this->getDoctrine()->getManager();
          $coreManager = $this->get('core_manager');
          $checkoutManager = $this->get('checkout_manager');
          $cart = $this->getCurrentCart();
          $emptyItem = new CartItem();
          
          try {
              $item = $checkoutManager->resolve($emptyItem, $request);
          } catch (\Exception $exception) {
              // Write flash message
              print_r($exception->getMessage());die();
              return $this->redirect($this->generateUrl('ecommerce_checkout_detail'));
          }
  
          $price = $item->getProduct()->getPrice();
          $item->setUnitPrice($price);
          $freeTransport = $item->getProduct()->isFreeTransport();
          $item->setFreeTransport($freeTransport);
          //add
          $cart->addItem($item);
          //refresh
          $cart->calculateTotal();
          $cart->setTotalItems($cart->countItems());
          //save
          $em->persist($cart);
          $em->flush();
         
          // Write flash message
          $referer = $coreManager->getRefererPath($request);
          return $this->redirect($this->generateUrl('ecommerce_checkout_detail').'?referer='.$referer);
      }
code_tokens: public function addAction ( Request $ request ) { $ em = $ this -> getDoctrine ( ) -> getManager ( ) ; $ coreManager = $ this -> get ( 'core_manager' ) ; $ checkoutManager = $ this -> get ( 'checkout_manager' ) ; $ cart = $ this -> getCurrentCart ( ) ; $ emptyItem = new CartItem ( ) ; try { $ item = $ checkoutManager -> resolve ( $ emptyItem , $ request ) ; } catch ( \ Exception $ exception ) { // Write flash message print_r ( $ exception -> getMessage ( ) ) ; die ( ) ; return $ this -> redirect ( $ this -> generateUrl ( 'ecommerce_checkout_detail' ) ) ; } $ price = $ item -> getProduct ( ) -> getPrice ( ) ; $ item -> setUnitPrice ( $ price ) ; $ freeTransport = $ item -> getProduct ( ) -> isFreeTransport ( ) ; $ item -> setFreeTransport ( $ freeTransport ) ; //add $ cart -> addItem ( $ item ) ; //refresh $ cart -> calculateTotal ( ) ; $ cart -> setTotalItems ( $ cart -> countItems ( ) ) ; //save $ em -> persist ( $ cart ) ; $ em -> flush ( ) ; // Write flash message $ referer = $ coreManager -> getRefererPath ( $ request ) ; return $ this -> redirect ( $ this -> generateUrl ( 'ecommerce_checkout_detail' ) . '?referer=' . $ referer ) ; }
docstring: Adds item to cart.
  It uses the resolver service so you can populate the new item instance
  with proper values based on current request.
  
  It redirect to cart summary page by default.
  
  @param Request $request
  @return Response
  
  @Route("/cart/add")
  @Template("EcommerceBundle:Front:detail.html.twig")
docstring_tokens: Adds item to cart . It uses the resolver service so you can populate the new item instance with proper values based on current request .