[ic] Warning message for out of stock items

Bob Puff bob at nleaudio.com
Wed Aug 30 01:26:28 EDT 2006

I searched through the archives trying to find how to display a warning 
to the user when they order a quantity of product that exceeds current 
stock.  I found a few threads the dealt with reducing the quantity to 
match inventory, but that's not what I wanted.

Here's my solution:
1. Put this code at the top of pages/ord/basket.html, 
pages/ord/checkout.html, pages/ord/finalize.html, etc/receipt.html, 
etc/mail_receipt, and etc/report:

[perl tables=inventory]
my $item;
foreach $item (@{$Carts->{main}}) {
   my $on_hand = tag_data('inventory', 'quantity', $item->{code});
   next if $on_hand >= $item->{quantity};  {
     $item->{q_message} = "Item(s) on back-order";

Each of the pages is going to take a little different mod to show the 
message.  For example, etc/report and mail_receipt need something like:

  [column width=14 align=right gutter=1][item-price][/column]
  [column width=15 align=right gutter=0][item-subtotal][/column]
-[if-item-data options o_enable][if-item-data !options o_modular][row 82]
+[if-item-modifier q_message][row 82]
+    [column width=5 gutter=1 align=right][/column]
+    [column width=12 gutter=1][/column]
+    [column width=32 wrap=1 gutter=1][item-modifier q_message] 
+[/if-item-modifier][if-item-data options o_enable][if-item-data 
!options o_modular][row 82]
      [column width=5 gutter=1 align=right][/column]
      [column width=12 gutter=1] [item-code] [/column]

Files like pages/ord/basket.html are easier:

                 <TD valign="top"><b>[item-sku]</b></TD>
                 <td><a href="[area href="[item-sku]"]" 
+[if-item-modifier q_message]<font color=red>[item-modifier 
         [if scratch dealer]
         [if-item-data pricing sku]
             <BR>[page quantity [item-code]]
             [L]QUANTITY PRICING[/L]</A>

(a bit of contextual diffing, pardon the poor wrapping)

I also noticed a bug in the MaxQuantityField as described by Mike in 
If the inventory number is negative, setting this variable causes the 
quantity of an affected item to become this negative number, which 
really makes a mess of things!  The code for this should check to make 
sure the value is not <0, and if so, enforce 0.


More information about the interchange-users mailing list