/**
  * Decreases customer purchase stats
  *
  * @access	public
  * @since	1.0
  */
 public function decrease_stats($customer_id = 0, $amount = 0.0)
 {
     $customer = new KBS_Customer($customer_id);
     if (!$customer) {
         return false;
     }
     $decreased_count = $customer->decrease_purchase_count();
     return $decreased_count && $decreased_value ? true : false;
 }
Пример #2
0
 /**
  * Once items have been set, an update is needed to save them to the database.
  *
  * @since	1.0
  * @return	bool	True of the save occurred, false if it failed or wasn't needed
  */
 public function save()
 {
     $saved = false;
     if (empty($this->ID)) {
         $ticket_id = $this->insert_ticket();
         if (false === $ticket_id) {
             $saved = false;
         } else {
             $this->ID = $ticket_id;
         }
     }
     if ($this->ID !== $this->_ID) {
         $this->ID = $this->_ID;
     }
     // If we have something pending, let's save it
     if (!empty($this->pending)) {
         foreach ($this->pending as $key => $value) {
             switch ($key) {
                 case 'status':
                     $this->update_status($this->status);
                     break;
                 case 'ip':
                     $this->update_meta('_kbs_ticket_user_ip', $this->ip);
                     break;
                 case 'customer_id':
                     $this->update_meta('_kbs_ticket_customer_id', $this->customer_id);
                     break;
                 case 'user_id':
                     $this->update_meta('_kbs_ticket_user_id', $this->user_id);
                     break;
                 case 'first_name':
                     $this->user_info['first_name'] = $this->first_name;
                     break;
                 case 'last_name':
                     $this->user_info['last_name'] = $this->last_name;
                     break;
                 case 'email':
                     $this->update_meta('_kbs_ticket_user_email', $this->email);
                     break;
                 case 'key':
                     $this->update_meta('_kbs_ticket_key', $this->key);
                     break;
                 case 'form_data':
                     foreach ($this->form_data as $form_key => $form_value) {
                         $this->update_meta('_kbs_ticket_form_' . $form_key, $form_value);
                     }
                     break;
                 case 'date':
                     $args = array('ID' => $this->ID, 'post_date' => $this->date, 'edit_date' => true);
                     wp_update_post($args);
                     break;
                 case 'ticket_title':
                     $args = array('ID' => $this->ID, 'post_title' => $this->ticket_title);
                     wp_update_post($args);
                     break;
                 case 'ticket_content':
                     $args = array('ID' => $this->ID, 'post_content' => $this->ticket_content);
                     wp_update_post($args);
                     break;
                 case 'resolved_date':
                     $this->update_meta('_kbs_ticket_resolved_date', $this->resolved_date);
                     break;
                 case 'files':
                     $this->files = $this->attach_files();
                     break;
                 case 'sla':
                     $this->update_meta('_kbs_ticket_sla', $this->sla);
                     break;
                 default:
                     do_action('kbs_ticket_save', $this, $key);
                     break;
             }
         }
         $customer = new KBS_Customer($this->customer_id);
         // Increase the customer's ticket stats
         $customer->increase_ticket_count();
         $new_meta = array('agent' => $this->agent, 'source' => $this->source, 'sla' => $this->sla, 'user_info' => is_array($this->user_info) ? $this->user_info : array(), 'user_ip' => $this->ip, 'resolved' => $this->resolved_date, 'files' => $this->files);
         // Do some merging of user_info before we merge it all
         if (!empty($this->ticket_meta['user_info'])) {
             $new_meta['user_info'] = array_replace_recursive($new_meta['user_info'], $this->ticket_meta['user_info']);
         }
         $meta = $this->get_meta();
         if (empty($meta)) {
             $meta = array();
         }
         $merged_meta = array_merge($meta, $new_meta);
         // Only save the ticket meta if it's changed
         if (md5(serialize($meta)) !== md5(serialize($merged_meta))) {
             $updated = $this->update_meta('_ticket_data', $merged_meta);
             if (false !== $updated) {
                 $saved = true;
             }
         }
         $this->pending = array();
         $saved = true;
     }
     if (true === $saved) {
         $this->setup_ticket($this->ID);
     }
     return $saved;
 }