Return an error for a shipping quote.

8 replies [Last post]
Joined: 08/13/2007
Juice: 1108

Hi there,

I'm working on some tweak for the worldquote module, and one of mofification I would like to do is to return an error when there are no rules that match the customer address... (ATM it return 0$ quote).

I don't find a function that allow to return an error, I find that I have to return the $quote[] array like that :

<?php

$quotes

[] = array('rate' => $rate, 'format' => uc_currency_format($rate), 'option_label' => $rule->name);
?>

But I'm obliged to return an amount etc...

How can I just return an custom error message and so, don't allow customer to continue his shipment ?

Joined: 09/06/2007
Juice: 431

My thought would be: how does the shipping module know no quotes have been calculated, then recreate that state as an "error!" since it does not let you continue without having quotes ...

Joined: 08/07/2007
Juice: 6673

I used to allow each quote method to set an error flag that would prevent the customer from continuing checkout. Unfortunately, it had been done badly, and it was preventing customers from selecting a quote even if there were some available. Now the error message shows up only if all quotes fail.

I do like the idea of individual error messages for quotes, though. I'll add them in so that they are displayed, but probably not affect the checkout process. Should the error message replace the "notes" field that was recently added, or should they be displayed side-by-side?

I also want to make the super error message customizable. It hasn't even been a translatable string, though if I make it configurable, it won't ever be.

Joined: 12/16/2007
Juice: 329

Lyle,

Was the individual error messages for quotes ever implemented in uc1.x? If so, how would I go about using it?

Thanks!

Joined: 12/16/2007
Juice: 329

Never mind, I found the solution in the docs (http://www.ubercart.org/docs/api/hook_shipping_method)

Joined: 08/07/2007
Juice: 6673

Gosh, I never got around to it. Got involved working on other parts of Ubercart.

Joined: 12/16/2007
Juice: 329

Lyle,

I still need a little help trying to implement a custom shipping quote error message. Using the documentation, I was able to find a reference to this and used the following to return a error message from my hook_quote:

<?php
 
return array(
       
'01' => array(
         
'error' => 'This order contains a shipment that is too large for our standard LTL freight quote. Please call us at [727] 319-2300 so we can arrange for the best possible freight quote for you.'
         
),
         );       
?>

This works find except that the error message says "UNDEFINED" before it (see screenshot). I thought it might be related to the accessorial in the hook_shipping_method, so I added that in as follow:

<?php
  $methods
= array(); 
 
$enabled = variable_get('uc_quote_enabled', array('freight' => true));
 
$weight = variable_get('uc_quote_method_weight', array('freight' => 0));
 
$methods['freight'] = array(
   
'id' => 'freight',
   
'title' => t('Freight'),
     
'module' => 'uc_freight_shipping'
   
'enabled' => $enabled['freight'],
    
'weight' => $weight['freight'],
   
'quote' => array(
     
'type' => 'freight',
     
'callback' => 'freight_quote',
     
'accessorials' => array(
         
'01' => t('Freight'),
      ),
     ),
  );
  return
$methods;
}
?>

...but the problem persists. Am I missing something, or is this a bug?

Thanks for your help!

AttachmentSize
shipping_quote_error.jpg 61.5 KB
Joined: 08/07/2007
Juice: 6673

It looks like your returned array needs an 'option_label' key alongside the 'error'. Now that I've seen this, I probably need to go add it to some other error messages my shipping methods are returning.

Joined: 12/16/2007
Juice: 329

Perfect, Thanks! Adding the 'option_label' key fixed the 'undefined' issue I was having. Thanks again~