Post by mezzat22 » Thu Oct 08, 2020 5:02 am

Hello ,
Open cart version 2.3.0

I have a probuct with two options
first option value Size : S - M - L Subtract ( yes )
S has 7 quantity , M has 3 , L has 4
second Are you want special package : Yes - No ( Subtract No ) - Quantity ( 1 )

The issue :
when i add 7 pices of product with Size : S and option yes
i can also add another 7 with size S and option no without any warning
warning only show if i add 8 pieces with same size and same option ( yes )

Thank you

Newbie

Posts

Joined
Thu Oct 08, 2020 4:58 am

Post by paulfeakins » Thu Oct 08, 2020 5:22 pm

Why would you want some options to subtract stock and not others?

UK OpenCart Hosting | OpenCart Audits | OpenCart Support - please email info@antropy.co.uk


User avatar
Guru Member
Online

Posts

Joined
Mon Aug 22, 2011 11:01 pm
Location - London Gatwick, United Kingdom

Post by mezzat22 » Thu Oct 08, 2020 7:14 pm

the first option is sizes .. so that it should subtract
but the second option is packaging service .. so there is no stock for this option

the issue there is the product have 7 pieces of small size only but the user can add this product twice in cart with same option " small size " 7 pieces + 7 piece , once select packaging = yes the another one select no .
if user select packing yes .. the cart system Treat it like it's one product in the basket and user get stock error but if select one with yes , one with no .. cart treat that it is two different items !
so user can add 14 pieces of same size " small " but only small size has 7 quantity .. so how user can add 14 from this size !

Newbie

Posts

Joined
Thu Oct 08, 2020 4:58 am

Post by mezzat22 » Fri Oct 09, 2020 4:49 am

please help??
product options stock is going to negative values because of this issue !

Newbie

Posts

Joined
Thu Oct 08, 2020 4:58 am

Post by mezzat22 » Sun Oct 11, 2020 9:57 pm

???? Up

Newbie

Posts

Joined
Thu Oct 08, 2020 4:58 am

Post by letxobnav » Mon Oct 12, 2020 12:51 pm

This is because Default OC counts stock towards cart line items, not unique product ids, the product id + options become the unique identifier.
This is a problem for not mandatory options, the true options, mandatory (required) options are not options but specifications.

if you have 1 product A with non-mandatory options B & C, you can add to the cart:
1 product A without options
1 product A with option B
1 product A with option C
1 product A with both options B and C

these become separate cart line items.
i.e. you can order 4 x product A without stock warning while you only have 1.

we solved this by changing the cart class:

system/library/cart/cart.php
change:

Code: Select all

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

Code: Select all

				$ptotal = 0;
				foreach ($cart_query->rows as $cart_3) {
					if ($cart_3['product_id'] == $cart['product_id']) $ptotal = $ptotal + $cart_3['quantity'];
				}
				// Stock
				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.


User avatar
Expert Member

Posts

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

Post by mezzat22 » Mon Oct 12, 2020 5:17 pm

letxobnav wrote:
Mon Oct 12, 2020 12:51 pm
This is because Default OC counts stock towards cart line items, not unique product ids, the product id + options become the unique identifier.
This is a problem for not mandatory options, the true options, mandatory (required) options are not options but specifications.

if you have 1 product A with non-mandatory options B & C, you can add to the cart:
1 product A without options
1 product A with option B
1 product A with option C
1 product A with both options B and C

these become separate cart line items.
i.e. you can order 4 x product A without stock warning while you only have 1.

we solved this by changing the cart class:

system/library/cart/cart.php
change:

Code: Select all

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

Code: Select all

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

Thanks for your reply
but it not fix my issue
Image
Look to image
Option A is not subtract option so their subtract = No
But option B is subtract and " Large " size have 10 quantity .
but in the cart i added 10 quantities of " Large " size twice without stock alert! I completed order and stock changed from 10 to " -10" .

Newbie

Posts

Joined
Thu Oct 08, 2020 4:58 am

Post by letxobnav » Mon Oct 12, 2020 6:03 pm

Then you did no do it correctly or you allow checkout without stock.
That change has nothing to do with subtract or not, it adds the stock check on product_id iso line item meaning you can never checkout with more that the stock level of that product regardless of options.

go here:
https://www.crystallight.com.tw/co/en/l ... et-BR-8260
that has 10 in stock
add it to the cart with different options will give different cart line items but you can not checkout any combination which exceeds 10.

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 mezzat22 » Mon Oct 12, 2020 6:29 pm

