original_string: public function saveDelivery(Delivery $delivery, array $params, $cart)
      {
          /** @var Carrier $carrier */
  //        $carrier = $this->manager->getRepository('ModelBundle:Carrier')->find($delivery->getCarrier());
  
          if ('same' === $params['selectDelivery']) {
              $delivery->setDeliveryContactPerson($delivery->getContactPerson());
              $delivery->setDeliveryDni($delivery->getDni());
              $delivery->setDeliveryAddressInfo($delivery->getAddressInfo());
              $delivery->setDeliveryPhone($delivery->getPhone());
              $delivery->setDeliveryPhone2($delivery->getPhone2());
              $delivery->setDeliveryPreferredSchedule($delivery->getPreferredSchedule());
          } else if ('existing' === $params['selectDelivery']) {
              /** @var Address $address */
              $address = $this->manager->getRepository('EcommerceBundle:Address')->find($params['existingDeliveryAddress']);
  
              $delivery->setDeliveryContactPerson($address->getContactPerson());
              $delivery->setDeliveryDni($address->getDni());
              $delivery->setDeliveryAddressInfo($address->getAddressInfo());
              $delivery->setDeliveryPhone($address->getPhone());
              $delivery->setDeliveryPhone2($address->getPhone2());
              $delivery->setDeliveryPreferredSchedule($address->getPreferredSchedule());
              
          } else if ('new' === $params['selectDelivery']) {
              $this->addUserDeliveryAddress($delivery);
          }
  
          $deliveryCountry = $this->manager->getRepository('CoreBundle:Country')->find('es');
          $delivery->setDeliveryCountry($deliveryCountry);
  
           
          $total = 0;
          $productPurchases = $this->manager->getRepository('EcommerceBundle:ProductPurchase')->findByTransaction($delivery->getTransaction());
          foreach ($productPurchases as $item) {
              if($item->getDeliveryExpenses()>0)
              $total = $total + $item->getDeliveryExpenses();
          }
          $delivery->setExpenses($total);
          if($total>0) $delivery->setExpensesType('store_pickup');
          else $delivery->setExpensesType('send');
  
          
          $this->saveUserBillingAddress($delivery);
          
        
                
          $this->manager->persist($delivery);
          $this->manager->flush();
  
          $this->session->set('delivery-id', $delivery->getId());
          $this->session->set('select-delivery', $params['selectDelivery']);
          if ('existing' === $params['selectDelivery']) {
              $this->session->set('existing-delivery-address', intval($params['existingDeliveryAddress']));
          } else {
              $this->session->remove('existing-delivery-address');
          }
  
          $this->session->save();
      }
code: public function saveDelivery(Delivery $delivery, array $params, $cart)
      {
          /** @var Carrier $carrier */
  //        $carrier = $this->manager->getRepository('ModelBundle:Carrier')->find($delivery->getCarrier());
  
          if ('same' === $params['selectDelivery']) {
              $delivery->setDeliveryContactPerson($delivery->getContactPerson());
              $delivery->setDeliveryDni($delivery->getDni());
              $delivery->setDeliveryAddressInfo($delivery->getAddressInfo());
              $delivery->setDeliveryPhone($delivery->getPhone());
              $delivery->setDeliveryPhone2($delivery->getPhone2());
              $delivery->setDeliveryPreferredSchedule($delivery->getPreferredSchedule());
          } else if ('existing' === $params['selectDelivery']) {
              /** @var Address $address */
              $address = $this->manager->getRepository('EcommerceBundle:Address')->find($params['existingDeliveryAddress']);
  
              $delivery->setDeliveryContactPerson($address->getContactPerson());
              $delivery->setDeliveryDni($address->getDni());
              $delivery->setDeliveryAddressInfo($address->getAddressInfo());
              $delivery->setDeliveryPhone($address->getPhone());
              $delivery->setDeliveryPhone2($address->getPhone2());
              $delivery->setDeliveryPreferredSchedule($address->getPreferredSchedule());
              
          } else if ('new' === $params['selectDelivery']) {
              $this->addUserDeliveryAddress($delivery);
          }
  
          $deliveryCountry = $this->manager->getRepository('CoreBundle:Country')->find('es');
          $delivery->setDeliveryCountry($deliveryCountry);
  
           
          $total = 0;
          $productPurchases = $this->manager->getRepository('EcommerceBundle:ProductPurchase')->findByTransaction($delivery->getTransaction());
          foreach ($productPurchases as $item) {
              if($item->getDeliveryExpenses()>0)
              $total = $total + $item->getDeliveryExpenses();
          }
          $delivery->setExpenses($total);
          if($total>0) $delivery->setExpensesType('store_pickup');
          else $delivery->setExpensesType('send');
  
          
          $this->saveUserBillingAddress($delivery);
          
        
                
          $this->manager->persist($delivery);
          $this->manager->flush();
  
          $this->session->set('delivery-id', $delivery->getId());
          $this->session->set('select-delivery', $params['selectDelivery']);
          if ('existing' === $params['selectDelivery']) {
              $this->session->set('existing-delivery-address', intval($params['existingDeliveryAddress']));
          } else {
              $this->session->remove('existing-delivery-address');
          }
  
          $this->session->save();
      }
