/**
  * Returns a string indicating current availability of the ticket.
  *
  * @return string
  */
 protected function get_ticket_availability()
 {
     $stock = $this->ticket->stock();
     if ($stock <= 0 && $stock !== '') {
         return 'SoldOut';
     }
     if ($stock > 1 && $stock <= $this->low_stock) {
         return 'LimitedAvailability';
     } else {
         return 'InStock';
     }
 }
Beispiel #2
0
 /**
  * Gets an individual ticket
  *
  * @param $unused_event_id
  * @param $ticket_id
  *
  * @return null|Tribe__Tickets__Ticket_Object
  */
 public function get_ticket($unused_event_id, $ticket_id)
 {
     $product = edd_get_download($ticket_id);
     if (!$product) {
         return null;
     }
     $return = new Tribe__Tickets__Ticket_Object();
     $purchased = $this->stock_control->get_purchased_inventory($ticket_id, array('publish'));
     $stock = '' === $product->_stock ? Tribe__Tickets__Ticket_Object::UNLIMITED_STOCK : $product->_stock;
     $return->description = $product->post_content;
     $return->frontend_link = get_permalink($ticket_id);
     $return->ID = $ticket_id;
     $return->name = $product->post_title;
     $return->price = $product->edd_price;
     $return->provider_class = get_class($this);
     $return->admin_link = admin_url(sprintf(get_post_type_object($product->post_type)->_edit_link . '&action=edit', $ticket_id));
     $return->start_date = get_post_meta($ticket_id, '_ticket_start_date', true);
     $return->end_date = get_post_meta($ticket_id, '_ticket_end_date', true);
     $pending = $this->stock_control->count_incomplete_order_items($ticket_id);
     $return->manage_stock((bool) $stock);
     $return->stock($stock - $purchased - $pending);
     $return->qty_sold($purchased);
     $return->qty_pending($pending);
     return $return;
 }
Beispiel #3
0
 /**
  * Gets an individual ticket
  *
  * @param $event_id
  * @param $ticket_id
  *
  * @return null|Tribe__Tickets__Ticket_Object
  */
 public function get_ticket($event_id, $ticket_id)
 {
     if (class_exists('WC_Product_Simple')) {
         $product = new WC_Product_Simple($ticket_id);
     } else {
         $product = new WC_Product($ticket_id);
     }
     if (!$product) {
         return null;
     }
     $return = new Tribe__Tickets__Ticket_Object();
     $product_data = $product->get_post_data();
     $qty = get_post_meta($ticket_id, 'total_sales', true);
     $return->description = $product_data->post_excerpt;
     $return->frontend_link = get_permalink($ticket_id);
     $return->ID = $ticket_id;
     $return->name = $product->get_title();
     $return->price = $product->get_price();
     $return->regular_price = $product->get_regular_price();
     $return->on_sale = (bool) $product->is_on_sale();
     $return->provider_class = get_class($this);
     $return->admin_link = admin_url(sprintf(get_post_type_object($product_data->post_type)->_edit_link . '&action=edit', $ticket_id));
     $return->start_date = get_post_meta($ticket_id, '_ticket_start_date', true);
     $return->end_date = get_post_meta($ticket_id, '_ticket_end_date', true);
     $return->purchase_limit = get_post_meta($ticket_id, '_ticket_purchase_limit', true);
     $complete_totals = $this->count_order_items_by_status($ticket_id, 'complete');
     $pending_totals = $this->count_order_items_by_status($ticket_id, 'incomplete');
     $qty = $qty ? $qty : 0;
     $pending = $pending_totals['total'] ? $pending_totals['total'] : 0;
     // if any orders transitioned from complete back to one of the incomplete states, their quantities
     // were already recorded in total_sales and we have to deduct them from there so they aren't
     // double counted
     $qty -= $pending_totals['recorded_sales'];
     // let's calculate the stock based on the product stock minus the quantity purchased minus the
     // pending purchases
     $stock = $product->get_stock_quantity() - $qty - $pending;
     // if any orders have reduced the stock of an order (check and cash on delivery payments do this, for example)
     // we need to re-inflate the stock by that amount
     $stock += $pending_totals['reduced_stock'];
     $stock += $complete_totals['reduced_stock'];
     $return->manage_stock($product->managing_stock());
     $return->stock($stock);
     $return->qty_sold($qty);
     $return->qty_pending($pending);
     $return->qty_cancelled($this->get_cancelled($ticket_id));
     if (empty($return->purchase_limit) && 0 !== (int) $return->purchase_limit) {
         /**
          * Filter the default purchase limit for the ticket
          *
          * @var int
          *
          * @return int
          */
         $return->purchase_limit = apply_filters('tribe_tickets_default_purchase_limit', 0);
     }
     return apply_filters('wootickets_get_ticket', $return, $event_id, $ticket_id);
 }
