original_string: public function updateTransaction()
      {        
          $cart = $this->cartProvider->getCart();
  
          if (0 === $cart->countItems() || $this->isTransactionUpdated($cart)) {
              return;
          }
  
          /** @var TransactionRepository $transactionRepository */
          $transactionRepository = $this->manager->getRepository('EcommerceBundle:Transaction');
  
          if ($this->session->has('transaction-id')) {
              /** @var Transaction $transaction */
              $transaction = $transactionRepository->find($this->session->get('transaction-id'));
  
              $transactionRepository->removeItems($transaction);
          } else {
              $transactionKey = $transactionRepository->getNextNumber();
  
              // create a new transaction
              $transaction = new Transaction();
              $transaction->setTransactionKey($transactionKey);
              $transaction->setStatus(Transaction::STATUS_CREATED);
              $transaction->setActor($this->securityContext->getToken()->getUser());
              $cartItem = $cart->getItems()->first();
              $product = $cartItem->getProduct();
          }
  
          $orderTotalPrice = 0;
  
          foreach ($cart->getItems() as $cartItem) {
              /** @var Product $product */
              $product = $cartItem->getProduct();
  
              $productPurchase = new ProductPurchase();
              $productPurchase->setProduct($product);
              $productPurchase->setBasePrice($cartItem->getUnitPrice());
              $productPurchase->setQuantity($cartItem->getQuantity());
              $productPurchase->setDiscount($product->getDiscount());
              $productPurchase->setTotalPrice($cartItem->getTotal());
              $productPurchase->setTransaction($transaction);
              $productPurchase->setReturned(false);
              //free transport
              if($cartItem->isFreeTransport()){
                  $productPurchase->setDeliveryExpenses(0);
              }else{ 
                  $productPurchase->setDeliveryExpenses($cartItem->getShippingCost());
              }
              $orderTotalPrice += $cartItem->getProduct()->getPrice() * $cartItem->getQuantity();
  
              $this->manager->persist($productPurchase);
          }
  
          $transaction->setTotalPrice($orderTotalPrice);
  
          $this->manager->persist($transaction);
          $this->manager->flush();
  
          $this->session->set('transaction-id', $transaction->getId());
          $this->session->save();
          
      }
code: public function updateTransaction()
      {        
          $cart = $this->cartProvider->getCart();
  
          if (0 === $cart->countItems() || $this->isTransactionUpdated($cart)) {
              return;
          }
  
          /** @var TransactionRepository $transactionRepository */
          $transactionRepository = $this->manager->getRepository('EcommerceBundle:Transaction');
  
          if ($this->session->has('transaction-id')) {
              /** @var Transaction $transaction */
              $transaction = $transactionRepository->find($this->session->get('transaction-id'));
  
              $transactionRepository->removeItems($transaction);
          } else {
              $transactionKey = $transactionRepository->getNextNumber();
  
              // create a new transaction
              $transaction = new Transaction();
              $transaction->setTransactionKey($transactionKey);
              $transaction->setStatus(Transaction::STATUS_CREATED);
              $transaction->setActor($this->securityContext->getToken()->getUser());
              $cartItem = $cart->getItems()->first();
              $product = $cartItem->getProduct();
          }
  
          $orderTotalPrice = 0;
  
          foreach ($cart->getItems() as $cartItem) {
              /** @var Product $product */
              $product = $cartItem->getProduct();
  
              $productPurchase = new ProductPurchase();
              $productPurchase->setProduct($product);
              $productPurchase->setBasePrice($cartItem->getUnitPrice());
              $productPurchase->setQuantity($cartItem->getQuantity());
              $productPurchase->setDiscount($product->getDiscount());
              $productPurchase->setTotalPrice($cartItem->getTotal());
              $productPurchase->setTransaction($transaction);
              $productPurchase->setReturned(false);
              //free transport
              if($cartItem->isFreeTransport()){
                  $productPurchase->setDeliveryExpenses(0);
              }else{ 
                  $productPurchase->setDeliveryExpenses($cartItem->getShippingCost());
              }
              $orderTotalPrice += $cartItem->getProduct()->getPrice() * $cartItem->getQuantity();
  
              $this->manager->persist($productPurchase);
          }
  
          $transaction->setTotalPrice($orderTotalPrice);
  
          $this->manager->persist($transaction);
          $this->manager->flush();
  
          $this->session->set('transaction-id', $transaction->getId());
          $this->session->save();
          
      }
code_tokens: public function updateTransaction ( ) { $ cart = $ this -> cartProvider -> getCart ( ) ; if ( 0 === $ cart -> countItems ( ) || $ this -> isTransactionUpdated ( $ cart ) ) { return ; } /** @var TransactionRepository $transactionRepository */ $ transactionRepository = $ this -> manager -> getRepository ( 'EcommerceBundle:Transaction' ) ; if ( $ this -> session -> has ( 'transaction-id' ) ) { /** @var Transaction $transaction */ $ transaction = $ transactionRepository -> find ( $ this -> session -> get ( 'transaction-id' ) ) ; $ transactionRepository -> removeItems ( $ transaction ) ; } else { $ transactionKey = $ transactionRepository -> getNextNumber ( ) ; // create a new transaction $ transaction = new Transaction ( ) ; $ transaction -> setTransactionKey ( $ transactionKey ) ; $ transaction -> setStatus ( Transaction :: STATUS_CREATED ) ; $ transaction -> setActor ( $ this -> securityContext -> getToken ( ) -> getUser ( ) ) ; $ cartItem = $ cart -> getItems ( ) -> first ( ) ; $ product = $ cartItem -> getProduct ( ) ; } $ orderTotalPrice = 0 ; foreach ( $ cart -> getItems ( ) as $ cartItem ) { /** @var Product $product */ $ product = $ cartItem -> getProduct ( ) ; $ productPurchase = new ProductPurchase ( ) ; $ productPurchase -> setProduct ( $ product ) ; $ productPurchase -> setBasePrice ( $ cartItem -> getUnitPrice ( ) ) ; $ productPurchase -> setQuantity ( $ cartItem -> getQuantity ( ) ) ; $ productPurchase -> setDiscount ( $ product -> getDiscount ( ) ) ; $ productPurchase -> setTotalPrice ( $ cartItem -> getTotal ( ) ) ; $ productPurchase -> setTransaction ( $ transaction ) ; $ productPurchase -> setReturned ( false ) ; //free transport if ( $ cartItem -> isFreeTransport ( ) ) { $ productPurchase -> setDeliveryExpenses ( 0 ) ; } else { $ productPurchase -> setDeliveryExpenses ( $ cartItem -> getShippingCost ( ) ) ; } $ orderTotalPrice += $ cartItem -> getProduct ( ) -> getPrice ( ) * $ cartItem -> getQuantity ( ) ; $ this -> manager -> persist ( $ productPurchase ) ; } $ transaction -> setTotalPrice ( $ orderTotalPrice ) ; $ this -> manager -> persist ( $ transaction ) ; $ this -> manager -> flush ( ) ; $ this -> session -> set ( 'transaction-id' , $ transaction -> getId ( ) ) ; $ this -> session -> save ( ) ; }
docstring: Update transaction with cart's contents
docstring_tokens: Update transaction with cart s contents