private function save_shipping_and_billing_info() { global $wpsc_cart; // see if an existing purchase log has been set for this user // otherwise create one $purchase_log_id = (int) wpsc_get_customer_meta('current_purchase_log_id'); if ($purchase_log_id) { $purchase_log = new WPSC_Purchase_Log($purchase_log_id); } else { $purchase_log = new WPSC_Purchase_Log(); } $sessionid = mt_rand(100, 999) . time(); wpsc_update_customer_meta('checkout_session_id', $sessionid); $purchase_log->set(array('user_ID' => wpsc_get_current_customer_id(), 'date' => time(), 'plugin_version' => WPSC_VERSION, 'statusno' => '0', 'sessionid' => $sessionid)); $form = WPSC_Checkout_Form::get(); $fields = $form->get_fields(); foreach ($fields as $field) { if (!array_key_exists($field->id, $_POST['wpsc_checkout_details'])) { continue; } $value = $_POST['wpsc_checkout_details'][$field->id]; switch ($field->unique_name) { case 'billingstate': wpsc_update_customer_meta('billing_region', $value); $purchase_log->set('billing_region', $value); break; case 'shippingstate': wpsc_update_customer_meta('shipping_region', $value); $purchase_log->set('shipping_region', $value); break; case 'billingcountry': wpsc_update_customer_meta('billing_country', $value); $purchase_log->set('billing_country', $value); break; case 'shippingcountry': wpsc_update_customer_meta('shipping_country', $value); $purchase_log->set('shipping_region', $value); break; case 'shippingpostcode': wpsc_update_customer_meta('shipping_zip', $value); break; } } _wpsc_update_location(); if (wpsc_is_tax_included()) { $tax = $wpsc_cart->calculate_total_tax(); $tax_percentage = $wpsc_cart->tax_percentage; } else { $tax = 0; $tax_percentage = 0; } $purchase_log->set(array('wpec_taxes_total' => $tax, 'wpec_taxes_rate' => $tax_percentage)); $purchase_log->save(); $wpsc_cart->log_id = $purchase_log->get('id'); wpsc_update_customer_meta('current_purchase_log_id', $purchase_log->get('id')); $this->save_form($purchase_log, $fields); $this->init_shipping_calculator(); if (wpsc_uses_shipping() && !$this->shipping_calculator->has_quotes) { $this->message_collection->add(__('Sorry but we cannot ship products to your submitted address. Please either provide another shipping address or contact the store administrator about product availability to your location.', 'wpsc'), 'error'); return; } $this->wizard->completed_step('shipping-and-billing'); wp_redirect(wpsc_get_checkout_url($this->wizard->pending_step)); exit; }
public function save_shipping_and_billing_info() { global $wpsc_cart; $purchase_log = $this->get_purchase_log(); $sessionid = mt_rand(100, 999) . time(); wpsc_update_customer_meta('checkout_session_id', $sessionid); $purchase_log->set(array('user_ID' => get_current_user_id(), 'date' => time(), 'plugin_version' => WPSC_VERSION, 'statusno' => '0', 'sessionid' => $sessionid)); $form = WPSC_Checkout_Form::get(); $fields = $form->get_fields(); foreach ($fields as $field) { if (!array_key_exists($field->id, $_POST['wpsc_checkout_details'])) { continue; } $value = $_POST['wpsc_checkout_details'][$field->id]; switch ($field->unique_name) { case 'billingstate': wpsc_update_customer_meta('billing_region', $value); $purchase_log->set('billing_region', $value); break; case 'shippingstate': wpsc_update_customer_meta('shipping_region', $value); $purchase_log->set('shipping_region', $value); break; case 'billingcountry': wpsc_update_customer_meta('billing_country', $value); $purchase_log->set('billing_country', $value); break; case 'shippingcountry': wpsc_update_customer_meta('shipping_country', $value); $purchase_log->set('shipping_region', $value); break; case 'shippingpostcode': wpsc_update_customer_meta('shipping_zip', $value); break; } } _wpsc_update_location(); //keep track of tax if taxes are exclusive $wpec_taxes_controller = new wpec_taxes_controller(); if (!$wpec_taxes_controller->wpec_taxes_isincluded()) { $tax = $wpsc_cart->calculate_total_tax(); $tax_percentage = $wpsc_cart->tax_percentage; } else { $tax = 0.0; $tax_percentage = 0.0; } $purchase_log->set(array('wpec_taxes_total' => $tax, 'wpec_taxes_rate' => $tax_percentage)); $purchase_log->save(); //Check to ensure purchase log row was inserted successfully if (is_null($purchase_log->get('id'))) { $this->message_collection->add(__('A database error occured while processing your request.', 'wp-e-commerce'), 'error'); return; } $wpsc_cart->log_id = $purchase_log->get('id'); wpsc_update_customer_meta('current_purchase_log_id', $purchase_log->get('id')); WPSC_Checkout_Form_Data::save_form($purchase_log, $fields); $this->init_shipping_calculator(); if (wpsc_uses_shipping() && !$this->shipping_calculator->has_quotes) { $this->message_collection->add(__('Sorry, but we cannot ship products to your submitted address. Please either provide another shipping address or contact the store administrator about product availability to your location.', 'wp-e-commerce'), 'error'); return; } $this->wizard->completed_step('shipping-and-billing'); $url = add_query_arg($_GET, wpsc_get_checkout_url($this->wizard->pending_step)); wp_redirect($url); exit; }
private function save_customer_settings() { $form = WPSC_Checkout_Form::get(); $fields = $form->get_fields(); $customer_details = wpsc_get_customer_meta('checkout_details'); if (!is_array($customer_details)) { $customer_details = array(); } foreach ($fields as $field) { if (!array_key_exists($field->id, $_POST['wpsc_checkout_details'])) { continue; } $value = $_POST['wpsc_checkout_details'][$field->id]; $customer_details[$field->id] = $value; switch ($field->unique_name) { case 'billingstate': wpsc_update_customer_meta('billing_region', $value); break; case 'shippingstate': wpsc_update_customer_meta('shipping_region', $value); break; case 'billingcountry': wpsc_update_customer_meta('billing_country', $value); break; case 'shippingcountry': wpsc_update_customer_meta('shipping_country', $value); break; case 'shippingpostcode': wpsc_update_customer_meta('shipping_zip', $value); break; } } _wpsc_update_location(); wpsc_save_customer_details($customer_details); }