You can mark this under a feature request and support request but I am having difficulty getting access to the output the function produces.

1. I think it would be a good idea to make this text customizable in the same fashion you have the default "Out Of Stock" message customizable.

2. In the mean time, how can I override that content without actually editing the function itself, because the output isn't wrapped by any pre-processing or themeing functions?

Comments

hanoii’s picture

Status: Active » Postponed

Sorry that I took a while to answer. You are right about pointing out that giving a way to override that function is useful. I might change it to a theme_xx() function sometime in the future. Thing is that the function handles different error messages depending on the error and if the product has attributes or not.

There is, however, something you can do. Those errors are enclosed with t() for translation. I use this trick quite a bit to modify this kind of strings, which is by enabling the locale module and create a new language (EN-special). By doing that you can 'translate' any string into whatever you want, and by translate it doesn't necessary mean another language, just another string. Strings that are not 'translated' would be displayed as default.

pieterdc’s picture

Version: 6.x-1.4 » 6.x-1.x-dev
Category: support » feature
Status: Postponed » Needs review
StatusFileSize
new385 bytes

The attached patch allows other modules to extend / alter the error message.

I, for example, use something like this (in a custom module) :

 /**
 * Implements hook_uc_out_of_stock_error_alter().
 * 
 * @param array $error
 * @param object $product 
 */
function uc_cart_alter_uc_out_of_stock_error_alter(&$error, $product) {
  switch ($error['type']) {
    case 'not_enough':
      $error['msg'] = t("We're sorry. We have now only @qty of the product @product left in stock.", array('@qty' => format_plural($error['stock'], '1 unit', '@count units'), '@product' => $error['product']));
      // Clearly state the desired action
      $error['msg'] .= ' '. t("Adjust your <a href=\"@cart-url\">shopping cart</a> accordingly.", array('@cart-url' => url('cart')));
      break;

    case 'out_of_stock':
      // Clearly state the desired action
      $error['msg'] .= ' '. t("Adjust your <a href=\"@cart-url\">shopping cart</a> accordingly.", array('@cart-url' => url('cart')));
      if (module_exists('uc_stock_notify')) {
        // Give an option te get notified once back in stock
        $error['msg'] .= ' '. t("<a href=\"@stock_notify_url\">Notify when back in stock.</a>", array('@stock_notify_url' => url('stock_notify/'. $product->model, array('query' => drupal_get_destination()))));
      }
      break;
  }
} 
hanoii’s picture

Status: Needs review » Fixed

nice way of doing it. thanks.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.