From 5f5eb2033580acbfe0b526324bc54bc40f543c47 Mon Sep 17 00:00:00 2001 From: Mike Jolley Date: Tue, 6 Dec 2011 16:45:08 +0000 Subject: [PATCH] Sort gateways and set a default --- admin/admin-init.php | 1 + admin/admin-settings.php | 187 +++++++++++++++++++--------- assets/css/admin.css | 2 + assets/css/admin.less | 12 ++ classes/gateways/gateways.class.php | 42 ++++++- readme.txt | 1 + templates/checkout/review_order.php | 9 +- 7 files changed, 194 insertions(+), 60 deletions(-) diff --git a/admin/admin-init.php b/admin/admin-init.php index e73e099fe5f..05c8c7d3346 100644 --- a/admin/admin-init.php +++ b/admin/admin-init.php @@ -68,6 +68,7 @@ function woocommerce_admin_scripts() { wp_enqueue_script( 'woocommerce_admin' ); wp_enqueue_script('farbtastic'); wp_enqueue_script('chosen'); + wp_enqueue_script('jquery-ui-sortable'); endif; diff --git a/admin/admin-settings.php b/admin/admin-settings.php index 8edaac25d57..e7bd9dc9b15 100644 --- a/admin/admin-settings.php +++ b/admin/admin-settings.php @@ -1071,7 +1071,7 @@ function woocommerce_settings() { break; case "payment_gateways" : - $links = array( ''.__('Gateways', 'woothemes').'' ); + $links = array( ''.__('Payment Gateways', 'woothemes').'' ); foreach ($woocommerce->payment_gateways->payment_gateways() as $gateway) : $title = ( isset( $gateway->method_title ) && $gateway->method_title) ? ucwords($gateway->method_title) : ucwords($gateway->id); @@ -1079,7 +1079,55 @@ function woocommerce_settings() { endforeach; echo '

'; - + + // Gateway ordering + echo '
'; + + ?> +

+

+ + + + + + + + + + payment_gateways->payment_gateways() as $gateway ) : + + $default_gateway = get_option('woocommerce_default_gateway'); + + echo ' + + + + '; + + endforeach; + ?> + +
+ id, false).' /> + + +

'.$gateway->title.'
+ '.__('Gateway ID', 'woothemes').': '.$gateway->id.'

+
'; + + if ($gateway->enabled == 'yes') + echo 'yes'; + else + echo 'no'; + + echo '
+ '; + + // Specific gateway options foreach ( $woocommerce->payment_gateways->payment_gateways() as $gateway ) : echo '
'; $gateway->admin_options(); @@ -1101,71 +1149,96 @@ function woocommerce_settings() {
diff --git a/assets/css/admin.css b/assets/css/admin.css index 19698e3bb46..3b6557a3e1f 100644 --- a/assets/css/admin.css +++ b/assets/css/admin.css @@ -111,6 +111,8 @@ ul.recent-orders.stock_list a,ul.stock_list.stock_list a{text-decoration:none;} .woocommerce table.shippingrows td.country p.edit,.woocommerce table.taxrows td.country p.edit,.woocommerce table.shippingrows td.country .options,.woocommerce table.taxrows td.country .options{min-width:400px;} .woocommerce table.shippingrows td.country .chzn-container,.woocommerce table.taxrows td.country .chzn-container{width:100% !important;margin:9px 0 5px;}.woocommerce table.shippingrows td.country .chzn-container .chzn-drop,.woocommerce table.taxrows td.country .chzn-container .chzn-drop{width:100% !important;-webkit-box-sizing:border-box;-moz-box-sizing:border-box;box-sizing:border-box;} .woocommerce table.shippingrows td.country .chzn-container .search-field input,.woocommerce table.taxrows td.country .chzn-container .search-field input{width:150px !important;} +table.wc_gateways td{vertical-align:middle;cursor:move;}table.wc_gateways td p{margin:0 0 2px;} +table.wc_gateways .radio{text-align:center;} .woocommerce table.widefat table.coupon_rows{border:0 !important;width:100%;}.woocommerce table.widefat table.coupon_rows thead th{padding:1px;border:0;font-weight:normal;font-size:11px;color:#999;} .woocommerce table.widefat table.coupon_rows tbody td{padding:3px 3px 0 0;border:0;vertical-align:middle;}.woocommerce table.widefat table.coupon_rows tbody td input.text{width:95px;} .woocommerce table.form-table textarea.input-text{height:100%;min-width:150px;} diff --git a/assets/css/admin.less b/assets/css/admin.less index 8a808eb8b33..03a2f090138 100644 --- a/assets/css/admin.less +++ b/assets/css/admin.less @@ -647,6 +647,18 @@ ul.recent-orders, ul.stock_list { } } } +table.wc_gateways { + td { + vertical-align: middle; + cursor: move; + p { + margin: 0 0 2px; + } + } + .radio { + text-align: center; + } +} .woocommerce { diff --git a/classes/gateways/gateways.class.php b/classes/gateways/gateways.class.php index f936b9c3763..fb0441a7861 100644 --- a/classes/gateways/gateways.class.php +++ b/classes/gateways/gateways.class.php @@ -17,11 +17,29 @@ class woocommerce_payment_gateways { $load_gateways = apply_filters('woocommerce_payment_gateways', array()); - foreach ($load_gateways as $gateway) : + // Get order option + $ordering = (array) get_option('woocommerce_gateway_order'); + $order_end = 999; - $this->payment_gateways[] = &new $gateway(); + // Load gateways in order + foreach ($load_gateways as $gateway) : + + $load_gateway = &new $gateway(); + + if (isset($ordering[$load_gateway->id]) && is_numeric($ordering[$load_gateway->id])) : + // Add in position + $this->payment_gateways[$ordering[$load_gateway->id]] = $load_gateway; + else : + // Add to end of the array + $this->payment_gateways[$order_end] = $load_gateway; + $order_end++; + endif; endforeach; + + ksort($this->payment_gateways); + + add_action('woocommerce_update_options_payment_gateways', array(&$this, 'process_admin_options')); } @@ -53,4 +71,24 @@ class woocommerce_payment_gateways { return $_available_gateways; } + function process_admin_options() { + + $default_gateway = (isset($_POST['default_gateway'])) ? esc_attr($_POST['default_gateway']) : ''; + $gateway_order = (isset($_POST['gateway_order'])) ? $_POST['gateway_order'] : ''; + + $order = array(); + + if (is_array($gateway_order) && sizeof($gateway_order)>0) : + $loop = 0; + foreach ($gateway_order as $gateway_id) : + $order[$gateway_id] = $loop; + $loop++; + endforeach; + endif; + + update_option( 'woocommerce_default_gateway', $default_gateway ); + update_option( 'woocommerce_gateway_order', $order ); + + } + } \ No newline at end of file diff --git a/readme.txt b/readme.txt index a82983c3e28..971fe845cfd 100644 --- a/readme.txt +++ b/readme.txt @@ -84,6 +84,7 @@ Yes you can! Join in on our GitHub repository :) https://github.com/woothemes/wo = 1.3.1 = * Many Minor bug fixes +* Ability to re-order payment gateways and choose a default * Added a 'Shipping class' taxonomy for grouping products * Enhanced Flat Rate shipping to give a flat rate to each shipping class * Made jQuery UI optional and improved Javascript diff --git a/templates/checkout/review_order.php b/templates/checkout/review_order.php index 20e11b80fbe..f52f843b37c 100755 --- a/templates/checkout/review_order.php +++ b/templates/checkout/review_order.php @@ -118,7 +118,14 @@ $available_gateways = $woocommerce->payment_gateways->get_available_payment_gateways(); if ($available_gateways) : // Chosen Method - if (sizeof($available_gateways)) current($available_gateways)->set_current(); + if (sizeof($available_gateways)) : + $default_gateway = get_option('woocommerce_default_gateway'); + if (isset($available_gateways[$default_gateway])) : + $available_gateways[$default_gateway]->set_current(); + else : + current($available_gateways)->set_current(); + endif; + endif; foreach ($available_gateways as $gateway ) : ?>