Post by SXGuy » Wed Jun 15, 2016 4:13 am

HI Guys.

One thing that has always bugged me is if you set the qty of one of your product options, but on the product page you change the qty of the product to more than the amount of stock for that option, it still adds to cart, you are only notified that the qty is greater than what is in stock, when you try to check out.

Is there a way to stop someone adding a product to the cart if the qty they select is greater than the qty for the option they also select?

i.e if my product has Option A with a qty of 2, and i select option A and change product qty to 3, how can i change it so no product gets added to cart, and a warning appears stating that the qty is to high?

Active Member

Posts

Joined
Sun Nov 08, 2009 2:07 am

Post by straightlight » Wed Jun 15, 2016 10:02 am

Which OC version are you using?

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
Opencart.com Administrator / Quality Assurance Analyst / Programmer / Opencart Tester


Legendary Member

Posts

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

Post by SXGuy » Wed Jun 15, 2016 12:18 pm

OC2. I forget which sub version but I'm guessing it shouldn't matter.

Active Member

Posts

Joined
Sun Nov 08, 2009 2:07 am

Post by straightlight » Wed Jun 15, 2016 7:24 pm

SXGuy wrote:OC2. I forget which sub version but I'm guessing it shouldn't matter.
It does, actually. You can either find the version build on the root index.php file or at the bottom of the admin footer-end.

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
Opencart.com Administrator / Quality Assurance Analyst / Programmer / Opencart Tester


Legendary Member

Posts

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

Post by SXGuy » Wed Jun 15, 2016 7:40 pm

2.1.0.2 cheers

Active Member

Posts

Joined
Sun Nov 08, 2009 2:07 am

Post by straightlight » Wed Jun 15, 2016 8:00 pm

Would it be possible to provide your store URL?

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
Opencart.com Administrator / Quality Assurance Analyst / Programmer / Opencart Tester


Legendary Member

Posts

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

Post by SXGuy » Wed Jun 15, 2016 8:03 pm

Www.sportsquestltd.com you will need to navigate to active schools and clubs link then click on shop. You will see each product football kit has size options. Select the blue and yellow kit. Size medium has 2 in Stock. But more than 2 can be added. It's only when you check your basket it tells you that you have to many. This is a normal way opencart works. I want to disable adding to. Cart if qty is greater than stock.

Active Member

Posts

Joined
Sun Nov 08, 2009 2:07 am

Post by cyclops12 » Thu Jun 16, 2016 1:33 am

What about one of these

Expert Member

Posts

Joined
Sun Sep 27, 2015 1:10 am

Post by SXGuy » Thu Jun 16, 2016 1:49 am

None of those work. They all centre around the product being out of stock. It isn't.

I just want to disable being able to add more than what's available using stock control for options. By default you can add it to the cart but it will only tell you to change the quantity when you view basket or checkout.
I have found a mod which stops you from adding a product to the cart if you select a qty greater than what's in Stock. But I need to adapt it to include option qty also.
Prob an easy job once I take a look at the code. I just wondered if a mod had already been written. I'm guessing not as this thread would have been answered by now.

Active Member

Posts

Joined
Sun Nov 08, 2009 2:07 am

Post by grgr » Thu Jun 16, 2016 1:58 am

My stock Stock Check and Max Quantity extension deals with this.

http://www.opencart.com/index.php?route ... n_id=13703

Image Image Image Image Image Image Image Image


User avatar
Active Member

Posts

Joined
Mon Mar 28, 2011 4:08 pm
Location - UK

Post by SXGuy » Thu Jun 16, 2016 3:52 am

grgr wrote:My stock Stock Check and Max Quantity extension deals with this.

http://www.opencart.com/index.php?route ... n_id=13703
Thank you, i would consider your mod, however i wouldnt mind trying to figure this out for myself.

Failing that, would you consider creating a mod that just deals with option quantity for a small fee? reason being, i dont need to set a maximum or minimum quantity and so the extra code will just bloat things.

I realise i need something like

Code: Select all

if ($quantity > $option_value['quantity']) {
					$json['error']['quantity'] = sprintf($this->language->get('error'), $option_value['quantity']);
				}
however, i cant seem to find the area to place it, i also think i may need to expand on $quantity, perhaps something like

