From 69ba855bc104409638b8dace5247bcf841bbb73b Mon Sep 17 00:00:00 2001
From: Chris Oden <wodenx@gmail.com>
Date: Tue, 24 Jan 2012 17:39:46 -0500
Subject: [PATCH] Issue #1215636: Ensure default quote is selected whenever it becomes available, unless another is explicitly selected.

---
 shipping/uc_quote/uc_quote.module |   16 +++++++++++++---
 1 files changed, 13 insertions(+), 3 deletions(-)

diff --git a/shipping/uc_quote/uc_quote.module b/shipping/uc_quote/uc_quote.module
index 8057f1e..96468cb 100644
--- a/shipping/uc_quote/uc_quote.module
+++ b/shipping/uc_quote/uc_quote.module
@@ -665,13 +665,23 @@ function uc_checkout_pane_quotes($op, &$order, $form = NULL, &$form_state = NULL
 
     case 'prepare':
     case 'process':
-      if (isset($form_state['values']['panes']['quotes']['quotes']['quote_option'])) {
+      // If a quote was explicitly selected, add it to the order.
+      if (isset($form['panes']['quotes']['quotes']['quote_option']['#value']) && isset($form['panes']['quotes']['quotes']['quote_option']['#default_value']) 
+          && $form['panes']['quotes']['quotes']['quote_option']['#value'] !== $form['panes']['quotes']['quotes']['quote_option']['#default_value']) { 
         $quote_option = explode('---', $form_state['values']['panes']['quotes']['quotes']['quote_option']);
         $order->quote['method'] = $quote_option[0];
         $order->quote['accessorials'] = $quote_option[1];
-        // Ensure that the form builder uses the default value to decide which radio button should be selected.
-        unset($form_state['input']['panes']['quotes']['quotes']['quote_option']);
+        $order->data['uc_quote_selected'] = TRUE;
       }
+
+      // If the current quote was never explicitly selected, discard it and use the default.
+      if (empty($order->data['uc_quote_selected'])) {
+        unset($order->quote);
+      }
+
+      // Ensure that the form builder uses the default value to decide which radio button should be selected.
+      unset($form_state['input']['panes']['quotes']['quotes']['quote_option']);
+
       $order->quote_form = uc_quote_build_quote_form($order, !empty($form_state['quote_requested']));
 
       $default_option = _uc_quote_extract_default_option($order->quote_form);
-- 
1.7.3.4