Beispiel #4
0
 /**
  * Gets an individual ticket
  *
  * @param $event_id
  * @param $ticket_id
  *
  * @return null|Tribe__Tickets__Ticket_Object
  */
 public function get_ticket($event_id, $ticket_id)
 {
     global $wpdb;
     $return = new Tribe__Tickets__Ticket_Object();
     $product_data = get_post($ticket_id);
     $product = new WPSC_Product($ticket_id);
     $return->description = $product_data->post_excerpt;
     $return->frontend_link = get_permalink($ticket_id);
     $return->ID = $ticket_id;
     $return->name = $product_data->post_title;
     $return->on_sale = (bool) $product->is_on_sale;
     $return->regular_price = $product->price;
     $return->price = $return->on_sale ? $product->sale_price : $product->price;
     $return->provider_class = get_class($this);
     $return->admin_link = admin_url(sprintf(get_post_type_object($product_data->post_type)->_edit_link . '&action=edit', $ticket_id));
     $return->start_date = get_post_meta($ticket_id, '_ticket_start_date', true);
     $return->end_date = get_post_meta($ticket_id, '_ticket_end_date', true);
     $cart_table = $cart_table = $wpdb->prefix . 'wpsc_cart_contents';
     $qty_sql = $wpdb->prepare("SELECT sum(quantity) FROM {$cart_table} WHERE prodid=%d", $ticket_id);
     $qty = max((int) $wpdb->get_var($qty_sql), 0);
     $pending = $qty ? $this->count_incomplete_order_items($ticket_id) : 0;
     $manage_stock = get_post_meta($ticket_id, '_manage_stock', true);
     if ('no' === $manage_stock) {
         $return->stock = null;
     }
     $return->manage_stock(!is_null($product->stock));
     $return->stock(is_null($product->stock) ? Tribe__Tickets__Ticket_Object::UNLIMITED_STOCK : $product->stock);
     $return->qty_sold($qty);
     $return->qty_pending($pending);
     return $return;
 }
Beispiel #5
0
 /**
  * Gets an individual ticket
  *
  * @param $event_id
  * @param $ticket_id
  *
  * @return null|Tribe__Tickets__Ticket_Object
  */
 public function get_ticket($event_id, $ticket_id)
 {
     $product = get_post($ticket_id);
     if (!$product) {
         return null;
     }
     $return = new Tribe__Tickets__Ticket_Object();
     $qty = (int) get_post_meta($ticket_id, 'total_sales', true);
     $return->description = $product->post_excerpt;
     $return->ID = $ticket_id;
     $return->name = $product->post_title;
     $return->price = get_post_meta($ticket_id, '_price', true);
     $return->provider_class = get_class($this);
     $return->admin_link = '';
     $return->start_date = get_post_meta($ticket_id, '_ticket_start_date', true);
     $return->end_date = get_post_meta($ticket_id, '_ticket_end_date', true);
     $return->manage_stock('yes' === get_post_meta($ticket_id, '_manage_stock', true));
     $return->stock(get_post_meta($ticket_id, '_stock', true) - $qty);
     $return->qty_sold($qty);
     return $return;
 }
Beispiel #6
0
 /**
  * Gets the "tickets sold" message for a given ticket
  *
  * @param Tribe__Tickets__Ticket_Object $ticket Ticket to analyze
  *
  * @return string
  */
 function tribe_tickets_get_ticket_stock_message(Tribe__Tickets__Ticket_Object $ticket)
 {
     $stock = $ticket->stock();
     $sold = $ticket->qty_sold();
     $cancelled = $ticket->qty_cancelled();
     $pending = $ticket->qty_pending();
     $event = Tribe__Tickets__Tickets::find_matching_event($ticket);
     $global_stock = new Tribe__Tickets__Global_Stock($event->ID);
     $is_global = Tribe__Tickets__Global_Stock::GLOBAL_STOCK_MODE === $ticket->global_stock_mode();
     $is_capped = Tribe__Tickets__Global_Stock::CAPPED_STOCK_MODE === $ticket->global_stock_mode();
     $stock_cap = $ticket->global_stock_cap();
     // If ticket sales are capped, do not suggest that more than the cap amount are available
     if ($is_capped && $stock > $stock_cap) {
         $stock = $stock_cap;
     }
     // If it is a global-stock ticket but the global stock level has not yet been set for the event
     // then return something better than just '0' as the available stock
     if ($is_global && 0 === $stock && !$global_stock->is_enabled()) {
         $stock = '<i>' . __('global inventory', 'event-tickets') . '</i>';
     }
     // There may not be a fixed inventory - in which case just report the number actually sold so far
     if (empty($stock) && $stock !== 0) {
         $message = sprintf(esc_html__('Sold %d', 'event-tickets'), esc_html($sold));
     } else {
         $cancelled_count = empty($cancelled) ? '' : esc_html(sprintf(_x(' cancelled: %1$d', 'ticket stock message (cancelled stock)', 'event-tickets'), (int) $cancelled));
         $pending_count = $pending < 1 ? '' : esc_html(sprintf(__(' pending: %1$d', 'ticket stock message (pending stock)', 'event-tickets'), (int) $pending));
         $message = sprintf(esc_html__('Sold %1$d (units remaining: %2$s%3$s%4$s)', 'event-tickets'), esc_html($sold), $stock, $cancelled_count, $pending_count);
     }
     return $message;
 }
