[ic] Inventory control in 5.2.0
Marty Tennison
marty at sediva.com
Tue Mar 1 16:43:23 EST 2005
Bill Eichin wrote:
> I'm in the middle of testing a new webstore. I just placed an order for
> 700 pieces of an item that only has 53 in stock; the order went through
> and is now pending. But that's not what I want...
>
> At the very least, I want the cart to prevent someone from ordering more
> than there are in stock. I thought that's what DECREMENT INVENTORY = 1
> in the hidden "variables" table stood for... I'm still looking for
> documentation on this, but can someone help me out here?
>
> Thanks, in advance,
>
> --Bill
> Eichin
Hi Bill,
The DECREMENT INVENTORY causes IC to reduce the quantity field in the
inventory table by the number of items ordered. However, this takes
place after the transaction.
In order to keep people from ordering more than you have in stock,
you'll need to loop through the cart items, compare the quantity they
have in their cart to what you have in stock, then reduce their cart
quantity to match your stock on hand, if they order to many.
Here is a little perl snippet (courtesy of Mike Heins in some email
thread a while ago) that does just that. You'll need to put this (or
something similar) in the top of your basket page or wherever the cart
is displayed.
Good Luck.
===========================================================
[comment]Adjust cart contents to match stock on hand[/comment]
[tmp outofstock][/tmp]
[perl tables="inventory"]
my $item;
foreach my $item ( @{$Carts->{main}} )
{
delete $item->{changed_qty};
if ($item->{quantity} > $Tag->data(inventory, quantity, $item->{code}) ) {
$item->{changed_qty} = $item->{quantity};
$item->{quantity} = $Tag->data(inventory, quantity, $item->{code});
}
if ($Tag->data(inventory, quantity, $item->{code}) <= 0 ) {
$Scratch->{outofstock} = "Sorry, item #$item->{code} is out of stock";
}
}
return;
[/perl]
[if scratch outofstock]
[scratch outofstock]
[tmp outofstock][/tmp]
[/if]
[if-item-modifier changed_qty]
Quantity changed from [item-modifier changed_qty] to [item-quantity] to
fit current inventory.
[/if-item-modifier]
==============================================================
--
- - -- ---- ---------------------------- --- -- - -
Marty Tennison The Sediva Company
email: marty at sediva.com
web: www.sediva.com
phone: +1-866-473-3482
fax: +1-866-686-6719
- -- --- --------------------------------------- --- --
More information about the interchange-users
mailing list