[Date Prev][Date Next][Thread Prev][Thread Next][Interchange by date
][Interchange by thread
]
[ic] Prevent from ordering more than is in stock
<<
> Hello,
>
> I have prevented out of stock orders (foundation demo) by conditionally
> displaying the quantity box / having an 'Add to cart' button clickable in
> the various pages (results.html, flypage.html, and the components such as
> random, etc.), by use of a [if-item-data inventory quantity > 0] tag. I
> also got rid of the 'Out Of Stock' and 'N' hyperlinks in flypage.html and
> results.html respectively.
>
> Is this sufficient to prevent people from ordering items that are out of
> stock?
>
>
> Also, the main reason for posting this; how can I prevent people from
> ordering more items than are in stock?
>
> A search of the archives revealed this:
> > [item-calc]
> > my $q = q{[item-data inventory quantity]};
> > my $s = q{[item-quantity]};
> > if($q < $s) {
> > return <<EOF;
> > <font size=1 face="arial, verdana, helvetica" color="#ff0000">
> > Sorry, only $q available.
> > <br></font></TD><TD ALIGN=CENTER>
> > <INPUT onChange="this.form.submit()" TYPE=text NAME="[quantity-name]"
> > VALUE=$q SIZE=3>
> > EOF
> > }
> > else {
> > return <<EOF;
> > </TD><TD ALIGN=CENTER>
> > <INPUT onChange="this.form.submit()" TYPE=text NAME="[quantity-name]"
> > VALUE="[item-quantity]" SIZE=3>
> > EOF
> > }
> > [/item-calc]
> > </TD>
>
> This would go in checkout.html, in the cart section, but the problem here
> is that if someone arrives at the checkout page with more items than are in
> stock, or changes the quantity on the checkout page to more than is in
> stock, the incorrect price is displayed.
>
> The solution is very simple - all I have to do is set the item quantity to
> the inventory value for that item within the above 'if' statement, but HOW
> do I do this, either in ITL or Perl?
>>
> I have this in my templates/components/cart. Display q_message
> somewhere in your "error message" area of the cart and it will let users
> know if their order has been modified. This code came out of this llist
> and seems to work well.
>
> It should probably go in the ord/checkout file also, although I don't
> have it there because I don't have that much concurrency. For sites with
> really high item concurrency at checkout there should probably be something
> in the etc/profiles.order also. For sites with mega ultra crazy order
> volume and small stock quantities it might even be necessary to go beyond
> that, one might have to start doing some sort of encapsulation using a
> database transaction or a nasty semaphone to check the stock level and
> decrement it or kick the order back all in one autonomous, serialized
> operation. But, man, if I ever get to that transaction volume I'll be able
> to pay someone else to do that while I sit on the beach and drink
> margaritas. Until that point I will be using this:
>
> [comment]dont let users add more to cart than we have in stock[/comment]
> [perl tables=inventory]
> my $item;
> foreach $item (@{$Carts->{main}}) {
> my $on_hand = tag_data('inventory', 'quantity', $item->{code});
> next if $on_hand >= $item->{quantity};
> if ($on_hand<=0) {
> $item->{quantity} = 0;
> $item->{q_message} = "Item is currently out of stock.";
> } else {
> $item->{quantity} = $on_hand;
> $item->{q_message} = "Limited item stock, order quantity adjusted.";
> }
> }
> [/perl]
>
>
>
> Jeff
Thanks Jeff, that's just the type of thing I was looking for. I've put that
at the top of ord/checkout.html, as I figure it should be parsed before
anything else, but it doesn't seem to be having any effect on the quantities
(I've restarted Interchange). Any ideas?
> How about a SQL query?
>
> [query sql="select quantity from inventory where sku = '[item-code]'"
> list=1]
> [sql-pos 0]
> [/query]
>
> In this example, "[sql-pos 0]" should pull the number in the inventory
> for the given sku.
>
> HTH
Sorry, I should have explained better. I'm OK on grabbing the inventory
value; what I wanted to know is how to set the quantity of the current item
(i.e. the value returned by [item-quantity].