You are here

function uc_paypal_ec_review_form_submit in Ubercart 5

Same name and namespace in other branches
  1. 6.2 payment/uc_paypal/uc_paypal.pages.inc \uc_paypal_ec_review_form_submit()
  2. 7.3 payment/uc_paypal/uc_paypal.pages.inc \uc_paypal_ec_review_form_submit()

File

payment/uc_paypal/uc_paypal.module, line 1094
Integrates various PayPal payment services and Instant Payment Notifications (IPN) with Ubercart!

Code

function uc_paypal_ec_review_form_submit($form_id, $form_values) {
  $order = uc_order_load($_SESSION['cart_order']);
  if ($form_values['shippable'] == 'true') {
    $method_accessorials = split("---", isset($_POST['quote-option']) ? strval($_POST['quote-option']) : 0);
    $order->quote['method'] = $method_accessorials[0];
    $order->quote['accessorials'] = $method_accessorials[1];
    $order->quote['rate'] = $_POST['rate'][isset($_POST['quote-option']) ? strval($_POST['quote-option']) : 0];
    $order->quote['quote_form'] = rawurldecode($_POST['quote-form']);
    $methods = module_invoke_all('shipping_method');
    $method = $methods[$order->quote['method']];
    $label = is_null($_POST['quote-option']) ? t('Error calculating shipping') : $method['quote']['accessorials'][$order->quote['accessorials']];
    $result = db_query("SELECT line_item_id FROM {uc_order_line_items} WHERE order_id = %d AND type = 'shipping'", $order->order_id);
    if ($lid = db_result($result)) {
      uc_order_update_line_item($lid, $label, $order->quote['rate']);
    }
    else {
      uc_order_line_item_add($order->order_id, 'shipping', $label, $order->quote['rate']);
    }
  }
  if (variable_get('uc_paypal_ec_review_company', TRUE)) {
    $order->delivery_company = $form_values['delivery_company'];
  }
  if (variable_get('uc_paypal_ec_review_phone', TRUE)) {
    $order->delivery_phone = $form_values['delivery_phone'];
  }
  if (variable_get('uc_paypal_ec_review_comment', TRUE)) {
    db_query("DELETE FROM {uc_order_comments} WHERE order_id = %d", $order->order_id);
    uc_order_comment_save($order->order_id, 0, $form_values['order_comments'], 'order');
  }
  uc_order_save($order);
  drupal_goto('cart/echeckout/submit');
}