Skip to content
Browse files

Modify WPSC_Checkout_Form so that it's compatible with the new Form API.

  • Loading branch information...
1 parent 116cb89 commit d6791335e7a895b2e43c63dd7afdb744e3c5bf12 @garyc40 garyc40 committed Jun 24, 2012
Showing with 74 additions and 136 deletions.
  1. +9 −127 wpsc-includes/checkout-form.class.php
  2. +65 −9 wpsc-theme-engine/form.php
View
136 wpsc-includes/checkout-form.class.php
@@ -165,11 +165,11 @@ public function get_title() {
return isset( self::$form_titles[$this->id] ) ? self::$form_titles[$this->id] : '';
}
- public function output_fields() {
+ public function get_field_args() {
if ( is_null( $this->fields ) )
$this->get_fields();
- $output = '';
+ $fields = array();
if ( empty( $_POST['wpsc_checkout_details'] ) )
$_POST['wpsc_checkout_details'] = array();
@@ -178,8 +178,8 @@ public function output_fields() {
$id = empty( $field->unique_name ) ? $field->id : $field->unique_name;
$field_arr = array(
- 'type' => $field->type,
- 'id' => "wpsc-checkout-field-{$id}",
+ 'type' => $field->type,
+ 'id' => "wpsc-checkout-field-{$id}",
'title' => $field->name,
'name' => 'wpsc_checkout_details[' . $field->id . ']',
'value' => wpsc_submitted_value( $field->id, '', $_POST['wpsc_checkout_details'] ),
@@ -189,7 +189,7 @@ public function output_fields() {
$field_arr['type'] = 'state_dropdown';
$field_arr['country'] = 'US';
} elseif ( in_array( $field->unique_name, array( 'billingcountry', 'shippingcountry' ) ) || $field->type == 'delivery_country' ) {
- $field_arr['type'] = 'country_dropdown';
+ $field_arr['type'] = 'select_country';
} elseif ( $field->type == 'text' ) {
$field_arr['type'] = 'textfield';
} elseif ( $field->type == 'select' ) {
@@ -200,131 +200,13 @@ public function output_fields() {
} 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';
}
- $output .= sprintf( apply_filters( 'wpsc_checkout_field_before', '<p class="%s" id="%s">', $field_arr ), "wpsc-checkout-field-wrapper wpsc-checkout-field-wrapper-{$field_arr['type']}", "wpsc-checkout-field-{$id}-wrapper" );
- $output .= apply_filters( "wpsc_checkout_field_{$field_arr['type']}", '', $field_arr );
- $output .= apply_filters( 'wpsc_checkout_field_after', '</p>', $field_arr );
+ $fields[] = $field_arr;
}
- echo $output;
- }
-}
-
-function wpsc_checkout_field_label( $output, $field ) {
- extract( $field );
-
- if ( $type != 'heading' )
- $output .= wpsc_form_label( $title, $id, array( 'class' => 'wpsc-checkout-label', 'id' => $id . '-label' ), false );
-
- return $output;
-}
-add_filter( 'wpsc_checkout_field_before', 'wpsc_checkout_field_label', 20, 2 );
-
-function wpsc_checkout_field_heading( $output, $field ) {
- extract( $field );
- if ( ! isset( $class ) )
- $class = 'wpsc-checkout-heading';
-
- return esc_html( $title );
-}
-add_filter( 'wpsc_checkout_field_heading', 'wpsc_checkout_field_heading', 10, 2 );
-
-function wpsc_checkout_field_textfield( $output, $field_array ) {
- extract( $field_array );
- if ( ! isset( $class ) )
- $class = 'wpsc-checkout-textfield';
-
- if ( $type !== 'textfield' )
- $class .= ' wpsc-checkout-' . $type;
-
- $output .= wpsc_form_input( $name, $value, array( 'id' => $id, 'class' => $class ), false );
-
- return $output;
-}
-add_filter( 'wpsc_checkout_field_address', 'wpsc_checkout_field_textfield', 10, 2 );
-add_filter( 'wpsc_checkout_field_city', 'wpsc_checkout_field_textfield', 10, 2 );
-add_filter( 'wpsc_checkout_field_email', 'wpsc_checkout_field_textfield', 10, 2 );
-add_filter( 'wpsc_checkout_field_textfield', 'wpsc_checkout_field_textfield', 10, 2 );
-
-function wpsc_checkout_field_country_dropdown( $output, $field_array ) {
- extract( $field_array );
- if ( ! isset( $class ) )
- $class = 'wpsc-checkout-country-dropdown';
-
- $country_data = WPSC_Country::get_all();
- $options = array();
- foreach ( $country_data as $country ) {
- $options[$country->isocode] = $country->country;
- }
-
- $output .= wpsc_form_select( $name, $value, $options, array( 'id' => $id, 'class' => $class ), false );
-
- return $output;
-}
-add_filter( 'wpsc_checkout_field_country_dropdown', 'wpsc_checkout_field_country_dropdown', 10, 2 );
-
-function wpsc_checkout_field_state_dropdown( $output, $field_array ) {
- global $wpdb;
-
- extract( $field_array );
- if ( ! isset( $class ) )
- $class = 'wpsc-checkout-state-dropdown';
-
- $state_data = $wpdb->get_results( $wpdb->prepare( "SELECT `regions`.* FROM `" . WPSC_TABLE_REGION_TAX . "` AS `regions` INNER JOIN `" . WPSC_TABLE_CURRENCY_LIST . "` AS `country` ON `country`.`id` = `regions`.`country_id` WHERE `country`.`isocode` IN(%s)", $country ) );
- $options = array();
- foreach ( $state_data as $state ) {
- $options[$state->id] = $state->name;
+ return $fields;
}
-
- $output .= wpsc_form_select( $name, $value, $options, array( 'id' => $id, 'class' => $class ), false );
-
- return $output;
-}
-add_filter( 'wpsc_checkout_field_state_dropdown', 'wpsc_checkout_field_state_dropdown', 10, 2 );
-
-function wpsc_checkout_field_textarea( $output, $field_array ) {
- extract( $field_array );
- if ( ! isset( $class ) )
- $class = 'wpsc-checkout-textarea';
-
- $output .= wpsc_form_textarea( $name, $value, array( 'id' => $id, 'class' => $class ), false );
-
- return $output;
-}
-add_filter( 'wpsc_checkout_field_textarea', 'wpsc_checkout_field_textarea', 10, 2 );
-
-function wpsc_checkout_field_select( $output, $field_array ) {
- extract( $field_array );
- if ( ! isset( $class ) )
- $class = 'wpsc-checkout-select';
-
- $output .= wpsc_form_select( $name, $value, $options, array( 'id' => $id, 'class' => $class ), false );
-
- return $output;
-}
-add_filter( 'wpsc_checkout_field_select', 'wpsc_checkout_field_select', 10, 2 );
-
-function wpsc_checkout_field_radios( $output, $field_array ) {
- extract( $field_array );
-
- if ( ! isset( $class ) )
- $class = 'wpsc-checkout-radios wpsc-checkout-radio';
-
- $output .= wpsc_form_radios( $name, $value, $options, array( 'id' => $id, 'class' => $class ), false );
-
- return $output;
-}
-add_filter( 'wpsc_checkout_field_radios', 'wpsc_checkout_field_radios', 10, 2 );
-
-function wpsc_checkout_field_checkboxes( $output, $field_array ) {
- extract( $field_array );
-
- if ( ! isset( $class ) )
- $class = 'wpsc-checkout-checkboxes wpsc-checkout-checkbox';
-
- $output .= wpsc_form_checkboxes( $name, $value, $options, array( 'id' => $id, 'class' => $class ), false );
-
- return $output;
}
-add_filter( 'wpsc_checkout_field_checkboxes', 'wpsc_checkout_field_checkboxes', 10, 2 );
View
74 wpsc-theme-engine/form.php
@@ -120,15 +120,20 @@ function wpsc_display_form( $args ) {
echo wpsc_get_form_output( $args );
}
-add_filter( 'wpsc_control_before' , '_wpsc_filter_control_before' , 10, 3 );
-add_filter( 'wpsc_control_after' , '_wpsc_filter_control_after' , 15, 3 );
-add_filter( 'wpsc_control_textfield', '_wpsc_filter_control_textfield', 10, 3 );
-add_filter( 'wpsc_control_password' , '_wpsc_filter_control_password' , 10, 3 );
-add_filter( 'wpsc_control_select' , '_wpsc_filter_control_select' , 10, 3 );
-add_filter( 'wpsc_control_submit' , '_wpsc_filter_control_submit' , 10, 3 );
-add_filter( 'wpsc_control_hidden' , '_wpsc_filter_control_hidden' , 10, 3 );
-add_filter( 'wpsc_control_button' , '_wpsc_filter_control_button' , 10, 3 );
-add_filter( 'wpsc_control_checkbox' , '_wpsc_filter_control_checkbox' , 10, 3 );
+add_filter( 'wpsc_control_before' , '_wpsc_filter_control_before' , 10, 3 );
+add_filter( 'wpsc_control_after' , '_wpsc_filter_control_after' , 15, 3 );
+add_filter( 'wpsc_control_textfield' , '_wpsc_filter_control_textfield', 10, 3 );
+add_filter( 'wpsc_control_password' , '_wpsc_filter_control_password' , 10, 3 );
+add_filter( 'wpsc_control_select' , '_wpsc_filter_control_select' , 10, 3 );
+add_filter( 'wpsc_control_select_country' , '_wpsc_filter_control_select_country' , 10, 3 );
+add_filter( 'wpsc_control_select_region' , '_wpsc_filter_control_select_region' , 10, 3 );
+add_filter( 'wpsc_control_submit' , '_wpsc_filter_control_submit' , 10, 3 );
+add_filter( 'wpsc_control_hidden' , '_wpsc_filter_control_hidden' , 10, 3 );
+add_filter( 'wpsc_control_button' , '_wpsc_filter_control_button' , 10, 3 );
+add_filter( 'wpsc_control_checkbox' , '_wpsc_filter_control_checkbox' , 10, 3 );
+add_filter( 'wpsc_control_radio' , '_wpsc_filter_control_radio' , 10, 3 );
+add_filter( 'wpsc_control_checkboxes' , '_wpsc_filter_control_checkboxes', 10, 3 );
+add_filter( 'wpsc_control_radios' , '_wpsc_filter_control_radios' , 10, 3 );
add_filter( 'wpsc_action_field_submit', '_wpsc_filter_control_submit', 10, 3 );
add_filter( 'wpsc_action_field_hidden', '_wpsc_filter_control_hidden', 10, 3 );
@@ -182,6 +187,34 @@ function _wpsc_filter_control_select( $output, $field, $args ) {
return $output;
}
+function wpsc_checkout_field_country_dropdown( $output, $field, $args ) {
+ extract( $field );
+
+ $country_data = WPSC_Country::get_all();
+ $options = array();
+ foreach ( $country_data as $country ) {
+ $options[$country->isocode] = $country->country;
+ }
+
+ $output .= wpsc_form_select( $name, $value, $options, array( 'id' => $id . '-control' ), false );
+ return $output;
+}
+
+function wpsc_checkout_field_select_region( $output, $field, $args ) {
+ global $wpdb;
+
+ extract( $field );
+
+ $state_data = $wpdb->get_results( $wpdb->prepare( "SELECT `regions`.* FROM `" . WPSC_TABLE_REGION_TAX . "` AS `regions` INNER JOIN `" . WPSC_TABLE_CURRENCY_LIST . "` AS `country` ON `country`.`id` = `regions`.`country_id` WHERE `country`.`isocode` IN(%s)", $country ) );
+ $options = array();
+ foreach ( $state_data as $state ) {
+ $options[$state->id] = $state->name;
+ }
+
+ $output .= wpsc_form_select( $name, $value, $options, array( 'id' => $id . '-control' ), false );
+ return $output;
+}
+
function _wpsc_filter_control_submit( $output, $field, $args ) {
extract( $field );
@@ -224,4 +257,27 @@ function _wpsc_filter_control_checkbox( $output, $field, $args ) {
$checked = false;
$output .= wpsc_form_checkbox( $name, $value, $title, $checked, array( 'id' => $id . '-control' ), false );
return $output;
+}
+
+function _wpsc_filter_control_radio( $output, $field, $args ) {
+ extract( $field );
+ if ( ! isset( $checked ) )
+ $checked = false;
+ $output .= wpsc_form_radio( $name, $value, $title, $checked, array( 'id' => $id . '-control' ), false );
+ return $output;
+}
+
+function _wpsc_filter_control_checkboxes( $output, $field, $args ) {
+ extract( $field );
+ if ( ! isset( $value ) )
+ $value = '';
+ $output .= wpsc_form_checkboxes( $name, $value, $options, array( 'id' => $id . '-control' ), false );
+ return $output;
+}
+
+function _wpsc_filter_control_radios( $output, $field, $args ) {
+ extract( $field );
+ if ( ! isset( $value ) )
+ $value = '';
+ $output .= wpsc_form_radios( $name, $value, $options, array( 'id' => $id . '-control' ), false );
}

0 comments on commit d679133

Please sign in to comment.
Something went wrong with that request. Please try again.