Exemple #1
0
/**
 * Displays listing package custom columns data.
 *
 * @param string $column_index
 * @param int $post_id
 *
 * @return void
 */
function cp_package_listing_add_column_data($column_index, $post_id)
{
    $package = cp_get_listing_package($post_id);
    if (!$package) {
        return;
    }
    switch ($column_index) {
        case 'description':
            echo strip_tags($package->description);
            break;
        case 'price':
            appthemes_display_price($package->price);
            break;
        case 'duration':
            printf(_n('%d day', '%d days', $package->duration, APP_TD), $package->duration);
            break;
        case 'status':
            if ($package->post_status == 'publish') {
                _e('Active', APP_TD);
            } else {
                _e('Inactive', APP_TD);
            }
            break;
    }
}
Exemple #2
0
 /**
  * Validates submitted fields.
  *
  * @param object $errors
  *
  * return object
  */
 public function validate_fields($errors)
 {
     global $cp_options;
     $errors = parent::validate_fields($errors);
     // check if ad pack is specified for fixed price option, and valid
     if ($cp_options->price_scheme == 'single' && cp_payments_is_enabled() && empty($this->posted_fields['ad_pack_id'])) {
         $errors->add('missed-ad_pack_id', __('You need to choose ad package.', APP_TD));
     } else {
         if (!empty($this->posted_fields['ad_pack_id'])) {
             $package = cp_get_listing_package($this->posted_fields['ad_pack_id']);
             if (!$package) {
                 $errors->add('invalid-ad_pack_id', __('Choosen ad package does not exist.', APP_TD));
             }
         }
     }
     return $errors;
 }
Exemple #3
0
/**
 * Calculates the ad listing fee.
 *
 * @param int $category_id
 * @param int $package_id
 * @param float $cp_price
 * @param string $price_curr
 *
 * @return float
 */
function cp_ad_listing_fee($category_id, $package_id, $cp_price, $price_curr)
{
    global $cp_options;
    // make sure we are charging for ads
    if (!cp_payments_is_enabled()) {
        return 0;
    }
    // now figure out which pricing scheme is set
    switch ($cp_options->price_scheme) {
        case 'category':
            $prices = $cp_options->price_per_cat;
            $adlistingfee = isset($prices[$category_id]) ? (double) $prices[$category_id] : 0;
            break;
        case 'percentage':
            // grab the % and then put it into a workable number
            $ad_percentage = $cp_options->percent_per_ad * 0.01;
            // calculate the ad cost. Ad listing price x percentage.
            $adlistingfee = appthemes_clean_price($cp_price, 'float') * $ad_percentage;
            // can modify listing fee. example: apply currency conversion
            $adlistingfee = apply_filters('cp_percentage_listing_fee', $adlistingfee, $cp_price, $ad_percentage, $price_curr);
            break;
        case 'featured':
            // listing price is always free in this pricing schema
            $adlistingfee = 0;
            break;
        case 'single':
        default:
            // pricing model must be single ad packs
            $listing_package = cp_get_listing_package($package_id);
            if ($listing_package) {
                $adlistingfee = $listing_package->price;
            } else {
                $adlistingfee = 0;
                //sprintf( __( 'ERROR: no ad packs found for ID %s.', APP_TD ), $package_id );
            }
            break;
    }
    // return the ad listing fee
    return $adlistingfee;
}
Exemple #4
0
/**
 * Returns duration of listing package.
 *
 * @param int $package_id
 *
 * @return int
 */
function cp_get_ad_pack_length($package_id)
{
    if (!$package_id) {
        return 0;
    }
    $listing_package = cp_get_listing_package($package_id);
    if (!$listing_package) {
        return 0;
    }
    return $listing_package->duration;
}