Post by Khalid H.S » Sun May 05, 2019 2:35 am

cart.png

cart.png (96.48 KiB) Viewed 1782 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.

Attachments

opt1.png

opt1.png (46.73 KiB) Viewed 1782 times

pro2.png

pro2.png (116.79 KiB) Viewed 1782 times


مصمم ومطور متاجر إلكترونية | @Oc_Style
لطلبات التصميم، تعريب القوالب والاضافات، ترقية الإصدار، حماية المتجر قم بمراسلتي من خلال المنتدى


موديل: إشعارات البنوك السعودية

1 | 2 | O :طرق لحماية السكربت


User avatar
Active Member

Posts

Joined
Fri Dec 10, 2010 9:39 pm
Location - Saudi Arabia

Post by straightlight » Sun May 05, 2019 4:57 am

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?

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

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

Post by letxobnav » Sun May 05, 2019 7:06 am

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.

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 » Sun May 05, 2019 11:59 am

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.

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

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

Post by letxobnav » Sun May 05, 2019 2:15 pm

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.

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 » Sun May 05, 2019 8:19 pm

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.

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

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

Post by letxobnav » Sun May 05, 2019 10:10 pm

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.

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 » Sun May 05, 2019 10:26 pm

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?

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

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

Post by letxobnav » Mon May 06, 2019 7:56 am

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.

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 letxobnav » 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;
				}
Last edited by letxobnav on Mon May 06, 2019 10:38 pm, edited 1 time in total.

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 » Mon May 06, 2019 8:58 am

Edit: The ptotal is an integer, not a float, I see.
Last edited by straightlight on Mon May 06, 2019 10:50 pm, edited 1 time in total.

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

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

Post by letxobnav » 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.

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 » Mon May 06, 2019 9:29 pm

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.

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

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

Post by letxobnav » Mon May 06, 2019 9:54 pm

Oh, I see, did not know that standard, good to know though.

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 » Mon May 06, 2019 10:12 pm

No problem. I would suggest to replace the $ptotal variable with $pquantity to clarify your suggested codes above, however.

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

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

Post by letxobnav » Mon May 06, 2019 10:39 pm

done, gave it a more meaningful name.

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 » Mon May 06, 2019 10:50 pm

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.

Dedication and passion goes to those who are able to push and merge a project.

Regards,
Straightlight
Programmer / Opencart Tester


Legendary Member

Posts

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

Post by Khalid H.S » Tue May 07, 2019 3:31 pm

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.

مصمم ومطور متاجر إلكترونية | @Oc_Style
لطلبات التصميم، تعريب القوالب والاضافات، ترقية الإصدار، حماية المتجر قم بمراسلتي من خلال المنتدى


موديل: إشعارات البنوك السعودية

1 | 2 | O :طرق لحماية السكربت


User avatar
Active Member

Posts

Joined
Fri Dec 10, 2010 9:39 pm
Location - Saudi Arabia

Post by timbits451 » Thu Apr 08, 2021 11:41 pm

Hello! I too am looking for this solution. I installed your code in the system/library/cart/cart.php

It made no difference. Am I doing this correctly. I have opencart 3.03

Thanks

Tim

Newbie

Posts

Joined
Wed Aug 12, 2020 7:17 am

Post by by mona » Fri Apr 09, 2021 1:07 am

timbits451 wrote:
Thu Apr 08, 2021 11:41 pm
Hello! I too am looking for this solution. I installed your code in the system/library/cart/cart.php

It made no difference. Am I doing this correctly. I have opencart 3.03

Thanks

Tim
There is no Opencart 3.03 ??
Try this Ensure you clear and refresh your modification caches

DISCLAIMER:
You should not modify core files .. if you would like to donate a cup of coffee I will write it in a modification for you.


https://www.youtube.com/watch?v=zXIxDoCRc84


User avatar
Expert Member

Posts

Joined
Mon Jun 10, 2019 9:31 am
Who is online

Users browsing this forum: jagall, moreduff and 263 guests