Page 1 of 1

Why not show Out Of Stock warning in cart page when I added the same product twice and one of them has option?

Posted: Sun May 05, 2019 2:35 am
by Khalid H.S
cart.png

cart.png (96.48 KiB) Viewed 400 times

Hi,

Version: 3.0.3.2 (Also in in 2.0.3.2)
Product quantity: 1
Option quantity: 1
Minimum quantity: 1
Subtract stock: Yes
Out of stock status: Out of stock
Show Out Of Stock Warning: Yes
Stock Checkout: No

Why not show Out Of Stock warning in cart page when I added the same product twice and one of them has option, then after order became -1 product quantity?

Thank you.

Re: Why not show Out Of Stock warning in cart page when I added the same product twice and one of them has option?

Posted: Sun May 05, 2019 4:57 am
by straightlight
While a validation may be possible to be added from the cart page, what happens when the customer adds the product with the product option where the product option quantity value is higher than 1 at that time but then the stock level for that product option quantity value gets lowered than 1 within the next hour (default time interval). Then, the customer gets notified but, prior, he was politically able to add that product to the cart.

What should then happened due to this transition period between that time?

Re: Why not show Out Of Stock warning in cart page when I added the same product twice and one of them has option?

Posted: Sun May 05, 2019 7:06 am
by letxobnav
He means disregard options when evaluating stock levels.
Default a product with options is regarded as a different product than the same product without options.

He has a point.

Re: Why not show Out Of Stock warning in cart page when I added the same product twice and one of them has option?

Posted: Sun May 05, 2019 11:59 am
by straightlight
Yes, he has a point - which is why I am asking the OP what should happened between the two time periods from the product page and the cart page when the stock level is being verified.

Re: Why not show Out Of Stock warning in cart page when I added the same product twice and one of them has option?

Posted: Sun May 05, 2019 2:15 pm
by letxobnav
well, same old.

now it checks one cart item at a time.
In this case you would have multiple cart items with the same product_id.
So perhaps instead of checking the stock of each product per cart item, check the stock levels of each product cart-wide.
No need to touch the stock checking of the options.

Re: Why not show Out Of Stock warning in cart page when I added the same product twice and one of them has option?

Posted: Sun May 05, 2019 8:19 pm
by straightlight
The product option quantity values of each option from each products would need to be validated since the quantity of those options have no stock levels that can be defined from the OC admin as compared to their main / related products. However, the only problem with this, politically, is that customers are adding products during a time where the product option quantity values are above 0 but could be subject to change by the time they try to checkout their products from the cart which means, by validating the product option quantity values from the cart page, if the quantity is below 1, the customer would be restricted on processing that demand where originally he was allowed to add it to the cart in order to checkout that good when adding the whole product from the product category page or from the product page itself.

Which is why, it is not as simple as it seem. I do have one unpublished extension where an event is initiated after the getProductOptions method has been called in order to verify the product option quantity value and also with the orders where store owners receives an email whenever the product option quantity value is below 1 but not sure politically if this would be the right call.

If there are more users posting about the best options, I'll see what I can do to suggest the change in the core if the changes haven't been made before by then.

Re: Why not show Out Of Stock warning in cart page when I added the same product twice and one of them has option?

Posted: Sun May 05, 2019 10:10 pm
by letxobnav
Not sure if we are talking about the same thing here.
As I understand it:

I have product A which has options.
I only have 1 product A in stock and do not allow checkout without stock.

I can add product A to my cart, quantity 1 without options.
I can add product A to my cart, quantity 1 with options.

Then I can checkout 2 products A while I do not have 2 in stock because the stock check does not take both cart items onto account even though the product is the same.

That is what I understand the OP was referring to, the stock levels of the options itself play no part in this.
What you are describing is a separate issue I think.

Re: Why not show Out Of Stock warning in cart page when I added the same product twice and one of them has option?

Posted: Sun May 05, 2019 10:26 pm
by straightlight
Then I can checkout 2 products A while I do not have 2 in stock because the stock check does not take both cart items onto account even though the product is the same.
Both products A should be regrouped as the same product in the cart database table but only the quantity should vary which is why we don't include the category ID into the cart database table by default. Otherwise, the identical products A would be redundant into the cart database table as the stock level would be almost impossible to validate with the same products unless the stock levels would be provided categorically from the OC admin.

