[ic] Inventory control in cart: code snippet question...

Mark Weaver mdw1982 at mdw1982.com
Thu Jun 16 11:37:54 EDT 2005

Hi all,

I've got an IC installation, 5.2 running on a RHEL4 WS server. The 
current catalog has the following snippet of code, curtosy of Mike 
Heins, to control the amount of items placed in the cart based on 
current inventory levels.

----------- CODE SNIPPET --------------
[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";

[if scratch outofstock]
	[scratch outofstock]
	[tmp outofstock][/tmp]

[if-item-modifier changed_qty]
	Quantity changed from [item-modifier changed_qty] to [item-quantity] to
fit current inventory.
---------------- end code snippet ---------------

This code works wonderfully, however, for some reason that I'm just not 
seeing when the snippet does what its supposed to do and gets a positive 
the message that is being displayed is the following:

[if-item-modifier changed_qty] Quantity changed from [item-modifier 
changed_qty] to [item-quantity] to fit current inventory. 

Its actually only supposed to display this message:

	Quantity changed from <selected value> to <actual level value>
	to fit current inventory.

Based on the code that I'm using on this basket code what am I missing 
that its outputting the entire if statement instead of just the message 
about the change being made along with the amount placed in the cart and 
the changed value?

This code snippet was placed at the very top of the basket.html page 
following the directions given in the following post:




More information about the interchange-users mailing list