In the last few days, two customers made orders that included the same item twice.
I think it might be that they added the item first without being logged in, but I don't know.
In the second case, the item now has a stock value of -1. This should not be possible.
Can I prevent users from adding the exact same item twice? (they can add the items if one has extra selections). In any case it should NEVER be possible to make order that makes the stock value lower than the minimum value.
Is there some simple line to add in the code?
UK OpenCart Hosting | OpenCart Audits | OpenCart Support - please email info@antropy.co.uk
Professional OpenCart extensions, support and custom work.
Contact me via email or Skype by support@thekrotek.com
I'm thinking it might be best to have the logic in the checkout rather than in the cart.
I found there is already some logic:
controller/checkout.php
Code: Select all
// Validate minimum quantity requirements.
$products = $this->cart->getProducts();
foreach ($products as $product) {
$product_total = 0;
foreach ($products as $product_2) {
if ($product_2['product_id'] == $product['product_id']) {
$product_total += $product_2['quantity'];
}
}
if ($product['minimum'] > $product_total) {
$this->response->redirect($this->url->link('checkout/cart'));
}
}
$product['minimum'] is 1, I assume. It is the standard.
In the case of a custumer ordering the same item twice, $product_total will be 2. Otherwise it will be 1. How can $product['minimum'] be higher than this value?
Isn't there any validation somewhere to prevent a customer from buying more of an item than there is stock?
I don't know how it is possible either but it has happened in my shop several times now.
I can't recreate it either. I don't know what the costumers do.
It does this on product per cart line item instead of on product cart-wide.
Example of how this goes with "optional" options:
So if I have 2 in stock of item A and item A has 2 options, I can add item A 3 times to the cart.
1) Item A qty=1 without any option
2) Item A qty=1 with option 1
3) Item A qty=1 with option 2
This is fine as they should be separate cart line items with their own pricing but it is not fine how OC handles the stock level check.
OC checks each line item product separately against the stock level and each is ok because each line item quantity of item A is below stock level of 2.
So no warning about not having enough stock, I can just checkout 3 items A when I only have 2, I could even make one line item qty=2 and I am still good.
So you need to alter the way OC checks the stocklevels and make sure it takes all cart line items with the same product into account.
I personally have changed the cart class: system/library/cart/cart.php
Code: Select all
// Stock
if (!$product_query->row['quantity'] || ($product_query->row['quantity'] < $cart['quantity'])) {
$stock = false;
}
into:
Code: Select all
// Stock
// Change[CARTCLASS[28] check all cart items and add qty of same product
$ptotal = 0;
foreach ($cart_query->rows as $cart_3) {
if ($cart_3['product_id'] == $cart['product_id']) $ptotal = $ptotal + $cart_3['quantity'];
}
// Change[CARTCLASS[28] check against total of product in cart regardless of line items
if (!$product_query->row['quantity'] || ($product_query->row['quantity'] < $cart['quantity']) || ($product_query->row['quantity'] < $ptotal)) {
$stock = false;
}
Crystal Light Centrum Taiwan
Extensions: MailQueue | SUKHR | VBoces
“Data security is paramount at [...], and we are committed to protecting the privacy of anyone who is associated with our [...]. We’ve made a lot of improvements and will continue to make them.”
When you know your life savings are gone.
If you had only a couple cases like this, I suggest you to ignore. Just disable checkout for out-of-stock items in store settings and be happy.
Professional OpenCart extensions, support and custom work.
Contact me via email or Skype by support@thekrotek.com
It is already disabled. Customers can't put out-of-stock items in the basket and check out, but they can do like this
Item in stock: 1
Add to basket: 1 pc.
Add by mistake another 1pc of same item.
They can't add 2pc. See also the post above.
Adding to basket is done line-by-line, so line 2 doesn't check if line 1 contains the same item. There is also no check done during checkout.
adding the "very same item" should not happen but it has been reported before.
The logic for merging an existing "guest" cart with an existing "customer" cart when a customer sign's in is at best flaky and is the most likely cause.
There is a solution for that, I posted it not so long ago, search for it.
Crystal Light Centrum Taiwan
Extensions: MailQueue | SUKHR | VBoces
“Data security is paramount at [...], and we are committed to protecting the privacy of anyone who is associated with our [...]. We’ve made a lot of improvements and will continue to make them.”
When you know your life savings are gone.
viewtopic.php?f=201&t=211273
Crystal Light Centrum Taiwan
Extensions: MailQueue | SUKHR | VBoces
“Data security is paramount at [...], and we are committed to protecting the privacy of anyone who is associated with our [...]. We’ve made a lot of improvements and will continue to make them.”
When you know your life savings are gone.
That's great!
Which of the posts exactly should I implement?
Do I need to edit all those files? I would prefer something simple.
Also, is this verified to work if a customer adds 1 item ABC with extra selection ("blue") and 1 item ABC with extra selection "red"? Of course this must be possible. What should not be possible is to add item ABC +"blue" and item ABC +"red".
The first post gives a warning and prevents checkout of these if you do not have 2 or more of item ABC.
The second post prevents the possible addition of multiple ABC or multiple ABC + "red" or multiple ABC + "blue" cart line items when a recorded customer cart is merged with his/her guest cart and it prevents the execution of that merging on every page request of a signed-in customer.
so you can still have a cart like:
item ABC qty=x
item ABC qty=y and option "red"
item ABC qty=z and option "blue"
but checkout only if x+y+z <= stock of ABC
you cannot have a cart like:
item ABC qty=a
item ABC qty=b
item ABC qty=c and option "red"
item ABC qty=d and option "red"
etc.
the first post would also prevent checkout if a+b+c+d > stock of ABC but it kind of looks silly and should not happen.
Crystal Light Centrum Taiwan
Extensions: MailQueue | SUKHR | VBoces
“Data security is paramount at [...], and we are committed to protecting the privacy of anyone who is associated with our [...]. We’ve made a lot of improvements and will continue to make them.”
When you know your life savings are gone.
I still have customers placing double orders, it happens at least once a month.
And there is no alternatives.


I mean seriously, what is this shit? This is from the last month alone.
If I had known that OpenCart is such a buggy mess I would have paid a bit more and used something else. This gives a very unprofessional impression to customers.
One customer told me he added some items to the cart and then switched language, and the cart became empty so he added them again.
That's not supposed to happen !!!
Professional OpenCart extensions, support and custom work.
Contact me via email or Skype by support@thekrotek.com
Crystal Light Centrum Taiwan
Extensions: MailQueue | SUKHR | VBoces
“Data security is paramount at [...], and we are committed to protecting the privacy of anyone who is associated with our [...]. We’ve made a lot of improvements and will continue to make them.”
When you know your life savings are gone.
Users browsing this forum: No registered users and 63 guests