Esempio n. 1
0
 public function order_step()
 {
     $form_errors = array();
     $transaction_errors = array();
     $pay_first = get_awpcp_option('pay-before-place-ad');
     $skip_payment_term_selection = false;
     $payments = awpcp_payments_api();
     $_payment_terms = $payments->get_payment_terms();
     // validate submitted data and set relevant transaction attributes
     if (!empty($_POST)) {
         $transaction = $this->get_transaction(true);
         if ($transaction->is_new()) {
             $payments->set_transaction_status_to_open($transaction, $transaction_errors);
         }
         $skip_payment_term_selection = $transaction->get('skip-payment-term-selection');
         $user = awpcp_post_param('user', intval($transaction->user_id));
         $category = awpcp_post_param('category', $transaction->get('category', 0));
         if ($skip_payment_term_selection) {
             $payment_terms = null;
             $term = $payments->get_transaction_payment_term($transaction);
             $payment_type = $transaction->get('payment-term-payment-type');
         } else {
             $payment_terms = new AWPCP_PaymentTermsTable($_payment_terms, $transaction->get('payment-term'));
             $term = $payment_terms->get_payment_term($payment_type, $selected);
         }
         $this->validate_order(compact('user', 'category', 'term'), $form_errors);
         if (empty($form_errors) && empty($transaction_errors)) {
             $transaction->user_id = $user;
             $transaction->set('category', $category);
             if (!$skip_payment_term_selection) {
                 $transaction->set('payment-term', $selected);
                 $transaction->set('payment-term-type', $term->type);
                 $transaction->set('payment-term-id', $term->id);
                 $transaction->set('payment-term-payment-type', $payment_type);
                 $transaction->remove_all_items();
                 $payment_terms->set_transaction_item($transaction);
                 // process transaction to grab Credit Plan information
                 $payments->set_transaction_credit_plan($transaction);
             }
         }
         // Ignore errors if category and user parameters were not sent. This
         // happens every time someone tries to place an Ad starting in the
         // Buy Subscription page.
         if ($skip_payment_term_selection && !isset($_POST['category'])) {
             unset($form_errors['category']);
         }
         if ($skip_payment_term_selection && !isset($_POST['user'])) {
             unset($form_errors['user']);
         }
         // let other parts of the plugin know a transaction is being processed
         $payments->process_transaction($transaction);
     } else {
         $transaction = null;
         $payment_terms = new AWPCP_PaymentTermsTable($_payment_terms);
         $user = wp_get_current_user()->ID;
         $category = 0;
         $term = null;
     }
     // are we done here? what next?
     if ($category > 0 && !is_null($term)) {
         if (empty($form_errors) && empty($transaction_errors)) {
             $payments->set_transaction_status_to_ready_to_checkout($transaction, $transaction_errors);
             if ($pay_first && empty($transaction_errors)) {
                 return $this->checkout_step();
             } else {
                 if (empty($transaction_errors)) {
                     return $this->details_step();
                 }
             }
         }
     }
     // display initial form and show errors, if any
     $messages = $this->messages;
     if (awpcp_current_user_is_admin()) {
         $messages[] = __("You are logged in as an administrator. Any payment steps will be skipped.", "AWPCP");
     }
     $params = array('page' => $this, 'payments' => $payments, 'table' => $payment_terms, 'transaction' => $transaction, 'skip_payment_term_selection' => $skip_payment_term_selection, 'categories' => awpcp_get_categories(), 'form' => compact('category', 'user'), 'messages' => $messages, 'form_errors' => $form_errors, 'transaction_errors' => $transaction_errors);
     $template = AWPCP_DIR . '/frontend/templates/page-place-ad-order-step.tpl.php';
     return $this->render($template, $params);
 }
Esempio n. 2
0
function awpcp_get_categories_ids()
{
    static $categories;
    if (!is_array($categories)) {
        $categories = awpcp_get_properties(awpcp_get_categories(), 'category_id');
    }
    return $categories;
}