/**
  * 	adds related EE_Registration objects for each ticket in the cart to the current EE_Transaction object
  *
  * 	@access private
  * 	@return 	void
  */
 private function _initialize_registrations()
 {
     if ($this->_transaction instanceof EE_Transaction) {
         $att_nmbr = 0;
         $total_items = $this->_cart->all_ticket_quantity_count();
         // now let's add the cart items to the $transaction
         foreach ($this->_cart->get_tickets() as $item) {
             // grab the related ticket object for this line_item
             $ticket = $item->ticket();
             if (!$ticket instanceof EE_Ticket) {
                 EE_Error::add_error(sprintf(__("Line item %s did not contain a valid ticket", "event_espresso"), $item->ID()), __FILE__, __FUNCTION__, __LINE__);
                 break;
             }
             $first_datetime = $ticket->get_first_related('Datetime');
             if (!$first_datetime instanceof EE_Datetime) {
                 EE_Error::add_error(sprintf(__("The ticket (%s) is not associated with any valid datetimes.", "event_espresso"), $ticket->name()), __FILE__, __FUNCTION__, __LINE__);
                 continue;
             }
             $event = $first_datetime->get_first_related('Event');
             if (!$event instanceof EE_Event) {
                 EE_Error::add_error(sprintf(__("The ticket (%s) is not associated with a valid event.", "event_espresso"), $ticket->name()), __FILE__, __FUNCTION__, __LINE__);
                 continue;
             }
             //do the following for each ticket of this type they selected
             for ($x = 1; $x <= $item->quantity(); $x++) {
                 $att_nmbr++;
                 $reg_url_link = $att_nmbr . '-' . $item->code();
                 // grab the default reg status for the event
                 $registration_status = $event->default_registration_status();
                 // if it's set to "Approved", then temporarily downgrade it to "Pending Payment", so that reg limits and/or ticket sales are not skewed in case the reg process is aborted
                 $registration_status = $registration_status == EEM_Registration::status_id_approved ? EEM_Registration::status_id_pending_payment : $registration_status;
                 try {
                     // now create a new registration for the ticket
                     $registration = EE_Registration::new_instance(array('EVT_ID' => $event->ID(), 'TXN_ID' => $this->_transaction->ID(), 'TKT_ID' => $ticket->ID(), 'STS_ID' => $registration_status, 'REG_date' => $this->_transaction->datetime(), 'REG_final_price' => $ticket->price(), 'REG_session' => EE_Registry::instance()->SSN->id(), 'REG_count' => $att_nmbr, 'REG_group_size' => $total_items, 'REG_url_link' => $reg_url_link));
                     // now create relations between various objects
                     $registration->_add_relation_to($event, 'Event', array(), $event->ID());
                     $registration->_add_relation_to($item->ticket(), 'Ticket', array(), $item->ticket()->ID());
                     $this->_transaction->_add_relation_to($registration, 'Registration', array(), $reg_url_link);
                     // if something failed...
                 } catch (Exception $e) {
                     EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
                     return;
                 }
             }
         }
         EE_Registry::instance()->SSN->set_session_data(array('transaction' => $this->_transaction));
         EE_Registry::instance()->SSN->update();
         //			echo '<h3>'. __CLASS__ . '->' . __FUNCTION__ . ' <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span></h3>';
     }
     return;
 }