Satchmo allows negative inventory with TRACK_INVENTORY

34 views
Skip to first unread message

Michal

unread,
May 30, 2010, 6:43:18 PM5/30/10
to Satchmo users
The use case is - the stock for a given product is 2 items and 5
shoppers put the same product in their carts and proceed with checkout
process and place an order. The outcome will be -3 in the
product.items_in_stock. Looks like the whole inventory tracking
mechanism is encapsulated in an signal listener attached to
order_success and there is no validation done anywhere before or even
here.

So - my question is - what is the best signal to connect to do cart
verification before it is passed to payment for checkout handling? Or
maybe there is another way to solve it without modifications to
satchmo core?

Regards,
Michal

Chris Moffitt

unread,
May 31, 2010, 9:40:22 PM5/31/10
to satchm...@googlegroups.com
You could used cart_add_verify to do an additional inventory check before adding to the cart.

http://www.satchmoproject.com/docs/dev/signals.html

-Chris


--
You received this message because you are subscribed to the Google Groups "Satchmo users" group.
To post to this group, send email to satchm...@googlegroups.com.
To unsubscribe from this group, send email to satchmo-user...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/satchmo-users?hl=en.


Michal

unread,
Jun 1, 2010, 3:23:53 AM6/1/10
to Satchmo users
That would not help, because all I can check at that point is how many
other people have that item in their carts, but I cannot make
decisions on whether to allow add or not based on this.

In the given use case at this point product.items_in_stock would still
be 2. So I will allow any number of users to add it to their carts.
And lets say none of them changes anything again before checkout - I
will still be left with -3 in the items_in_stock. ...and 3 very
unhappy customers.

Do you see a way to verify the cart once user clicks "Checkout"?

-Michal
> > satchmo-user...@googlegroups.com<satchmo-users%2Bunsubscribe@goog legroups.com>
> > .

Michal

unread,
Jun 4, 2010, 4:53:05 PM6/4/10
to Satchmo users
Any ideas... anyone?

-M

Alex Robbins

unread,
Jun 4, 2010, 5:50:14 PM6/4/10
to satchm...@googlegroups.com
Seems like the problem is that you want lots of people to put it in
their cart, even if you don't have that many left. That violates the
shopping cart mental model. In the real world, if a store is out of a
certain item, I can't put it in my cart. If you followed that same
principle here, then Chris' idea works. You would need to drop old
carts after a reasonable amount of time (maybe an hour?) with some
kind of cleanup script, but that seems doable.

I haven't coded any of this, but it makes sense in my head :)
Alex

> To unsubscribe from this group, send email to satchmo-user...@googlegroups.com.

Michal

unread,
Jun 5, 2010, 2:17:33 PM6/5/10
to Satchmo users
I hear you, but that doesn't solve my problem. I need to be able to
allow many people add item to cart (as satchmo allows by default) but
with the "Track inventory"=true and "Allow checkout with 0
inventory"=false make sure that satchmo _does not_ allow checking out
while product.items_in_stock=0. That is the behavior I expected after
setting those configuration options.

Similar problem resulting with the same bug is reported here:
http://bitbucket.org/chris1610/satchmo/issue/1163/purchase-of-inactive-products-after-add-to

So I was asking for ideas on how to workaround this as I was not able
to find out how to hook to the moment in satchmo execution that
happens when user presses the "Checkout" button and submits the cart
for checkout.

Also a potential problem with your solution would be that someone
could potentially create a script that would add all of your products
to cart and no one else would be able to put anything from your store
to cart for an hour or however long until the cart cleanup script
would kick-in. And since you are not notified on cart creation (as
opposed to when someone submits an order) you wouldn't even know about
it.

-Michal
On Jun 4, 11:50 pm, Alex Robbins <alexander.j.robb...@gmail.com>
wrote:

davecap

unread,
Jun 9, 2010, 11:27:35 AM6/9/10
to Satchmo users
I'm implementing a store now where adding to a cart means reserving an
item for some time (2 hours). I am not worried about someone adding
everything to the cart to block other people for a few hours. Even if
some jerk does do that, I can easily add a hook requiring log in for
adding more than X items to the cart... but I'm not going to waste my
time implementing that until that happens.

This is what I am doing:
- add some reservation settings to global config (reservations enabled
and reservation time)
- reservations start as soon as anything is added to the cart (I use
the cart's created_at time)
- add 'items_reserved()' to my custom product model
- items_reserved() goes through all carts looking for the
product_id and totals the reserved product count
- add 'net_items_in_stock()' to my custom product model, subtracts
items_in_stock by items_reserved()
- add my own listener (veto_reserved) and disconnect satchmo's
veto_out_of_stock
- use net_items_in_stock() from my custom product instead of
items_in_stock (in the new listener)
- add a cron job with a script called 'clear_expired_carts', expire
all carts by deleting them from Carts (I will also add an ExpiredCarts
model for analysis later)
- I don't want to customize the satchmo code (the Cart model) so I
have to work around it by adding the ExpiredCarts model..... any ideas
on how to do this better?
- I will add caching to this too (with invalidation when something is
added/removed from carts).

I understand this may not be what you want but this may give you an
idea on how to implement it your way.

- David

On Jun 5, 2:17 pm, Michal <mic...@na-strychu.pl> wrote:
> I hear you, but that doesn't solve my problem. I need to be able to
> allow many people add item to cart (as satchmo allows by default) but
> with the "Track inventory"=true and "Allow checkout with 0
> inventory"=false make sure that satchmo _does not_ allow checking out
> while product.items_in_stock=0. That is the behavior I expected after
> setting those configuration options.
>
> Similar problem resulting with the same bug is reported here:http://bitbucket.org/chris1610/satchmo/issue/1163/purchase-of-inactiv...

Michal

unread,
Jun 9, 2010, 12:20:14 PM6/9/10
to Satchmo users
David,

Thanks for providing a very informative description of your solution.

This however would not work in my scenario because I have people
browsing through site for days while reaching their decision to buy. I
currently have over 1600 items in stock and will soon exceed 2k so I
want to give people enough time to contemplate on their choices. I
decided that they will keep all of the items in their carts unless an
item or items go out of stock - then only such will be removed.

I've done the following: I have replaced cart.display view with my own
that verifies if all of the items are still in stock - if not removes
such item(s) from cart. All I have to add to it right now is some
feedback to the customer to tell them that someone was quicker about
one or more of their products.

This approach is not perfect because it requires that customer
refreshes their cart before clicking checkout, but with some tricks it
should be good enough right now.

-Michal

Tay Ray Chuan

unread,
Jun 9, 2010, 11:27:17 PM6/9/10
to satchm...@googlegroups.com
Hi,

On Thu, Jun 10, 2010 at 12:20 AM, Michal <mic...@na-strychu.pl> wrote:
> I've done the following: I have replaced cart.display view with my own
> that verifies if all of the items are still in stock - if not removes
> such item(s) from cart. All I have to add to it right now is some
> feedback to the customer to tell them that someone was quicker about
> one or more of their products.
>
> This approach is not perfect because it requires that customer
> refreshes their cart before clicking checkout, but with some tricks it
> should be good enough right now.

You could implement this as a middleware, wrapping before the "display
cart" view, and "checkout step 1" view.

--
Cheers,
Ray Chuan

Reply all
Reply to author
Forward
0 new messages