/** * adjust_registration_quantities * will either add registrations for NEW tickets * or adjust quantities for existing tickets * * @access protected * @param \EE_Transaction $transaction * @param int $TKT_ID * @param array $ticket_line_items * @param array $reg_tickets * @return bool */ protected static function adjust_registration_quantities(EE_Transaction $transaction, $TKT_ID = 0, $ticket_line_items = array(), $reg_tickets = array()) { $changes = false; // are there any corresponding registrations for this ticket? if (isset($reg_tickets[$TKT_ID])) { // corresponding registrations exist, so let's compare counts... $tkt_count = count($ticket_line_items); $reg_count = count($reg_tickets[$TKT_ID]); if ($tkt_count > $reg_count) { // ticket(s) added = create registrations for ($x = 0; $x < $tkt_count - $reg_count; $x++) { $changes = EED_Multi_Event_Registration::add_registration($ticket_line_items[$x], $transaction) ? true : $changes; } } else { if ($tkt_count < $reg_count) { // ticket(s) removed = remove registrations for ($x = $reg_count; $x > $tkt_count; $x--) { // grab last registration that corresponds to this ticket type $registration = array_pop($reg_tickets[$TKT_ID]); $changes = EED_Multi_Event_Registration::remove_registration($transaction, $registration) ? true : $changes; } } else { // tickets match registrations = no change return false; } } } else { // no corresponding registrations???? // we need to create registrations for these tickets $reg_count = 0; foreach ($ticket_line_items as $ticket_line_item) { $reg_count++; $changes = EED_Multi_Event_Registration::add_registration($ticket_line_item, $transaction) ? true : $changes; } } return $changes; }
/** * display the widget * * @access public * @param array $args * @param array $instance * @throws \EE_Error */ function widget($args, $instance) { $instance['title'] = !empty($instance['title']) ? $instance['title'] : __('Your Registrations', 'event_espresso'); $instance['template'] = !empty($instance['template']) ? $instance['template'] : EE_MER_PATH . 'templates' . DS . 'widget_minicart_table.template.php'; // autoload Line_Item_Display classes EE_Registry::instance()->load_core('Cart'); EE_Registry::instance()->load_helper('Line_Item'); EE_Registry::instance()->load_core('Request_Handler'); extract($args); /** @type string $before_widget */ /** @type string $after_widget */ /** @type string $before_title */ /** @type string $after_title */ $checkout_page = false; if (EE_Registry::instance()->REQ->get_post_name_from_request() == basename(EE_Registry::instance()->CFG->core->reg_page_url()) && EE_Registry::instance()->REQ->get('event_cart', '') !== 'view') { $checkout_page = true; } $template_args = array(); $template_args['before_widget'] = $before_widget; $template_args['after_widget'] = $after_widget; $template_args['before_title'] = $before_title; $template_args['after_title'] = $after_title; $template_args['title'] = apply_filters('widget_title', $instance['title']); $template_args['event_cart_name'] = EED_Multi_Event_Registration::event_cart_name(); // hide "Proceed to Checkout" button on checkout page $template_args['checkout_page'] = $checkout_page; $template_args['events_list_url'] = EE_EVENTS_LIST_URL; $template_args['register_url'] = EE_EVENT_QUEUE_BASE_URL; $template_args['view_event_cart_url'] = add_query_arg(array('event_cart' => 'view'), EE_EVENT_QUEUE_BASE_URL); $template_args['btn_class'] = apply_filters('FHEE__EEW_Mini_Cart__event_cart_template__btn_class', ''); $template_args['mini_cart_display'] = EE_Registry::instance()->CART->all_ticket_quantity_count() > 0 ? '' : ' style="display:none;"'; $template_args['event_cart'] = $this->get_mini_cart($instance['template']); // ugh... inline css... well... better than loading another stylesheet on every page // and at least it's filterable... echo apply_filters('FHEE__EEW_Mini_Cart__widget__minicart_css', ' <style> .mini-cart-tbl-qty-th, .mini-cart-tbl-qty-td { padding: 0 .25em; } #mini-cart-whats-next-buttons { text-align: right; } .mini-cart-button { box-sizing: border-box; display: inline-block; padding: 8px; margin: 4px 0 4px 4px; vertical-align: middle; line-height: 8px; font-size: 12px; font-weight: normal; -webkit-user-select: none; border-radius: 2px !important; text-align: center !important; cursor: pointer !important; white-space: nowrap !important; } </style> '); echo EEH_Template::display_template($instance['template'], $template_args, true); }