From f6303ec2833bd607e03147ef67eb4fb3f928f397 Mon Sep 17 00:00:00 2001
From: Jake Bell <jake@theunraveler.com>
Date: Fri, 17 Jun 2011 14:40:48 -0500
Subject: [PATCH] Initial stab at D7 compatibility.

---
 uc_free_order.info   |    2 +-
 uc_free_order.js     |   82 +++++++++++++++++++++++++++-----------------------
 uc_free_order.module |   18 +++++++----
 3 files changed, 56 insertions(+), 46 deletions(-)

diff --git a/uc_free_order.info b/uc_free_order.info
index 0fcae5c..1150f6f 100644
--- a/uc_free_order.info
+++ b/uc_free_order.info
@@ -3,4 +3,4 @@ description = Enables a payment method to handle the possibility of free orders.
 dependencies[] = uc_order
 dependencies[] = uc_payment
 package = Ubercart - payment
-core = 6.x
+core = 7.x
diff --git a/uc_free_order.js b/uc_free_order.js
index 0cbb294..02a2fae 100644
--- a/uc_free_order.js
+++ b/uc_free_order.js
@@ -1,53 +1,59 @@
+(function ($) {
 
-var free_order_initialized = false;
-var using_free_order = false;
+Drupal.behaviors.ucFreeOrder = {
 
-// Adds a click function to the total so we can check its updated values.
-$(document).ready(
-  function() {
+	attach: function (context, settings) {
+
+		var free_order_initialized = false;
+		var using_free_order = false;
+
+		// Our main click handler.
+		// Adds a click function to the total so we can check its updated values.
     $('#edit-panes-payment-current-total').click(function() { free_order_check_total(this.value); });
-  }
-);
 
-/**
- * Checks the current total and updates the available/selected payment methods
- * accordingly.
- */
-function free_order_check_total(total) {
-  total = parseFloat(total);
+		/**
+		* Checks the current total and updates the available/selected payment methods
+		* accordingly.
+		*/
+		function free_order_check_total(total) {
+			total = parseFloat(total);
+
+			// Disable the free order option and select the first available method.
+			if (total >= .005 && (using_free_order != false || free_order_initialized == false)) {
+				// Show the other payment method radios.
+				$("#payment-pane .form-radios input:radio").removeAttr('disabled').parent().show(0);
 
-  // Disable the free order option and select the first available method.
-  if (total >= .005 && (using_free_order != false || free_order_initialized == false)) {
-    // Show the other payment method radios.
-    $("#payment-pane .form-radios input:radio").removeAttr('disabled').parent().show(0);
+				// Hide the free order radio.
+				$("input:radio[value=free_order]").attr('disabled', 'disabled').parent().hide(0);
 
-    // Hide the free order radio.
-    $("input:radio[value=free_order]").attr('disabled', 'disabled').parent().hide(0);
+				// Find the first available payment method.
+				var uc_free_order_next_method = $(':radio[name="panes[payment][payment_method]"]:enabled:first').val();
 
-    // Find the first available payment method.
-    var uc_free_order_next_method = $(':radio[name="panes[payment][payment_method]"]:enabled:first').val();
+				// Select the first payment method.
+				$("input:radio[value=" + uc_free_order_next_method + "]").attr('checked', 'checked');
 
-    // Select the first payment method.
-    $("input:radio[value=" + uc_free_order_next_method + "]").attr('checked', 'checked');
+				// Refresh the payment details section.
+				get_payment_details(Drupal.settings.ucURL.checkoutPaymentDetails + uc_free_order_next_method);
 
-    // Refresh the payment details section.
-    get_payment_details(Drupal.settings.ucURL.checkoutPaymentDetails + uc_free_order_next_method);
+				using_free_order = false;
+			}
+			else if (total < .005 && using_free_order != true) {
+				// Hide the fallback payment method radio.
+				$("#payment-pane .form-type-radios input:radio").attr('disabled', 'disabled').parent().hide(0);
 
-    using_free_order = false;
-  }
-  else if (total < .005 && using_free_order != true) {
-    // Hide the fallback payment method radio.
-    $("#payment-pane .form-radios input:radio").attr('disabled', 'disabled').parent().hide(0);
+				// Show and select the free order payment method.
+				$("input:radio[value=free_order]").removeAttr('disabled').attr('checked', 'checked').parent().show(0);
 
-    // Show and select the free order payment method.
-    $("input:radio[value=free_order]").removeAttr('disabled').attr('checked', 'checked').parent().show(0);
+				// Refresh the payment details section.
+				get_payment_details(Drupal.settings.ucURL.checkoutPaymentDetails + 'free_order');
 
-    // Refresh the payment details section.
-    get_payment_details(Drupal.settings.ucURL.checkoutPaymentDetails + 'free_order');
+				using_free_order = true;
+			}
 
-    using_free_order = true;
-  }
+			free_order_initialized = true;
+		}
+	}
 
-  free_order_initialized = true;
-}
+};
 
+})(jQuery);
diff --git a/uc_free_order.module b/uc_free_order.module
index 6b48e13..5b97530 100644
--- a/uc_free_order.module
+++ b/uc_free_order.module
@@ -7,10 +7,14 @@
 
 
 /**
- * Implementation of hook_perm().
+ * Implementation of hook_permission().
  */
-function uc_free_order_perm() {
-  return array('test free order');
+function uc_free_order_permission() {
+  return array(
+    'test free order' => array(
+      'title' => t('Test Free Order Functionality'),
+    ),
+  );
 }
 
 /**
@@ -40,9 +44,9 @@ function uc_free_order_form_alter(&$form, &$form_state, $form_id) {
 }
 
 /**
- * Implementation of hook_payment_method().
+ * Implementation of hook_uc_payment_method().
  */
-function uc_free_order_payment_method() {
+function uc_free_order_uc_payment_method() {
   $methods[] = array(
     'id' => 'free_order',
     'name' => t('Free order'),
@@ -51,14 +55,14 @@ function uc_free_order_payment_method() {
     'callback' => 'uc_payment_method_free_order',
     'checkout' => TRUE,
     'no_gateway' => TRUE,
-    'weight' => 10,
+    'weight' => -10,
   );
 
   return $methods;
 }
 
 // Handles the free order payment method.
-function uc_payment_method_free_order($op, &$arg1, $silent = FALSE) {
+function uc_payment_method_free_order($op, &$order) {
   if ($op == 'cart-details') {
     return t('Continue with checkout to complete your free order.');
   }
-- 
1.7.5.4

