Page 1 of 1
Having 100+ items in the basket gives "error_stock" message
Posted: Wed Aug 28, 2019 8:26 pm
by xoomit
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
Re: Having 100+ items in the basket gives "error_stock" message
Posted: Wed Aug 28, 2019 9:01 pm
by letxobnav
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.
Re: Having 100+ items in the basket gives "error_stock" message
Posted: Wed Aug 28, 2019 11:00 pm
by xoomit
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
Re: Having 100+ items in the basket gives "error_stock" message
Posted: Wed Aug 28, 2019 11:17 pm
by letxobnav
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.
Re: Having 100+ items in the basket gives "error_stock" message
Posted: Thu Aug 29, 2019 6:11 pm
by paulfeakins
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?
Re: Having 100+ items in the basket gives "error_stock" message
Posted: Thu Aug 29, 2019 6:49 pm
by xoomit
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.
Re: Having 100+ items in the basket gives "error_stock" message
Posted: Thu Aug 29, 2019 7:19 pm
by letxobnav
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.
Re: Having 100+ items in the basket gives "error_stock" message
Posted: Wed Sep 04, 2019 5:13 pm
by xoomit
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
Re: Having 100+ items in the basket gives "error_stock" message
Posted: Wed Sep 04, 2019 5:51 pm
by letxobnav
if you remove or comment out all instances of
in the cart class, you will not get the stock message.
If you still do, you are editing the wrong source.
Re: Having 100+ items in the basket gives "error_stock" message
Posted: Tue Oct 20, 2020 9:28 pm
by xoomit
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
Re: Having 100+ items in the basket gives "error_stock" message
Posted: Wed Oct 21, 2020 6:32 am
by sw!tch
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.
Re: Having 100+ items in the basket gives "error_stock" message
Posted: Wed Oct 21, 2020 6:57 pm
by xoomit
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