Пример #1
0
 if (isset($postvals['cp_currency']) && !empty($postvals['cp_currency'])) {
     $price_curr = $postvals['cp_currency'];
 } else {
     $price_curr = $cp_options->curr_symbol;
 }
 // keep only values and insert/strip commas if needed
 if (!empty($_POST['tags_input'])) {
     $postvals['tags_input'] = appthemes_clean_tags($_POST['tags_input']);
     $_POST['tags_input'] = $postvals['tags_input'];
 }
 // store the user IP address, ID for later
 $postvals['cp_sys_userIP'] = appthemes_get_ip();
 $postvals['user_id'] = $current_user->ID;
 $ad_pack_id = isset($_POST['ad_pack_id']) ? appthemes_numbers_only($_POST['ad_pack_id']) : false;
 if ($ad_pack_id) {
     $postvals['pack_duration'] = cp_get_ad_pack_length($ad_pack_id);
 }
 $coupon = false;
 if (cp_payments_is_enabled()) {
     // see if the featured ad checkbox has been checked
     if (isset($_POST['featured_ad'])) {
         $postvals['featured_ad'] = $_POST['featured_ad'];
         // get the featured ad price into the array
         $postvals['cp_sys_feat_price'] = $cp_options->sys_feat_price;
     }
     // calculate the ad listing fee and put into a variable
     $postvals['cp_sys_ad_listing_fee'] = cp_ad_listing_fee($_POST['cat'], $ad_pack_id, $postvals['cp_price'], $price_curr);
     // calculate the total cost of the ad
     if (isset($postvals['cp_sys_feat_price'])) {
         $postvals['cp_sys_total_ad_cost'] = cp_calc_ad_cost($_POST['cat'], $ad_pack_id, $postvals['cp_sys_feat_price'], $postvals['cp_price'], $coupon, $price_curr);
     } else {
Пример #2
0
 /**
  * Sets listing internal data.
  *
  * return void
  */
 protected function set_internal_data()
 {
     global $cp_options, $current_user;
     $listing = $this->get_listing_obj();
     // add items needed for function that displays listing preview
     $this->posted_fields['fid'] = $this->form_id;
     $this->posted_fields['cat'] = $this->category_id;
     // set listing unique id
     if ($unique_id = get_post_meta($listing->ID, 'cp_sys_ad_conf_id', true)) {
         $this->posted_fields['cp_sys_ad_conf_id'] = $unique_id;
     } else {
         $this->posted_fields['cp_sys_ad_conf_id'] = cp_generate_id();
     }
     // set user IP
     $this->posted_fields['cp_sys_userIP'] = appthemes_get_ip();
     // set listing duration
     if ($this->posted_fields['ad_pack_id']) {
         $this->posted_fields['cp_sys_ad_duration'] = cp_get_ad_pack_length($this->posted_fields['ad_pack_id']);
     } else {
         $this->posted_fields['cp_sys_ad_duration'] = $cp_options->prun_period;
     }
     $listing_price_currency = !empty($this->posted_fields['cp_currency']) ? $this->posted_fields['cp_currency'] : $cp_options->curr_symbol;
     $coupon = false;
     // legacy coupon value
     if (cp_payments_is_enabled()) {
         // see if the featured ad checkbox has been checked
         if (!empty($this->posted_fields['featured_ad'])) {
             $this->posted_fields['featured_ad'] = 1;
             // save featured ad price
             $this->posted_fields['cp_sys_feat_price'] = $cp_options->sys_feat_price;
         }
         // calculate the ad listing fee and put into a variable
         $this->posted_fields['cp_sys_ad_listing_fee'] = cp_ad_listing_fee($this->category_id, $this->posted_fields['ad_pack_id'], $this->posted_fields['cp_price'], $listing_price_currency);
         $featured_price = isset($this->posted_fields['cp_sys_feat_price']) ? $this->posted_fields['cp_sys_feat_price'] : 0;
         $this->posted_fields['cp_sys_total_ad_cost'] = cp_calc_ad_cost($this->category_id, $this->posted_fields['ad_pack_id'], $featured_price, $this->posted_fields['cp_price'], $coupon, $listing_price_currency);
         $this->posted_fields['cp_sys_total_ad_cost_no_benefit'] = $this->posted_fields['cp_sys_total_ad_cost'];
         // apply membership benefit
         if ($cp_options->enable_membership_packs && ($membership = cp_get_user_membership_package($current_user->ID))) {
             $this->posted_fields['membership_pack'] = $membership->ID;
             // update the total cost based on the membership pack ID and current total cost
             $this->posted_fields['cp_sys_total_ad_cost'] = cp_calculate_membership_package_benefit($membership->ID, $this->posted_fields['cp_sys_total_ad_cost']);
             // add featured cost to static pack type
             if ($featured_price && $membership->pack_type == 'static') {
                 $this->posted_fields['cp_sys_total_ad_cost'] += $featured_price;
             }
         }
     }
     // prevent from minus prices if bigger discount applied
     if (!isset($this->posted_fields['cp_sys_total_ad_cost']) || $this->posted_fields['cp_sys_total_ad_cost'] < 0) {
         $this->posted_fields['cp_sys_total_ad_cost'] = 0;
     }
 }