public function save_details_step($transaction, $errors = array()) { global $wpdb, $hasextrafieldsmodule; $data = $this->get_posted_details($_POST, $transaction); $characters = $this->get_characters_allowed($data['ad_id'], $transaction); $errors = array(); $payment_term = awpcp_payments_api()->get_transaction_payment_term($transaction); if (!$this->validate_details($data, false, $payment_term, $errors)) { return $this->details_step_form($transaction, $data, $errors); } $now = current_time('mysql'); if ($transaction->get('ad-id')) { $ad = AWPCP_Ad::find_by_id($transaction->get('ad-id')); } else { $ad = new AWPCP_Ad(); $totals = $transaction->get_totals(); $ad->adterm_id = $transaction->get('payment-term-id'); $ad->payment_term_type = $transaction->get('payment-term-type'); $ad->ad_transaction_id = $transaction->id; $ad->ad_fee_paid = $totals['money']; $ad->ad_key = AWPCP_Ad::generate_key(); $timestamp = awpcp_datetime('timestamp', $now); $payment_term = $ad->get_payment_term(); $ad->set_start_date($now); $ad->set_end_date($payment_term->calculate_end_date($timestamp)); $ad->ad_postdate = $now; $ad->disabled = true; $ad->payment_status = 'Unpaid'; } if (!$transaction->get('ad-id') || $this->verify_preview_hash($ad)) { $ad->user_id = $data['user_id']; $ad->ad_category_id = $data['ad_category']; $ad->ad_category_parent_id = get_cat_parent_ID($data['ad_category']); $ad->ad_title = $this->prepare_ad_title($data['ad_title'], $characters['characters_allowed_in_title']); $ad->ad_details = $this->prepare_ad_details($data['ad_details'], $characters['characters_allowed']); $ad->ad_contact_name = $data['ad_contact_name']; $ad->ad_contact_phone = $data['ad_contact_phone']; $ad->ad_contact_email = $data['ad_contact_email']; $ad->websiteurl = $data['websiteurl']; $ad->ad_item_price = $data['ad_item_price'] * 100; $ad->is_featured_ad = $data['is_featured_ad']; $ad->ad_last_updated = $now; $ad->posterip = awpcp_getip(); if (!$ad->save()) { $errors[] = __('There was an unexpected error trying to save your Ad details. Please try again or contact an administrator.', 'AWPCP'); return $this->details_step_form($transaction, $data, $errors); } $regions_allowed = $this->get_regions_allowed($ad->ad_id, $transaction); awpcp_basic_regions_api()->update_ad_regions($ad, $data['regions'], $regions_allowed); $transaction->set('ad-id', $ad->ad_id); do_action('awpcp-save-ad-details', $ad, $transaction); $transaction->save(); } if (awpcp_post_param('preview-hash', false)) { return $this->preview_step(); } else { if ($this->should_show_upload_files_step($ad)) { return $this->upload_images_step(); } else { if ((bool) get_awpcp_option('pay-before-place-ad')) { return $this->finish_step(); } else { if ((bool) get_awpcp_option('show-ad-preview-before-payment')) { return $this->preview_step(); } else { return $this->checkout_step(); } } } } }
/** * @since 3.0.0 */ public function get_access_key() { if (empty($this->ad_key)) { $this->ad_key = AWPCP_Ad::generate_key(); $this->save(); } return $this->ad_key; }