Post by xoomit » Wed Aug 28, 2019 8:26 pm

Dear OC community,

whenever someone wants to purchase more than 99 of the same products in my shop the cart shows the "error_stock" message ("Products marked with *** are not available in the desired quantity or not in stock!"). This happens for all my products.

The quantity for my products is 9999 (or higher) and I have no options. It happens consistently for all my products.
I am using OC 3.0.2.0 my ThemeBurn (Burn Engine) theme together with some mods. However, I have no idea why this message gets triggered.

Does anyone have an idea how to trouble-shoot this?

Thanks & best,
Torge

New member

Posts

Joined
Tue Jun 19, 2012 6:09 am

Post by letxobnav » Wed Aug 28, 2019 9:01 pm

well, don't know the theme or your mods but in default 3.0.2.0 those messages are set when the product quantity in the DB is smaller that the quantity in the cart per line item, there are no other conditions for it.
That condition is tested in the cart class and the messages are set in the cart controller.

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 xoomit » Wed Aug 28, 2019 11:00 pm

Thanks for your help!
Even when I delete

Code: Select all

if ($option_value_query->row['subtract'] && (!$option_value_query->row['quantity'] || ($option_value_query->row['quantity'] < $cart['quantity']))) {
	$stock = false;
}							}
from the cart class the problem does still exist.
Also I noticed that in the DB product quantity is an int(4) field. Higher values do save and show in admin but could this lead to trouble?

This problem is driving me insane!

Cheers,
Torge

New member

Posts

Joined
Tue Jun 19, 2012 6:09 am

Post by letxobnav » Wed Aug 28, 2019 11:17 pm

there is this:

Code: Select all

									if ($option_value_query->row['subtract'] && (!$option_value_query->row['quantity'] || ($option_value_query->row['quantity'] < $cart['quantity']))) {
										$stock = false;
									}
and there is this:

Code: Select all

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

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 paulfeakins » Thu Aug 29, 2019 6:11 pm

xoomit wrote:
Wed Aug 28, 2019 8:26 pm
The quantity for my products is 9999
It sounds like you just don't want to use stock control? So you should be able to turn that off in the admin?

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


User avatar
Legendary Member
Online

Posts

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

Post by xoomit » Thu Aug 29, 2019 6:49 pm

re: letxobnav
Darn, I posted the wrong code, sorry. In fact even when I delete the lines you posted I still get the same error message.... :-\
I already search all my code (incl. extensions) for another "$stock = false" but there is no such line anywhere else. Any other idea on how to bugfix this?

re: paulfeakins
I do want to use this for most products but not all. For the product in question I set "subtract from stock" to no. Still getting the error.

New member

Posts

Joined
Tue Jun 19, 2012 6:09 am

Post by letxobnav » Thu Aug 29, 2019 7:19 pm

well, the cart class (the one in checkout) does this check:

Code: Select all

	if (!$this->cart->hasStock() && (!$this->config->get('config_stock_checkout') || $this->config->get('config_stock_warning'))) {
		$data['error_warning'] = $this->language->get('error_stock');
	} elseif (isset($this->session->data['error'])) {
		$data['error_warning'] = $this->session->data['error'];
	
and $this->cart->hasStock() looks like this:

Code: Select all

	public function hasStock() {
		foreach ($this->getProducts() as $product) {
			if (!$product['stock']) {
				return false;
			}
		}
		return true;
	}

so the individual cart items have a value stock which may be false and the function hasStock will return false if any of the cart items has stock set to false.

you could print those values in the error_log to see if any of them gets set to false.

Are you sure you are editing the right source?
You do not have additional sources in modifications?
Test it by adding error_log('testing'); somewhere to make sure.

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 xoomit » Wed Sep 04, 2019 5:13 pm

Dear letxobnav,

yes, I edited the correct code and still get the same message. Funny thing is: Everything works as expected. Meaning that when a product has an availability of 35 the checkout works with 35 and throws an error beginning at 36. This works correct for all products. Only when I put a product to 100 and above I always get the error message no matter what the availability of the specific product is.

Thanks & best,
Torge

New member

Posts

Joined
Tue Jun 19, 2012 6:09 am

Post by letxobnav » Wed Sep 04, 2019 5:51 pm

if you remove or comment out all instances of

Code: Select all

$stock = false;
in the cart class, you will not get the stock message.
If you still do, you are editing the wrong source.

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 xoomit » Tue Oct 20, 2020 9:28 pm

Hi all,

I finally come around to work on this again. I am still having this problem. However, I found that @letxobnav was right fun that there was a modification that lead to my changes not showing up. In fact, when I change the hasStock function in the cart library to this

Code: Select all

	public function hasStock() {
		return true;
	}
or delete the first ! from the following line in the checkout controller

Code: Select all

if (!$this->cart->hasStock() && (!$this->config->get('config_stock_checkout') || $this->config->get('config_stock_warning'))) {
The warning disappears. However, the item amount in the frontend is still shown in red and also the *** after the product name make clear that the message should be there (see attached image). This happens for both changes described above. So there is still another check somewhere.

I someone wants to take a look on my dev I'd really appreciate it. I'd gladly pay for it, too. Please answer here if interested.

Thanks & Best,
Torge

Attachments

Bildschirmfoto 2020-10-20 um 15.24.10.png

Bildschirmfoto 2020-10-20 um 15.24.10.png (247.55 KiB) Viewed 841 times


New member

Posts

Joined
Tue Jun 19, 2012 6:09 am

Post by sw!tch » Wed Oct 21, 2020 6:32 am

Depends on your theme.. But If you look at your cart twig.

You may see something like...

Code: Select all

{% if not product.stock %} <span class="text-danger">***</span> {% endif %}
Which relates to the products array in the checkout/cart controller index method.

Code: Select all

'stock'     => $product['stock'] ? true : !(!$this->config->get('config_stock_checkout') || $this->config->get('config_stock_warning')),
Again depends on your theme, looks custom so might be other stuff going on. You can check that line and modify as needed per your requirement.

Full Stack Web Developer :: Send a PM for Custom Work.
Backup and learn how to recover before you make any changes!


Active Member

Posts

Joined
Sat Apr 28, 2012 2:32 pm

Post by xoomit » Wed Oct 21, 2020 6:57 pm

Dear sw!tch,

thanks a lot for your reply. You are right in that when I edit the line accordingly the warnings in the product table disappear. However, this is the same outcome I could achieve by changing the setting in admin (that availability is just not checked anymore). The underlying problem is that the availability check does not work in my case. The hasStock() function somehow always returns false if the cart amount for any given product exceeds 100. Any idea on how to bugfix this?

Thanks & best,
Torge

New member

Posts

Joined
Tue Jun 19, 2012 6:09 am
Who is online

Users browsing this forum: No registered users and 68 guests