Beispiel #7
0
 /**
  * Gets an individual ticket
  *
  * @param $event_id
  * @param $ticket_id
  *
  * @return null|Tribe__Tickets__Ticket_Object
  */
 public function get_ticket($event_id, $ticket_id)
 {
     if (class_exists('WC_Product_Simple')) {
         $product = new WC_Product_Simple($ticket_id);
     } else {
         $product = new WC_Product($ticket_id);
     }
     if (!$product) {
         return null;
     }
     $return = new Tribe__Tickets__Ticket_Object();
     $product_data = $product->get_post_data();
     $qty = get_post_meta($ticket_id, 'total_sales', true);
     $return->description = $product_data->post_excerpt;
     $return->frontend_link = get_permalink($ticket_id);
     $return->ID = $ticket_id;
     $return->name = $product->get_title();
     $return->price = $product->get_price();
     $return->regular_price = $product->get_regular_price();
     $return->on_sale = (bool) $product->is_on_sale();
     $return->provider_class = get_class($this);
     $return->admin_link = admin_url(sprintf(get_post_type_object($product_data->post_type)->_edit_link . '&action=edit', $ticket_id));
     $return->start_date = get_post_meta($ticket_id, '_ticket_start_date', true);
     $return->end_date = get_post_meta($ticket_id, '_ticket_end_date', true);
     $return->purchase_limit = get_post_meta($ticket_id, '_ticket_purchase_limit', true);
     $complete_totals = $this->count_order_items_by_status($ticket_id, 'complete');
     $pending_totals = $this->count_order_items_by_status($ticket_id, 'incomplete');
     $qty = $qty ? $qty : 0;
     $pending = $pending_totals['total'] ? $pending_totals['total'] : 0;
     // Ticket stock is a simple reflection of remaining inventory for this item...
     $stock = $product->get_stock_quantity();
     // ...With some exceptions for global stock tickets
     $stock = $this->set_stock_level_for_global_stock_tickets($stock, $event_id, $ticket_id);
     $return->manage_stock($product->managing_stock());
     $return->stock($stock);
     $return->global_stock_mode(get_post_meta($ticket_id, '_global_stock_mode', true));
     $return->global_stock_cap(get_post_meta($ticket_id, '_global_stock_cap', true));
     $return->qty_sold($qty);
     $return->qty_pending($pending);
     $return->qty_cancelled($this->get_cancelled($ticket_id));
     if (empty($return->purchase_limit) && 0 !== (int) $return->purchase_limit) {
         /**
          * Filter the default purchase limit for the ticket
          *
          * @var int
          *
          * @return int
          */
         $return->purchase_limit = apply_filters('tribe_tickets_default_purchase_limit', 0);
     }
     return apply_filters('wootickets_get_ticket', $return, $event_id, $ticket_id);
 }
Beispiel #8
0
 /**
  * Gets an individual ticket
  *
  * @param $unused_event_id
  * @param $ticket_id
  * @return null|Tribe__Tickets__Ticket_Object
  */
 public function get_ticket($unused_event_id, $ticket_id)
 {
     $product = shopp_product($ticket_id);
     if (!$product) {
         return null;
     }
     // We can't take it for granted that Shopp will have populated the product's price data
     $product->load_data(array('prices'));
     $return = new Tribe__Tickets__Ticket_Object();
     list($start_date, $end_date) = $this->ticket_sale_dates($ticket_id);
     $return->description = $product->description;
     $return->frontend_link = get_permalink($ticket_id);
     $return->ID = $ticket_id;
     $return->name = $product->name;
     $return->on_sale = Shopp::str_true($product->sale);
     $return->price = $return->on_sale ? $this->get_sale_price($product) : $this->get_single_price($product);
     $return->regular_price = $this->get_single_price($product);
     $return->provider_class = get_class($this);
     $return->admin_link = admin_url(sprintf(get_post_type_object(Product::$posttype)->_edit_link . '&action=edit', $ticket_id));
     $return->start_date = empty($start_date) ? '' : $start_date;
     $return->end_date = empty($end_date) ? '' : $end_date;
     $sold = (int) $product->sold;
     $pending = $product->sold ? $this->count_incomplete_order_items($ticket_id) : 0;
     $return->manage_stock('off' !== $product->inventory);
     $return->stock('off' === $product->inventory ? Tribe__Tickets__Ticket_Object::UNLIMITED_STOCK : $product->stock - $sold);
     $return->qty_sold($sold - $pending);
     $return->qty_pending($pending);
     return $return;
 }