News:

Support the VirtueMart project and become a member

Main Menu

Out of stock products getting purchased

Started by anantmaks, December 23, 2017, 09:45:21 AM

Previous topic - Next topic

anantmaks

VirtueMart Version: 3.2.10
To replicate the issue go to Admin->Configuration->shopfront and set "Action when a Product is Out of Stock" to "Do not Display Product" or "Displays 'Notify Me' instead of 'Add To Cart' button". Then go to Admin->Products and create/edit a product, reach 'Product Status' tab and and set 'In stock' to 50, also set 'Minimum Purchase Quantity' to any higher value, like in this case 100. Now go to store front end and try to purchase this product, this product is available to be bought with quantity 100.
The highest priority should be of 'In Stock' when any availability check being made. 
Anant Garg
Ghaziabad, India

jenkinhill

Kelvyn
Lowestoft, Suffolk, UK

Retired from forum life November 2023

Please mention your VirtueMart, Joomla and PHP versions when asking a question in this forum

anantmaks

ok I checked and it is behaving same with version 3.2.12 as well. The product is order-able out of stock limit
Anant Garg
Ghaziabad, India

Jörgen

#3
Hello

I have tested this with VM 3.2.10 and used in stock = 1 and min order quantity = 5.

The Buy now button is active this is not good. The pop up tells that there is only only 1 item added, but there are actually 5 items put into cart.

Regards

Jörgen @ Kreativ Fotografi
Joomla 3.9.18
Virtuemart 3.4.x
Olympiantheme Hera (customized)
This reflects current status when viewing old post.

Jörgen

#4
Hello

I have taken a closer look at this and found the following fix for the problem:

