GuestCustomer no checkout
markusmo opened this issue · 7 comments
Hi
I have an issue, and I am not quite sure, why it occurs.
When I am shopping as an anoymous customer, a visiting customer is created there is also a cart and cart_items visible in the database. Only in the UI there is a empty cart.
I do not get any exceptions or something, which is quite strange.
I checked all my foreign keys and my configuration, but I cannot see anything wrong there.
This is a feature. The cart is created together with the Session-Cookie. The Session-Cookie is created on first interaction with the cart. Reason is, that django-SHOP wants to allow a user to shop as guest. This means that we must create a cart tight to a user – an anonymous user. In Django however, anonymous users are indistinguishable. Therefore django-SHOP, creates pseudo anonymous users, which are tight to their session-ID.
You should check when your Django setup creates the session-ID. It normally happens when the first item is added to the cart.
I checked. I do have a session-ID in my cookie, but when debugging, I do not have a customer in my request (for example in my cart-modifier).
Should I switch to my own context processor, overwriting yours?
Did you add 'shop.middleware.CustomerMiddleware'
to MIDDLEWARE
in your settings? Since process_request
is called on each request, the customer
will for sure be added to the request object. Please check line 29.
I added the middleware and I have a customer object in my settings. I can see a customer added to the request.
But when adding a product to my cart and I am not logged in I can see the following error message in my cart modifier when looking at the customer owning the cart:
'Traceback (most recent call last): ... shop.models.defaults.cart.Cart.customer.RelatedObjectDoesNotExist: Cart has no customer.'
An the request in my cart-modifier does not have a customer ...
In model Cart
, the foreign key customer
is a non-nullable field. May it be, that due to a previous misconfiguration, the table myshop_cart
became inconsistent?
Please look at that table and delete all rows where customer_id
points to nowhere.
Latest update works perfectly! Thanks