private function order($id) { $this->view = 'customer-account-order'; $form_data_obj = new WPSC_Checkout_Form_Data($id); $this->form = WPSC_Checkout_Form::get(); $this->log = new WPSC_Purchase_Log($id); $this->title = sprintf(__('View Order #%d', 'wpsc'), $id); foreach ($form_data_obj->get_raw_data() as $data) { $this->form_data[(int) $data->id] = $this->process_checkout_form_value($data); } require_once WPSC_TE_V2_CLASSES_PATH . '/cart-item-table-order.php'; $this->cart_item_table = new WPSC_Cart_Item_Table_Order($id); }
function _wpsc_convert_checkout_form_fields($customer_settings = false) { $form = WPSC_Checkout_Form::get(); $fields = $form->get_fields(); $args = array(); $purchase_log_exists = false; if (!$customer_settings) { $purchase_log_id = wpsc_get_customer_meta('current_purchase_log_id'); $purchase_log_exists = (bool) $purchase_log_id; if ($purchase_log_exists) { $form_data_obj = new WPSC_Checkout_Form_Data($purchase_log_id); $form_raw_data = $form_data_obj->get_raw_data(); $form_data = array(); foreach ($form_raw_data as $data) { $form_data[$data->id] = $data; } } } $i = 0; $state_country_pairs = array('billing_state' => array(), 'shipping_state' => array()); $customer_details = wpsc_get_customer_meta('checkout_details'); if (!is_array($customer_details)) { $customer_details = array(); } foreach ($fields as $field) { $id = empty($field->unique_name) ? $field->id : $field->unique_name; $default_value = array_key_exists($field->id, $customer_details) ? $customer_details[$field->id] : ''; if ($purchase_log_exists && $field->type != 'heading' && isset($form_data[$field->id])) { $default_value = $form_data[$field->id]->value; } $field_arr = array('type' => $field->type, 'id' => "wpsc-checkout-field-{$id}", 'title' => esc_html($field->name), 'name' => 'wpsc_checkout_details[' . $field->id . ']', 'value' => wpsc_submitted_value($field->id, $default_value, $_POST['wpsc_checkout_details'])); $validation_rules = array('trim'); if ($field->mandatory) { $validation_rules[] = 'required'; } $optional_state_field = false; if (in_array($field->unique_name, array('billingstate', 'shippingstate'))) { $field_arr['type'] = 'select_region'; /* output states for all countries just in case Javascript doesn't work */ $field_arr['country'] = 'all'; if ($field->unique_name == 'billingstate') { $state_country_pairs['billing_state']['key'] = $i; } else { $state_country_pairs['shipping_state']['key'] = $i; } // optional text field in case the country they select do not have states // and JS is disabled either by preferences or on error $optional_state_field = true; // convert state values in text into proper ID $validation_rules[] = '_wpsc_convert_state'; } elseif (in_array($field->unique_name, array('billingcountry', 'shippingcountry')) || $field->type == 'delivery_country') { $field_arr['type'] = 'select_country'; $validation_rules[] = 'country'; if ($field->unique_name == 'billingcountry') { $state_country_pairs['billing_state']['country_field_id'] = $field->id; } else { $state_country_pairs['shipping_state']['country_field_id'] = $field->id; } } elseif ($field->type == 'text') { $field_arr['type'] = 'textfield'; } elseif ($field->type == 'select') { $field_arr['options'] = array_flip(unserialize($field->options)); } elseif ($field->type == 'radio') { $field_arr['type'] = 'radios'; $field_arr['options'] = array_flip(unserialize($field->options)); } elseif ($field->type == 'checkbox') { $field_arr['type'] = 'checkboxes'; $field_arr['options'] = array_flip(unserialize($field->options)); } elseif (in_array($field->type, array('address', 'city', 'email'))) { $field_arr['type'] = 'textfield'; if ($field->type == 'email') { $validation_rules[] = 'email'; } } elseif ($field->type == 'heading' && $field->unique_name == 'delivertoafriend') { $field_arr['shipping_heading'] = true; } $field_arr['rules'] = implode('|', $validation_rules); $args[$i] = $field_arr; $i++; if ($optional_state_field) { $args[$i] = $args[$i - 1]; $args[$i]['type'] = 'textfield'; $args[$i]['id'] = 'wpsc-checkout-field-' . $id . '-text'; $i++; } } if (wpsc_has_tnc() && !$customer_settings) { $args[] = array('type' => 'checkbox', 'id' => 'wpsc-terms-and-conditions', 'title' => sprintf(__("I agree to the <a class='thickbox' target='_blank' href='%s' class='termsandconds'>Terms and Conditions</a>", "wpsc"), esc_url(site_url("?termsandconds=true&width=360&height=400"))), 'value' => 1, 'name' => 'wpsc_terms_conditions', 'rules' => 'required', 'checked' => wpsc_submitted_value('wpsc_terms_conditions', 0) == 1); } foreach ($state_country_pairs as $field) { $args[$field['key']]['rules'] .= '|state_of[' . $field['country_field_id'] . ']'; $args[$field['key']]['rules'] = ltrim($args[$field['key']]['rules'], '|'); } return $args; }
public function get_raw_message() { global $wpdb; $form_data = new WPSC_Checkout_Form_Data($this->purchase_log->get('id')); $raw_data = $form_data->get_raw_data(); $args = $this->get_common_args(); $data = array('billing' => array('title' => __('Billing Details', 'wp-e-commerce'), 'fields' => array()), 'shipping' => array('title' => __('Shipping Details', 'wp-e-commerce'), 'fields' => array()), 'misc' => array('title' => __('Other Details', 'wp-e-commerce'), 'fields' => array())); foreach ($raw_data as $field) { if (strpos($field->unique_name, 'billing') !== false) { $type = 'billing'; } elseif (strpos($field->unique_name, 'shipping') !== false) { $type = 'shipping'; } else { $type = 'misc'; } $data[$type]['fields'][] = $field; } // Transaction details $message = '<strong>' . __('Transaction Details', 'wp-e-commerce') . "</strong>\r\n"; $message .= __('Sale Log ID', 'wp-e-commerce') . ': %purchase_id%' . "\r\n"; if (!empty($args['transaction_id'])) { $message .= __('Transaction ID', 'wp-e-commerce') . ': %transaction_id%' . "\r\n"; } // Discount if (!empty($args['coupon_code'])) { $message .= __('Coupon Code', 'wp-e-commerce') . ': %coupon_code%' . "\r\n"; $message .= __('Discount Value', 'wp-e-commerce') . ': %discount%' . "\r\n"; } // Subtotal, tax, shipping, total $message .= __('Subtotal', 'wp-e-commerce') . ': %subtotal%' . "\r\n"; $message .= __('Tax', 'wp-e-commerce') . ': %tax%' . "\r\n"; $message .= __('Shipping', 'wp-e-commerce') . ': %shipping%' . "\r\n"; $message .= __('Total', 'wp-e-commerce') . ': %total%' . "\r\n"; $message .= __('Payment Method', 'wp-e-commerce') . ': %payment_method%' . "\r\n"; if (!get_option('do_not_use_shipping')) { $message .= __('Shipping Method', 'wp-e-commerce') . ': %shipping_method%' . "\r\n"; $message .= __('Shipping Option', 'wp-e-commerce') . ': %shipping_option%' . "\r\n"; } $message .= "\r\n"; // Items $message .= '<strong>' . __('Items', 'wp-e-commerce') . "</strong>\r\n"; $message .= "%product_list%\r\n"; // Checkout fields $message .= "\r\n"; foreach ($data as $section) { if (empty($section['fields'])) { continue; } $message .= "<strong>{$section['title']}</strong>\r\n"; foreach ($section['fields'] as $field) { if (strpos($field->unique_name, 'state') && is_numeric($field->value)) { $field->value = wpsc_get_region($field->value); } $message .= $field->name . ' : ' . $field->value . "\r\n"; } $message .= "\r\n"; } // preserve pre-3.8.9 hooks $message = apply_filters('wpsc_transaction_result_report', $message); return apply_filters('wpsc_purchase_log_admin_notification_raw_message', $message, $this); }
function _wpsc_convert_checkout_form_fields($customer_settings = false) { $form = WPSC_Checkout_Form::get(); $fields = $form->get_fields(); if (empty($fields)) { return array(); } $args = array(); $purchase_log_exists = false; $fieldsets = array('billing' => array('type' => 'fieldset', 'title' => apply_filters('wpsc_checkout_billing_header_label', __('<h2>Billing & Shipping Details</h2>', 'wp-e-commerce')), 'id' => 'wpsc-checkout-form-billing', 'fields' => array()), 'shipping' => array('type' => 'fieldset', 'title' => apply_filters('wpsc_checkout_shipping_header_label', __('<h2>Shipping Details</h2>', 'wp-e-commerce')), 'id' => 'wpsc-checkout-form-shipping', 'fields' => array())); if (!$customer_settings) { $purchase_log_id = wpsc_get_customer_meta('current_purchase_log_id'); $purchase_log_exists = (bool) $purchase_log_id; if ($purchase_log_exists) { $form_data_obj = new WPSC_Checkout_Form_Data($purchase_log_id); $form_raw_data = $form_data_obj->get_raw_data(); $form_data = array(); foreach ($form_raw_data as $data) { $form_data[$data->id] = $data; } } } $i = 0; $state_country_pairs = array('billing_state' => array(), 'shipping_state' => array()); $customer_details = wpsc_get_customer_meta('checkout_details'); if (!is_array($customer_details)) { $customer_details = array(); } foreach ($fields as $field) { $id = empty($field->unique_name) ? $field->id : $field->unique_name; $is_shipping = false !== strpos($field->unique_name, 'shipping'); $is_billing = false !== strpos($field->unique_name, 'billing'); $default_value = array_key_exists($field->id, $customer_details) ? $customer_details[$field->id] : ''; /* Doing our college-best to check for one of the two original headings */ if ('heading' == $field->type && ('delivertoafriend' == $field->unique_name || '1' === $field->id)) { continue; } if ($purchase_log_exists && isset($form_data[$field->id])) { $default_value = $form_data[$field->id]->value; } if (isset($_POST['wpsc_checkout_details'])) { $_POST['wpsc_checkout_details'] = wp_unslash($_POST['wpsc_checkout_details']); } $field_arr = array('type' => $field->type, 'id' => "wpsc-checkout-field-{$id}", 'title' => esc_html($field->name), 'name' => 'wpsc_checkout_details[' . $field->id . ']', 'value' => wpsc_submitted_value($field->id, wp_unslash($default_value), $_POST['wpsc_checkout_details'])); $validation_rules = array('trim'); if ($field->mandatory) { $validation_rules[] = 'required'; } $optional_state_field = false; if (in_array($field->unique_name, array('billingstate', 'shippingstate'))) { $field_arr['type'] = 'select_region'; /* output states for all countries just in case Javascript doesn't work */ $field_arr['country'] = 'all'; if ($field->unique_name == 'billingstate') { $state_country_pairs['billing_state']['key'] = $i; } else { $state_country_pairs['shipping_state']['key'] = $i; } // optional text field in case the country they select do not have states // and JS is disabled either by preferences or on error $optional_state_field = true; // convert state values in text into proper ID $validation_rules[] = '_wpsc_convert_state'; } elseif (in_array($field->unique_name, array('billingcountry', 'shippingcountry')) || $field->type == 'delivery_country') { $field_arr['type'] = 'select_country'; $validation_rules[] = 'country'; if ($field->unique_name == 'billingcountry') { $state_country_pairs['billing_state']['country_field_id'] = $field->id; } else { $state_country_pairs['shipping_state']['country_field_id'] = $field->id; } } elseif ($field->type == 'text') { $field_arr['type'] = 'textfield'; } elseif ($field->type == 'select') { $field_arr['options'] = array_flip(unserialize($field->options)); } elseif ($field->type == 'radio') { $field_arr['type'] = 'radios'; $field_arr['options'] = array_flip(unserialize($field->options)); } elseif ($field->type == 'checkbox') { $field_arr['type'] = 'checkboxes'; $field_arr['options'] = array_flip(unserialize($field->options)); } elseif (in_array($field->type, array('address', 'city', 'email'))) { $field_arr['type'] = 'textfield'; if ($field->type == 'email') { $validation_rules[] = 'email'; } } elseif ($field->type == 'heading' && $field->unique_name == 'delivertoafriend') { $field_arr['shipping_heading'] = true; } $field_arr['rules'] = implode('|', $validation_rules); if ($is_shipping) { $fieldsets['shipping']['fields'][$i] = $field_arr; } else { if ($is_billing) { $fieldsets['billing']['fields'][$i] = $field_arr; } else { $args[$i] = $field_arr; } } $i++; if ($optional_state_field && $is_billing) { $fieldsets['billing']['fields'][$i] = $fieldsets['billing']['fields'][$i - 1]; $fieldsets['billing']['fields'][$i]['type'] = 'textfield'; $fieldsets['billing']['fields'][$i]['id'] = 'wpsc-checkout-field-' . $id . '-text'; $i++; } else { if ($optional_state_field && $is_shipping) { $fieldsets['shipping']['fields'][$i] = $fieldsets['shipping']['fields'][$i - 1]; $fieldsets['shipping']['fields'][$i]['type'] = 'textfield'; $fieldsets['shipping']['fields'][$i]['id'] = 'wpsc-checkout-field-' . $id . '-text'; } } } if (wpsc_has_tnc() && !$customer_settings) { $args[] = array('type' => 'checkbox', 'id' => 'wpsc-terms-and-conditions', 'title' => sprintf(__("I agree to the <a class='thickbox' target='_blank' href='%s' class='termsandconds'>Terms and Conditions</a>", 'wp-e-commerce'), esc_url(add_query_arg(array('termsandconds' => 'true', 'width' => 360, 'height' => 400)))), 'value' => 1, 'name' => 'wpsc_terms_conditions', 'rules' => 'required', 'checked' => wpsc_submitted_value('wpsc_terms_conditions', 0) == 1); } foreach ($state_country_pairs as $state => $field) { $is_shipping = 'shipping_state' == $state; if (isset($field['key']) && $is_shipping) { $fieldsets['shipping']['fields'][$field['key']]['rules'] .= '|state_of[' . $field['country_field_id'] . ']'; $fieldsets['shipping']['fields'][$field['key']]['rules'] = ltrim($fieldsets['shipping']['fields'][$field['key']]['rules'], '|'); } else { if (isset($field['key'])) { $fieldsets['billing']['fields'][$field['key']]['rules'] .= '|state_of[' . $field['country_field_id'] . ']'; $fieldsets['billing']['fields'][$field['key']]['rules'] = ltrim($fieldsets['billing']['fields'][$field['key']]['rules'], '|'); } } } /* Add 'shipping same as billing' box to end of billing, rather than shipping header. */ if (!empty($fieldsets['billing']['fields']) && !empty($fieldsets['shipping']['fields'])) { $checked = wpsc_get_customer_meta('wpsc_copy_billing_details'); $fieldsets['billing']['fields'][$i++] = array('type' => 'checkbox', 'id' => 'wpsc-terms-and-conditions', 'title' => apply_filters('wpsc_shipping_same_as_billing', __('Shipping address is same as billing', 'wp-e-commerce')), 'value' => 1, 'name' => 'wpsc_copy_billing_details', 'checked' => empty($checked) || '1' == $checked); } if (empty($fieldsets['billing']['fields'])) { unset($fieldsets['billing']); } if (empty($fieldsets['shipping']['fields'])) { unset($fieldsets['shipping']); } return $fieldsets + $args; }