code_tokens: public function saveDelivery ( Delivery $ delivery , array $ params , $ cart ) { /** @var Carrier $carrier */ //        $carrier = $this->manager->getRepository('ModelBundle:Carrier')->find($delivery->getCarrier()); if ( 'same' === $ params [ 'selectDelivery' ] ) { $ delivery -> setDeliveryContactPerson ( $ delivery -> getContactPerson ( ) ) ; $ delivery -> setDeliveryDni ( $ delivery -> getDni ( ) ) ; $ delivery -> setDeliveryAddressInfo ( $ delivery -> getAddressInfo ( ) ) ; $ delivery -> setDeliveryPhone ( $ delivery -> getPhone ( ) ) ; $ delivery -> setDeliveryPhone2 ( $ delivery -> getPhone2 ( ) ) ; $ delivery -> setDeliveryPreferredSchedule ( $ delivery -> getPreferredSchedule ( ) ) ; } else if ( 'existing' === $ params [ 'selectDelivery' ] ) { /** @var Address $address */ $ address = $ this -> manager -> getRepository ( 'EcommerceBundle:Address' ) -> find ( $ params [ 'existingDeliveryAddress' ] ) ; $ delivery -> setDeliveryContactPerson ( $ address -> getContactPerson ( ) ) ; $ delivery -> setDeliveryDni ( $ address -> getDni ( ) ) ; $ delivery -> setDeliveryAddressInfo ( $ address -> getAddressInfo ( ) ) ; $ delivery -> setDeliveryPhone ( $ address -> getPhone ( ) ) ; $ delivery -> setDeliveryPhone2 ( $ address -> getPhone2 ( ) ) ; $ delivery -> setDeliveryPreferredSchedule ( $ address -> getPreferredSchedule ( ) ) ; } else if ( 'new' === $ params [ 'selectDelivery' ] ) { $ this -> addUserDeliveryAddress ( $ delivery ) ; } $ deliveryCountry = $ this -> manager -> getRepository ( 'CoreBundle:Country' ) -> find ( 'es' ) ; $ delivery -> setDeliveryCountry ( $ deliveryCountry ) ; $ total = 0 ; $ productPurchases = $ this -> manager -> getRepository ( 'EcommerceBundle:ProductPurchase' ) -> findByTransaction ( $ delivery -> getTransaction ( ) ) ; foreach ( $ productPurchases as $ item ) { if ( $ item -> getDeliveryExpenses ( ) > 0 ) $ total = $ total + $ item -> getDeliveryExpenses ( ) ; } $ delivery -> setExpenses ( $ total ) ; if ( $ total > 0 ) $ delivery -> setExpensesType ( 'store_pickup' ) ; else $ delivery -> setExpensesType ( 'send' ) ; $ this -> saveUserBillingAddress ( $ delivery ) ; $ this -> manager -> persist ( $ delivery ) ; $ this -> manager -> flush ( ) ; $ this -> session -> set ( 'delivery-id' , $ delivery -> getId ( ) ) ; $ this -> session -> set ( 'select-delivery' , $ params [ 'selectDelivery' ] ) ; if ( 'existing' === $ params [ 'selectDelivery' ] ) { $ this -> session -> set ( 'existing-delivery-address' , intval ( $ params [ 'existingDeliveryAddress' ] ) ) ; } else { $ this -> session -> remove ( 'existing-delivery-address' ) ; } $ this -> session -> save ( ) ; }
docstring: Save delivery fields from billing fields
  
  @param Delivery $delivery
  @param array    $params
docstring_tokens: Save delivery fields from billing fields