Personalised mugs with a text option (2 mugs left in stock and Subtract Stock is set to Yes and Stock Checkout set to No)
OC allows a customer to do the following with no warning anywhere in the whole process of the completed order.
2 x Mug Text=Bob
2 x Mug Text=Fred
2 x Mug Text=Joe
2 x Mug Text=Jim
So clearly this mug is oversold by 6 (or more if I added more names)
Does anyone know how to fix this bug?
Knd Regards
Tim
product A with option B is considered a different cart item than product A with option C and this is perfectly fine.
Except when it comes to stock checking.
Instead of checking the total quantity of product A against the stock of product A, OC checks that per individual cart item.
In your case:
2 x Mug Text=Bob
2 x Mug Text=Fred
2 x Mug Text=Joe
2 x Mug Text=Jim
OC cart checks 4 times if stock is available for 2 mugs (it is) instead of 1 time against 8 mugs (it is not).
which is just plain wrong.
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.
The most generated errors being found on Opencart forum originates from contributed programming. The increased post counters are caused by redundancies of the same solutions that were already provided prior.
Regards,
Straightlight
Programmer / Opencart Tester
It's not really about stock checking, it's about option management in general. Options in OpenCart don't have quantities and product quantily is always subtracted. In this concept per items checks are pretty much valid.
Professional OpenCart extensions, support and custom work.
Contact me via email or Skype by support@thekrotek.com
It behaves how I want it to warning me correctly (as in the case above when I've ordered more than 2 mugs).
I've kept the main product to Subtract Stock and the Options to Not Subtract Stock
I've added the code just below the following code found on line 213 in system/library/cart/cart.php
Code: Select all
// Stock
if (!$product_query->row['quantity'] || ($product_query->row['quantity'] < $cart['quantity'])) {
$stock = false;
}
Code: Select all
if($product_query->row['subtract'] == 1){
$sum_query = $this->db->query("SELECT SUM(quantity) AS sum_total FROM " . DB_PREFIX . "cart WHERE api_id = '" . (isset($this->session->data['api_id']) ? (int)$this->session->data['api_id'] : 0) . "' AND customer_id = '" . (int)$this->customer->getId() . "' AND session_id = '" . $this->db->escape($this->session->getId()) . "' AND product_id = '" . (int)$product_query->row['product_id'] . "'");
if ($sum_query->row['sum_total']) {
if (!$product_query->row['quantity'] || ($product_query->row['quantity'] < $sum_query->row['sum_total'])) {
$stock = false;
}
}
}
Tim
Using another simple foreach as the one being already implemented for the discounts in the cart library could do it rather than using another query since the $cart array is already fetching based on the position you are addressing about in the getProducts() method.timocratic wrote: ↑Tue Apr 21, 2020 8:59 pmHi, thanks for your replies just wondering if you can see any problems elsewhere with the following code I've added to my test site before I go live with it.
It behaves how I want it to warning me correctly (as in the case above when I've ordered more than 2 mugs).
I've kept the main product to Subtract Stock and the Options to Not Subtract Stock
I've added the code just below the following code found on line 213 in system/library/cart/cart.phpThis is the code:Code: Select all
// Stock if (!$product_query->row['quantity'] || ($product_query->row['quantity'] < $cart['quantity'])) { $stock = false; }
RegardsCode: Select all
if($product_query->row['subtract'] == 1){ $sum_query = $this->db->query("SELECT SUM(quantity) AS sum_total FROM " . DB_PREFIX . "cart WHERE api_id = '" . (isset($this->session->data['api_id']) ? (int)$this->session->data['api_id'] : 0) . "' AND customer_id = '" . (int)$this->customer->getId() . "' AND session_id = '" . $this->db->escape($this->session->getId()) . "' AND product_id = '" . (int)$product_query->row['product_id'] . "'"); if ($sum_query->row['sum_total']) { if (!$product_query->row['quantity'] || ($product_query->row['quantity'] < $sum_query->row['sum_total'])) { $stock = false; } } }
Tim
The most generated errors being found on Opencart forum originates from contributed programming. The increased post counters are caused by redundancies of the same solutions that were already provided prior.
Regards,
Straightlight
Programmer / Opencart Tester
Does the following look ok added just above Product Discounts on line 178 of the same file (it worked same as before)
Code: Select all
$cart_sum_qty = "";
foreach ($cart_query->rows as $cart_sum) {
if ($cart_sum['product_id'] == $cart['product_id']) {
$cart_sum_qty += $cart_sum['quantity'];
if ((!$product_query->row['quantity'] || $product_query->row['quantity'] < $cart_sum_qty)) {
$stock = false;
}
}
}
Tim
Yes it is and no it isn't.It's not really about stock checking, it's about option management in general.
Yes they do and no it isn't.Options in OpenCart don't have quantities and product quantily is always subtracted.
No they're not.In this concept per items checks are pretty much valid.
No points.
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.
You are still using the cart sum. As explained, you do not need to pull a new query. In your system/library/cart/cart.php file,timocratic wrote: ↑Tue Apr 21, 2020 10:24 pmHi, thanks Straightlight
Does the following look ok added just above Product Discounts on line 178 of the same file (it worked same as before)RegardsCode: Select all
$cart_sum_qty = ""; foreach ($cart_query->rows as $cart_sum) { if ($cart_sum['product_id'] == $cart['product_id']) { $cart_sum_qty += $cart_sum['quantity']; if ((!$product_query->row['quantity'] || $product_query->row['quantity'] < $cart_sum_qty)) { $stock = false; } } }
Tim
you already have the following you could use:
Code: Select all
// Product Discounts
$discount_quantity = 0;
foreach ($cart_query->rows as $cart_2) {
if ($cart_2['product_id'] == $cart['product_id']) {
$discount_quantity += $cart_2['quantity'];
}
}
The most generated errors being found on Opencart forum originates from contributed programming. The increased post counters are caused by redundancies of the same solutions that were already provided prior.
Regards,
Straightlight
Programmer / Opencart Tester
Yes, they are. What this guy sells is ONE product with some post-production customization. His options are kinda... virtual. It's not size or color, it's a custom text, which can be applied to ANY product unit.
If he has 10 items only and defined quantity as 10 for each option, then it was broken from the start. For product quantity 10 its options total quantity MUST be 10, not 10 times number of options. So yes, I still think OC checks for stock properly, yet option management lacks flexibility and requires understanding.
Professional OpenCart extensions, support and custom work.
Contact me via email or Skype by support@thekrotek.com
(The whole OC stock management product and options are probably written by a person with DB skills and no warekousing skills.)yet option management lacks flexibility and requires understanding.
All of your other comments are completely wrong.
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.
The only thing I was wrong about is options quantity. My bad. Your replies on the contrary are useless and full of unnecessary criticism as usual. I already explained you, why there's no issue with stock checking - it is designed accordingly and OP uses options improperly from the start. This is the real issue. But I'm pretty sure you will come with more stupid replies on how everybody around is bad, except yourself. You always do, but nobody really cares.
Now regarding issue itself. Like I already mentioned, problem is in how options are defined, because in this case options aren't really options in terms of OpenCart design. Size, volume or color - these are the options, providing you have a limited quantity of them, which IN TOTAL doesn't exceed product quantity. So none of the options, which have Quantity and Subtract fields available should be used. Basically, the only option from default ones which can be used is Text. Select or Radio will eventually bring "improper stock checking", which as I said works exactly as OC was designed to work with options.
Another solution would be to create a simple Select, which works like Text, but with pre-defined values and without subtracting stock. This will require some messing with the code though. However, this solutions seems much better and much more friendly to OC design.
Professional OpenCart extensions, support and custom work.
Contact me via email or Skype by support@thekrotek.com
Users browsing this forum: pprmkr and 20 guests