Code: Select all

 if (isset $this->request->post['quantity]
but again, im unsure where i need to place it.

Active Member

Posts

Joined
Sun Nov 08, 2009 2:07 am

Post by straightlight » Thu Jun 16, 2016 4:30 am

The code above would be incorrect for the latest version of OC. Your original topic request was about disabling the add-to-cart, not to return an error message if the product quantity would be higher than the product option value quantity.

In catalog/controller/checkout/cart.php file,

find:

Code: Select all

foreach ($product_options as $product_option) {
replace with:

Code: Select all

$i = 0;
			
			foreach ($product_options as $product_option) {
				if (!empty($product_option['product_option_value']) && is_array($product_option['product_option_value'])) {
					$j = 0;
					
					foreach ($product_option['product_option_value'] as $product_option_value) {
						if ((int)$j == (int)$i && isset($product_option_value['quantity']) && (int)$quantity > (int)$product_option_value['quantity']) {
							$json['error']['quantity'] = sprintf($this->language->get('error_quantity'), $product_option_value['quantity']);
						}
						
						++$j;
					}
				}
				
				++$i;
			}
In catalog/view/theme/<your_theme>/template/product/product.tpl file,

find:

Code: Select all

if (json['error']['recurring']) {
add above:

Code: Select all

if (json['error']['quantity']) {
					$('.breadcrumb').after('<div class="alert alert-danger">' + json['error']['quantity'] + '<button type="button" class="close" data-dismiss="alert">&times;</button></div>');
				}
In catalog/language/en-gb/checkout/cart.php file,

add:

Code: Select all

$_['error_quantity'] = 'The product quantity cannot exceed the product option value quantity!';
Last edited by straightlight on Tue Jun 21, 2016 8:04 pm, edited 2 times in total.

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
Opencart.com Administrator / Quality Assurance Analyst / Programmer / Opencart Tester


Legendary Member

Posts

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

Post by SXGuy » Thu Jun 16, 2016 4:37 am

Thanks for the help. Really appreciate it. I'll give it a go.

Active Member

Posts

Joined
Sun Nov 08, 2009 2:07 am

Post by straightlight » Thu Jun 16, 2016 4:52 am

Code edited above due to the captcha.

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
Opencart.com Administrator / Quality Assurance Analyst / Programmer / Opencart Tester


Legendary Member

Posts

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

Post by Hannah00 » Thu Jun 16, 2016 12:15 pm

straightlight wrote:Would it be possible to provide your store URL?
Thank you @straightlight, best answer ever. ;D

Opencart migration & upgrade tool


User avatar
New member

Posts

Joined
Wed May 04, 2016 5:09 pm

Post by SXGuy » Tue Jun 21, 2016 12:11 am

im afraid the code doesnt quite work how it should.

It seems to only allow max qty of the option which has the least amount.

Example

Option A 20pcs
Option B 10pcs
Option C 5pcs

Will only allow a max qty of 5.

Ive even tried it like this

Code: Select all

                if (!empty($product_option['product_option_value']) && is_array($product_option['product_option_value'])) {
               foreach ($product_option['product_option_value'] as $product_option_value) {
                  if (isset($this->request->post['quantity']) && ((int)$this->request->post['quantity'] > $product_option_value['quantity'])) {
				$quantity = $product_option_value['quantity'];
			} else {
			$quantity = $this->request->post['quantity'];
			}

               }
            }
This automatically changes to cart total, to what should be the max qty total of the option selected, however the same happens, it changes the cart total to which ever option has the lowest qty.

So im guessing it has something to do with these lines

Code: Select all

                if (!empty($product_option['product_option_value']) && is_array($product_option['product_option_value'])) {
               foreach ($product_option['product_option_value'] as $product_option_value) {
Any advice?

Active Member

Posts

Joined
Sun Nov 08, 2009 2:07 am

Post by straightlight » Tue Jun 21, 2016 2:18 am

One point I didn't covered on my last post above was the order totals versus this modification code. It is possible that you might have an order total module that resets the calculations compared to what has been modified above in order to affect your total. If so, it would be unpredictable to tell which one would be recalculating the product option value quantity until you find the source of the installed module located in your catalog/model/total folder or your catalog/controller/total folder.

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
Opencart.com Administrator / Quality Assurance Analyst / Programmer / Opencart Tester


Legendary Member

Posts

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

Post by SXGuy » Tue Jun 21, 2016 3:08 am

i did have some code which displays the option qty along side the option names, but even if i remove that, the issue is still the same.

Active Member

Posts

Joined
Sun Nov 08, 2009 2:07 am

Post by straightlight » Tue Jun 21, 2016 7:04 pm

In your admin settings for product minimum quantity, did you also adjusted it accordingly compared to the code I posted above? Both balance has to fit.

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
Opencart.com Administrator / Quality Assurance Analyst / Programmer / Opencart Tester


Legendary Member

Posts

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

Post by SXGuy » Tue Jun 21, 2016 7:28 pm

You didn't mention anything about adjusting min qty? Product min qty is set to 1. But isn't that irrelevant? Product qty is 12. All qty options add up to 12, both product and options subtract stock. So it's correct as far as I can see. What would changing min qty achieve? A product may have one option with qty of 2 and one option to with qty of 5. That's a total of 7 for main product. Min qty for main product would be 1?

Active Member

Posts

Joined
Sun Nov 08, 2009 2:07 am
Who is online

Users browsing this forum: No registered users and 15 guests