letxobnav wrote:
Mon Oct 12, 2020 6:03 pm
Then you did no do it correctly or you allow checkout without stock.
That change has nothing to do with subtract or not, it adds the stock check on product_id iso line item meaning you can never checkout with more that the stock level of that product regardless of options.

go here:
https://www.crystallight.com.tw/co/en/l ... et-BR-8260
that has 10 in stock
add it to the cart with different options will give different cart line items but you can not checkout any combination which exceeds 10.
i am sure i did it correctly ???
and disable checkout without stock

i don't know what is the issue .. but i think that your code not working with 2 levels of options ( one is subtract and mandotry , the other is not subtracted and not mandatory )

Newbie

Posts

Joined
Thu Oct 08, 2020 4:58 am

Post by mezzat22 » Mon Oct 12, 2020 6:33 pm

Image

Look .. when one item quantity exceeded than 10 get error message!
i should get this alert when the total of the two items quantity is 10 .. not every item count 10!

Newbie

Posts

Joined
Thu Oct 08, 2020 4:58 am

Post by mezzat22 » Mon Oct 12, 2020 6:44 pm

Your code fix the non mandotory options scenario that mean : cart contain : product without options - product with non mandatory options .

but not fix my scenario

Cart have:
Product with option A ( not subtract - selected value : A ) & Option B ( selected value : A - subtract ( Quantity : 10 ) )
Product with option A ( not subtract - selected Value : B ) & Option B ( selected value : A - subtract ( Quantity : 10 ) )

expected : i should get stock error message when total pieces of selected value A of option B over 10 quantity

Newbie

Posts

Joined
Thu Oct 08, 2020 4:58 am

Post by letxobnav » Mon Oct 12, 2020 8:35 pm

i don't know what is the issue .. but i think that your code not working with 2 levels of options ( one is subtract and mandotry , the other is not subtracted and not mandatory )
That change checks the bare product stock against all cart line items regardless of options, regardless of subtract, regardless of mandatory.
So you did it 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 mezzat22 » Tue Oct 13, 2020 2:14 am

letxobnav wrote:
Mon Oct 12, 2020 8:35 pm
i don't know what is the issue .. but i think that your code not working with 2 levels of options ( one is subtract and mandotry , the other is not subtracted and not mandatory )
That change checks the bare product stock against all cart line items regardless of options, regardless of subtract, regardless of mandatory.
So you did it wrong.
it worked thanks
but there is an issue .. it make a conflict with another option values
when i added option B with another value " small " .. small has a 5 quantity but i can't add any quantity .. i get no available quantities .. i need to discrease " Large " quantity in the cart ... to add one or more of small :/

Newbie

Posts

Joined
Thu Oct 08, 2020 4:58 am

Post by by mona » Tue Oct 13, 2020 2:49 am

I am not sure if I am understanding this correctly.
What I am understanding is that you have product options of physical items and then a gift packaging type service which has no physical quantity.

Your issue is that it is counting each packaging as a quantity, which you don’t want and subtracting it and if it is 1 then it won’t allow you to checkout because of the stock status and then this kind of spirals off somewhere ..

It is getting most confusing because the numbers are not adding up and you are using A and B
Product T-Shirt - Global Stock 14
Option - Size
Size S - stock 7
Size M - stock 3
Size L - stock 4
Setting subtract yes
If you add more than 7 small, more than 3 medium or more than 4 large an error will be initialised.
No matter what you swop around, you can not have more than 14 in total or more than the sizes. This is correct.
Option - Packaging
Gift Packaging - stock 500
Setting subtract no

This should not produce an error or change the quantity available. and no matter if gift packaging is chosen for 5 size small and 2 size large it will be fine, but you will not be able to have more than 7 size small or 14 in total. As far as I am aware and you will have to provide your OC version, but a global figure is not required, you can not checkout with more than is set in options if you have set it that way.

Please explain the part of this I am not understanding.

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

Post by by mona » Tue Oct 13, 2020 3:28 am


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

Post by eddielai » Thu Feb 10, 2022 11:16 am

Thank you so much for sharing your code letxobnav

It works perfectly. Although need to do a bit modification for OC ver 1.5

Newbie

Posts

Joined
Fri Apr 20, 2012 10:42 am
Who is online

Users browsing this forum: No registered users and 3 guests