Post by timocratic » Mon Apr 20, 2020 11:33 pm

Version 3.0.3.2
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

Newbie

Posts

Joined
Mon Mar 16, 2020 11:26 pm

Post by letxobnav » Tue Apr 21, 2020 9:33 am

that is because OC considers/checks stock on cart item not product.
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.


User avatar
Expert Member

Posts

Joined
Fri Aug 18, 2017 4:35 pm
Location - Taiwan

Post by straightlight » Tue Apr 21, 2020 8:06 pm

This topic has now been moved to the OpenCart 3.0 Support > General Support section of the forum.

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


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by thekrotek » Tue Apr 21, 2020 8:49 pm

letxobnav wrote:
Tue Apr 21, 2020 9:33 am
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.
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


User avatar
Expert Member
Online

Posts

Joined
Sun Jul 03, 2016 12:24 am


Post by timocratic » Tue Apr 21, 2020 8:59 pm

Hi, 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.php

Code: Select all

// Stock
if (!$product_query->row['quantity'] || ($product_query->row['quantity'] < $cart['quantity'])) {
	$stock = false;
}
This is the code:

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;
		}
	}
}
Regards
Tim

Newbie

Posts

Joined
Mon Mar 16, 2020 11:26 pm

Post by straightlight » Tue Apr 21, 2020 9:26 pm

timocratic wrote:
Tue Apr 21, 2020 8:59 pm
Hi, 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.php

Code: Select all

// Stock
if (!$product_query->row['quantity'] || ($product_query->row['quantity'] < $cart['quantity'])) {
	$stock = false;
}
This is the code:

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;
		}
	}
}
Regards
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.

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


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by timocratic » Tue Apr 21, 2020 10:24 pm

Hi, thanks Straightlight
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;
		}
	}
}
Regards
Tim

Newbie

Posts

Joined
Mon Mar 16, 2020 11:26 pm

Post by letxobnav » Tue Apr 21, 2020 10:30 pm

It's not really about stock checking, it's about option management in general.
Yes it is and no it isn't.
Options in OpenCart don't have quantities and product quantily is always subtracted.
Yes they do and no it isn't.
In this concept per items checks are pretty much valid.
No they're not.

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.


User avatar
Expert Member

Posts

Joined
Fri Aug 18, 2017 4:35 pm
Location - Taiwan

Post by straightlight » Tue Apr 21, 2020 10:45 pm

timocratic wrote:
Tue Apr 21, 2020 10:24 pm
Hi, thanks Straightlight
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;
		}
	}
}
Regards
Tim
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,

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'];
					}
				}
This is the discount example originally used. You could simply use your own counter variable instead of $discount_quantity in this case. Even better, you could re-use the already counted $discount_quantity from that loop and simply use the IF statement you already used above but with the $discount_quantity so to show the expected error message in the output.

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


Legendary Member

Posts

Joined
Mon Nov 14, 2011 11:38 pm
Location - Canada, ON

Post by thekrotek » Tue Apr 21, 2020 10:54 pm

letxobnav wrote:
Tue Apr 21, 2020 10:30 pm
In this concept per items checks are pretty much valid.
No they're not.
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


User avatar
Expert Member
Online

Posts

Joined
Sun Jul 03, 2016 12:24 am


Post by timocratic » Tue Apr 21, 2020 11:22 pm

Thanks Straightlight have done as you suggested works brilliantly

Kind Regards
Tim

Newbie

Posts

Joined
Mon Mar 16, 2020 11:26 pm

Post by letxobnav » Tue Apr 21, 2020 11:23 pm

while I agree with this:
yet option management lacks flexibility and requires understanding.
(The whole OC stock management product and options are probably written by a person with DB skills and no warekousing skills.)
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.


User avatar
Expert Member

Posts

Joined
Fri Aug 18, 2017 4:35 pm
Location - Taiwan

Post by thekrotek » Wed Apr 22, 2020 2:51 am

letxobnav wrote:
Tue Apr 21, 2020 11:23 pm
All of your other comments are completely wrong.
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


User avatar
Expert Member
Online

Posts

Joined
Sun Jul 03, 2016 12:24 am

Who is online

Users browsing this forum: No registered users and 24 guests