private function fee_selection()
 {
     // Cancel renewal?
     if (isset($_POST['cancel-renewal'])) {
         $this->listing->remove_category($this->category->id, true);
         if (!$this->listing->get_categories('all')) {
             $this->listing->delete();
         }
         return wpbdp_render_msg(_x('Your renewal was successfully cancelled.', 'renewal', 'WPBDM'));
     }
     $fees = wpbdp_get_fees_for_category($this->category->id);
     if (isset($_POST['fees']) && isset($_POST['fees'][$this->category->id])) {
         $fee_id = intval($_POST['fees'][$this->category->id]);
         if ($fee = wpbdp_get_fee($fee_id)) {
             $payment = new WPBDP_Payment(array('listing_id' => $this->listing->get_id()));
             $payment->add_item('fee', $fee->amount, sprintf(_x('Fee "%s" renewal for category "%s"', 'listings', 'WPBDM'), $fee->label, wpbdp_get_term_name($this->category->id)), array('fee_id' => $fee_id, 'fee_days' => $fee->days, 'fee_images' => $fee->images), $this->category->id, $fee_id);
             $payment->save();
             $this->category->payment_id = $payment->get_id();
             return $this->checkout();
         }
     }
     return wpbdp_render('renew-listing', array('listing' => $this->listing, 'category' => $this->category, 'fees' => $fees));
 }
 public function fix_categories($charge = false)
 {
     global $wpdb;
     // Delete fee information for categories that no longer exist.
     $wpdb->query($wpdb->prepare("DELETE lf FROM {$wpdb->prefix}wpbdp_listing_fees lf WHERE lf.listing_id = %d AND lf.category_id NOT IN (SELECT tt.term_id FROM {$wpdb->term_taxonomy} tt WHERE tt.taxonomy=%s)", $this->id, WPBDP_CATEGORY_TAX));
     $terms = wp_get_post_terms($this->id, WPBDP_CATEGORY_TAX, 'fields=ids');
     // Remove listing information for categories that no longer apply to the listing.
     $removed_cats = array_diff(array_keys($this->get_categories('current')), $terms);
     if ($removed_cats) {
         $cats = implode(',', $removed_cats);
         $wpdb->query($wpdb->prepare("DELETE lf FROM {$wpdb->prefix}wpbdp_listing_fees lf WHERE lf.listing_id = %d AND lf.category_id IN ({$cats})", $this->id));
     }
     // Assign a default fee for categories without a fee.
     foreach ($terms as $category_id) {
         $category_info = $this->get_category_info($category_id);
         if ($category_info && 'pending' == $category_info->status) {
             $this->add_category($category_id, $category_info->fee, false, null, true);
         } elseif (!$category_info) {
             $fee_options = wpbdp_get_fees_for_category($category_id);
             if ($charge) {
                 $payment = new WPBDP_Payment(array('listing_id' => $this->id));
                 $payment->add_category_fee_item($category_id, $fee_options[0]);
                 $payment->set_status(WPBDP_Payment::STATUS_COMPLETED);
                 $payment->save();
             } else {
                 $this->add_category($category_id, $fee_options[0]);
             }
         }
     }
 }
 private function setup_fee_selection()
 {
     $fee_selection = array();
     foreach ($this->state->categories as $cat_id => $fee_id) {
         if ($this->state->editing) {
             $fee_selection[$cat_id] = array('fee_id' => $fee_id);
         } else {
             if ($term = get_term($cat_id, WPBDP_CATEGORY_TAX)) {
                 $options = wpbdp_get_fees_for_category($cat_id);
                 if (count($options) > 1 || $options[0]->id != 0) {
                     $fee_selection[$cat_id] = array('fee_id' => isset($_POST['fees'][$cat_id]) ? $_POST['fees'][$cat_id] : $fee_id, 'term' => $term, 'options' => $options);
                 } else {
                     $fee_selection[$cat_id] = array('fee_id' => 0, 'term' => $term, 'options' => $options);
                 }
             } else {
                 unset($this->state->categories[$cat_id]);
             }
         }
     }
     return $fee_selection;
 }
Example #4
0
 public function ajax_listing_change_fee()
 {
     global $wpdb;
     $response = new WPBDP_Ajax_Response();
     if (!current_user_can('administrator')) {
         $response->send_error();
     }
     $fee_info = $wpdb->get_row($wpdb->prepare("SELECT * FROM {$wpdb->prefix}wpbdp_listing_fees WHERE id = %d", isset($_POST['renewal']) ? $_POST['renewal'] : 0));
     if (!$fee_info) {
         $response->send_error();
     }
     $listing = WPBDP_Listing::get($fee_info->listing_id);
     $category = $listing->get_category_info($fee_info->category_id);
     if (!$listing || !$category || 'pending' == $category->status) {
         $response->send_error();
     }
     $response->add('html', wpbdp_render_page(WPBDP_PATH . 'admin/templates/listing-change-fee.tpl.php', array('category' => $category, 'listing' => $listing, 'fees' => wpbdp_get_fees_for_category($fee_info->category_id))));
     $response->send();
 }