Are you both implying that the same products can be added by default as separated rows in the cart page?

Re: Why not show Out Of Stock warning in cart page when I added the same product twice and one of them has option?

Posted: Mon May 06, 2019 7:56 am
by letxobnav
Are you both implying that the same products can be added by default as separated rows in the cart page?
well, I am.

you can add all these:
product A without options
product A with option 1
product A with option 2
product A with option 1 and option 2
etc.

no problem as each cart item is stock checked on its own ignoring the other items with the same product id.
In essence, it treats a product with an option as a separate product which is fine except where stock is concerned.

Re: Why not show Out Of Stock warning in cart page when I added the same product twice and one of them has option?

Posted: Mon May 06, 2019 8:35 am
by letxobnav
in order to prevent this I have to change

Code: Select all

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

Code: Select all

				$productCartQuantity = 0;
				foreach ($cart_query->rows as $cart_3) {
					if ($cart_3['product_id'] == $cart['product_id']) $productCartQuantity = $productCartQuantity + $cart_3['quantity'];
				}
				
				// Stock
				if (!$product_query->row['quantity'] || ($product_query->row['quantity'] < $productCartQuantity)) {
					$stock = false;
				}

Re: Why not show Out Of Stock warning in cart page when I added the same product twice and one of them has option?

Posted: Mon May 06, 2019 8:58 am
by straightlight
Edit: The ptotal is an integer, not a float, I see.

Re: Why not show Out Of Stock warning in cart page when I added the same product twice and one of them has option?

Posted: Mon May 06, 2019 9:53 am
by letxobnav
no, $ptotal counts the total quantity I have of each product_id in the cart across all cart items regardless of options, it simply adds them up.

Re: Why not show Out Of Stock warning in cart page when I added the same product twice and one of them has option?

Posted: Mon May 06, 2019 9:29 pm
by straightlight
letxobnav wrote:
Mon May 06, 2019 9:53 am
no, $ptotal counts the total quantity I have of each product_id in the cart across all cart items regardless of options, it simply adds them up.
Yes … which is why I wrote this at the bottom:
Edit: The ptotal is an integer, not a float, I see.
However, the OC core uses the total terms for float variables, not integers. It simply got me confused for a second when I analyzed your code on the above due to this reason.

Re: Why not show Out Of Stock warning in cart page when I added the same product twice and one of them has option?

Posted: Mon May 06, 2019 9:54 pm
by letxobnav
Oh, I see, did not know that standard, good to know though.

Re: Why not show Out Of Stock warning in cart page when I added the same product twice and one of them has option?

Posted: Mon May 06, 2019 10:12 pm
by straightlight
No problem. I would suggest to replace the $ptotal variable with $pquantity to clarify your suggested codes above, however.

Re: Why not show Out Of Stock warning in cart page when I added the same product twice and one of them has option?

Posted: Mon May 06, 2019 10:39 pm
by letxobnav
done, gave it a more meaningful name.

Re: Why not show Out Of Stock warning in cart page when I added the same product twice and one of them has option?

Posted: Mon May 06, 2019 10:50 pm
by straightlight
Putting Java / jQuery variable structure with the ones using the underscores. At least, the variable name is more significant. ;D

My modification code post has been edited as well.

Re: Why not show Out Of Stock warning in cart page when I added the same product twice and one of them has option?

Posted: Tue May 07, 2019 3:31 pm
by Khalid H.S
letxobnav wrote:
Mon May 06, 2019 8:35 am
in order to prevent this I have to change

Code: Select all

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

Code: Select all

				$productCartQuantity = 0;
				foreach ($cart_query->rows as $cart_3) {
					if ($cart_3['product_id'] == $cart['product_id']) $productCartQuantity = $productCartQuantity + $cart_3['quantity'];
				}
				
				// Stock
				if (!$product_query->row['quantity'] || ($product_query->row['quantity'] < $productCartQuantity)) {
					$stock = false;
				}
Thank you that's what i need.