In the file components/com_virtuemart/sublayouts/addtocartbar.php, replace line 78
if (($stockhandle == 'disableit' or $stockhandle == 'disableadd') and ($product->product_in_stock - $product->product_ordered) < 1) { ?>

with this

      // JH 2017-12-24 Check for min order level as minimum order qty, if not set, test for 1
       if ($product->min_order_level > 0) {
  minOrderLevel = $product->min_order_level;
}
else {
  $minOrderLevel = 1;
}
if (($stockhandle == 'disableit' or $stockhandle == 'disableadd') and ($product->product_in_stock - $product->product_ordered) < $minOrderLevel) { ?>


This is not an official bug fix, but there will probably bee one, coming soon.

It is important to notice that this is a file that is very often overridden. Please check Your template file :
templates/your-active-template/html/com_virtuemart/sublayouts/addtocartbar.php

merry x-mas

Jörgen @ Kreativ Fotografi
Joomla 3.9.18
Virtuemart 3.4.x
Olympiantheme Hera (customized)
This reflects current status when viewing old post.

anantmaks

Also a check on $product->min_order_level should be made, as when admin stores any string value in that parameter it reflects that. So it should be type-casted when accessed as (int)$product->min_order_level; or should be type-casted right at the moment of saving
Anant Garg
Ghaziabad, India

Jörgen

You are absolutely correct.
Making the typecast when saving the min_order_level might break some shops using float or otherwise. But at line 50 just before:
if(!empty($product->min_order_level) and $init<$product->min_order_level){

add this typecast:
$product->min_order_level = (int) $product->min_order_level;

regards

Jörgen @ Kreativ Fotografi
Joomla 3.9.18
Virtuemart 3.4.x
Olympiantheme Hera (customized)
This reflects current status when viewing old post.

Studio 42

Hi, i think that the value is never checked on save, if you enable php debug, and check your log file, you have many errors, because value are not set or not the right type.
Problem is that Virtuemart redirect after save(as most joomla core component) so noone complain about this. I already reported such problem for some month, but this was simply ignored and the answer was to not use PHP debug, but this is a pain when you develop a plugin and ajax, because in this case you see all this bugs.
A new example is this on cloning product
Notice: Undefined property: TableProducts::$_tempHash in /MYSITE/administrator/components/com_virtuemart/helpers/vmtable.php on line 1088
For your other problem about $minOrderLevel, this is not so easy to fix, because minOrderLevel is not refreshed on adding to cart.
For eg if you have 20 in stock, add 15 in cart and add 10 in cart you have no warning before add to cart because 20 is min$minOrderLevel, so the stock level have to be returned on add to cart in the json response to update it, it's the only way to always have valid min stock quantity.

Jörgen

Hello Patrick
Thanks for Your reply. But with the new I do not see how this can happen. If I have 20 in stock and minorderlevel is 20 and I can not add 15. Not what I can see.
If we make the sceanrio 9 in stock, 6 minorderlevel and try to order 2 times 6 we get a message the second time that only three items have been placed in the cart, 6 + 3 = 9. A third try gives the message that there are a maximum of 9 items in the cart.

It is maybe not perfect, but now You can not put more items in the cart than available and if minorderevel is greater than stock at the first try You do not see an activated Buy now button.

Improvements are of course welcome.

regards

Jörgen @ Kreativ Fotografi
Joomla 3.9.18
Virtuemart 3.4.x
Olympiantheme Hera (customized)
This reflects current status when viewing old post.

Milbo

#9
Quote from: Studio 42 on December 28, 2017, 00:25:08 AM
Hi, i think that the value is never checked on save, if you enable php debug, and check your log file, you have many errors, because value are not set or not the right type.
Problem is that Virtuemart redirect after save(as most joomla core component) so noone complain about this. I already reported such problem for some month, but this was simply ignored and the answer was to not use PHP debug,
,
I really wonder, why you think, that it make sense to lie and telll bullshit.

and you have really a problem with TIME! When you was in the team,.. years ago, I said there are more important things todo, than to remove notices. But this is more than 5 years ago. And I told often the last 2 years, that we are interested to know any error, even it is just a notice, or just a deprecated note.

So absolutly nonsense. It is really strange, that you work with VM, but you cannot stop to blame VM for whatever.

And as you said yourself, due the redirect, we just do not see the notices. So why you cannot just talk about in a friendly manner without directly doing the childish blame game.


and back to the topic

you are all NOOBS, sorry to say that.  This is soo ***obscenity removed*** annoying. I tell you know a lesson, which pupils learn after 3 weeks PHP.


An html form is ALWAYS STRING. . You CANNOT give an INTEGER within a form!


Again for the beginners here. When you have an html form and you store it,.. it will transfered ALWAYS AS STRING. okey? YES? always string! You can cast it for storing, and? what will it bring? nothing, because the db already cast it for you automatically. So,. .and when we read a line in the db, we get it back as,... tada STRING.

So it makes absolutly no sense todo a cast while storing, besides the effect that it can be more safe. It makes a bit sense to cast it to Int, when LOADING it.

But actually, I must admit. Theoretically it is clear. All the time. The POST or GET is just a String. It took me years to get completly aware of it and to understand all consequences. It is also the reason that our "booleans" use always empty string "","0", or "1". Never true, false, FALSE, and so on.
Should I fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/

Milbo

Quote from: anantmaks on December 26, 2017, 09:42:28 AM
Also a check on $product->min_order_level should be made, as when admin stores any string value in that parameter it reflects that. So it should be type-casted when accessed as (int)$product->min_order_level; or should be type-casted right at the moment of saving

No, else you destroy the deriving stuff. Empty is not 0 !
Should I fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/

Milbo

So the fix of Jörgen is correct for the layout, but we need also to fix the check in the cart (the real evil error).

the function private function checkForQuantities in the cart helper does the check in the cart. I just removed the "return false" in the min, max, step checks and moved the

if ($stockhandle!='none' && $stockhandle!='risetime') {

at the end. So it looks like this now


...
$checkForDisable = false;
if ($stockhandle!='none' && $stockhandle!='risetime') {
$checkForDisable = true;
}

// Check for the minimum and maximum quantities
$min = $product->min_order_level;
if ($min != 0 && $quantity < $min){
$quantity = $min;
$errorMsg = vmText::sprintf('COM_VIRTUEMART_CART_MIN_ORDER', $min, $product->product_name);
vmInfo($errorMsg,$product->product_name);
if (!$checkForDisable) return false;
}

$max = $product->max_order_level;
if ($max != 0 && $quantity > $max) {
$quantity = $max;
$errorMsg = vmText::sprintf('COM_VIRTUEMART_CART_MAX_ORDER', $max, $product->product_name);
vmInfo($errorMsg,$product->product_name);
if (!$checkForDisable) return false;
}

$step = $product->step_order_level;
if ($step != 0 && ($quantity%$step)!= 0) {
$quantity = $quantity + ($quantity%$step);
$errorMsg = vmText::sprintf('COM_VIRTUEMART_CART_STEP_ORDER', $step);
vmInfo($errorMsg,$product->product_name);
if (!$checkForDisable) return false;
}

// Check to see if checking stock quantity
if ($checkForDisable) {

$productsleft = $product->product_in_stock - $product->product_ordered;
.....


Should I fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/

Studio 42

Max, i explained for some weeks, that cloning give errors.
This is not seen if you disable debug and standard clone(without using ajax) do not show this because you are redirect.
If you want i can do for each error a new post, but if i have no answer, why ?
Of course, in a live shop, you disable PHP debug, and no one see this error because Virtuemart cloning always redirect.
Why you mean i lie ? I Have no interest, i'm perhaps the only one to see this bugs, because i use Vm models and not redirect after because i use ajax response and no redirect with php displaying all errors(not to see VM errors, but to debug my extensions).

I have another bug, you see in the edit product action bar : cloning, product child, add note. This should be hidden for new product. But when i report a problem, you say a lie or it's ignored, so why should i report each time bugs ?

Milbo

Quote from: Studio 42 on January 02, 2018, 13:34:39 PM
If you want i can do for each error a new post, but if i have no answer, why ?
Then we try to find it together.

QuoteWhy you mean i lie

I meant
QuoteI already reported such problem for some month, but this was simply ignored and the answer was to not use PHP debug,
We do not ignore it and the fast solution is to disable the notes.

Quote from: Studio 42 on January 02, 2018, 13:34:39 PM
I have another bug, you see in the edit product action bar : cloning, product child, add note. This should be hidden for new product. But when i report a problem, you say a lie or it's ignored, so why should i report each time bugs ?
No, this is a misunderstanding. As I said, years ago we had more important things than deprecated notes and things like this, but that is long time ago.
Should I fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/

Studio 42

removing in action bar : cloning, product child, add note,  only change is to check for the product_id is empty.
This simply trouble a customer, and i had to explain him. it's not a developer and don't understand why some action can be done but give bad result.
Of course it's not a real bug, but it's more professional to remove button giving trouble.