@@ 590-603 (lines=14) @@ | ||
587 | // and removing the ticket from datetimes it got removed from. |
|
588 | ||
589 | // first let's add datetimes |
|
590 | if ( ! empty( $added_datetimes ) && is_array( $added_datetimes ) ) { |
|
591 | foreach ( $added_datetimes as $row_id ) { |
|
592 | $row_id = (int)$row_id; |
|
593 | if ( isset( $saved_datetimes[ $row_id ] ) && $saved_datetimes[ $row_id ] instanceof EE_Datetime ) { |
|
594 | $ticket->_add_relation_to( $saved_datetimes[ $row_id ], 'Datetime' ); |
|
595 | // Is this an existing ticket (has an ID) and does it have any sold? |
|
596 | // If so, then we need to add that to the DTT sold because this DTT is getting added. |
|
597 | if ( $ticket->ID() && $ticket->sold() > 0 ) { |
|
598 | $saved_datetimes[ $row_id ]->increase_sold( $ticket->sold() ); |
|
599 | $saved_datetimes[ $row_id ]->save(); |
|
600 | } |
|
601 | } |
|
602 | } |
|
603 | } |
|
604 | // then remove datetimes |
|
605 | if ( ! empty( $removed_datetimes ) && is_array( $removed_datetimes ) ) { |
|
606 | foreach ( $removed_datetimes as $row_id ) { |
|
@@ 605-620 (lines=16) @@ | ||
602 | } |
|
603 | } |
|
604 | // then remove datetimes |
|
605 | if ( ! empty( $removed_datetimes ) && is_array( $removed_datetimes ) ) { |
|
606 | foreach ( $removed_datetimes as $row_id ) { |
|
607 | $row_id = (int)$row_id; |
|
608 | // its entirely possible that a datetime got deleted (instead of just removed from relationship. |
|
609 | // So make sure we skip over this if the dtt isn't in the $saved_datetimes array) |
|
610 | if ( isset( $saved_datetimes[ $row_id ] ) && $saved_datetimes[ $row_id ] instanceof EE_Datetime ) { |
|
611 | $ticket->_remove_relation_to( $saved_datetimes[ $row_id ], 'Datetime' ); |
|
612 | // Is this an existing ticket (has an ID) and does it have any sold? |
|
613 | // If so, then we need to remove it's sold from the DTT_sold. |
|
614 | if ( $ticket->ID() && $ticket->sold() > 0 ) { |
|
615 | $saved_datetimes[ $row_id ]->decrease_sold( $ticket->sold() ); |
|
616 | $saved_datetimes[ $row_id ]->save(); |
|
617 | } |
|
618 | } |
|
619 | } |
|
620 | } |
|
621 | // cap ticket qty by datetime reg limits |
|
622 | $ticket->set_qty( min( $ticket->qty(), $ticket->qty( 'reg_limit' ) ) ); |
|
623 | return $ticket; |