Author Topic: Cart: Max-quantity warning doesn't show if you add more items than are in stock  (Read 1564 times)

kmeyer

  • Beginner
  • *
  • Posts: 31
If I have an item with 10 units in stock, and I set the quantity-input to 12 and click Add To Cart, the pop-up tells me it added 10xitem to the cart, it is a little hard to notice that I only got 10, when I asked for 12. After I have 10 in the cart, if I try to add 1 more, I get a very nice message like this:
"Max quantity of product XXX reached, new quantity in cart set to 10"
Is there a way to cause this message to display the first time around, when I first exceed the quantity in stock?

Similarly, when I view the cart, if I change the quantity to more than is in stock and click the Update Quantity In Cart icon, I get the Notice at the top of the page "Product quantity successfully updated", but the number stays at the maximum stock level. Here also I'd like the nice warning message to display instead.

My site is test.kurtmeyer.com, running VM 3.0.8 on Joomla 3.3.6.

I have "Action when a Product is Out of Stock" set to "Displays 'Notify Me' instead of 'Add To Cart' button".

stanislavus

  • Beginner
  • *
  • Posts: 30
Hi

did you manage to fix that?
Current specs:
Joomla! 2.5.9 PHP 5.6.3 VM  2.0.18a
Getting ready to upgrade (currently testing):
Joomla! 2.5.27 PHP 5.6.3 VM 3.0.2

kmeyer

  • Beginner
  • *
  • Posts: 31
No solution yet, anyone out there have any ideas how to fix this? Thanks.

siristru

  • Beginner
  • *
  • Posts: 11
  • VirtueMart Version: 2.x.x
Fix may be easy. Copy this file:

ROOT/components/com_virtuemart/sublayouts/addtocartbar.php

to:

ROOT/templates/your-template/html/com_virtuemart/sublayouts/addtocartbar.php

Then look for this:

            
Code: [Select]
<div class="quantity-box">
<input type="text" class="quantity-input js-recalculate" name="quantity[]"
data-errStr="<?php echo vmText::('COM_VIRTUEMART_WRONG_AMOUNT_ADDED')?>"
value="<?php echo $init?>" init="<?php echo $init?>" step="<?php echo $step?>" <?php echo $maxOrder?> />
</div>

Change it to:

            
Code: [Select]
<div class="quantity-box">
<input type="text" class="quantity-input js-recalculate" name="quantity[]"
data-errStr="<?php echo vmText::('COM_VIRTUEMART_WRONG_AMOUNT_ADDED')?>"
value="<?php echo $init?>" init="<?php echo $init?>" step="<?php echo $step?>" <?php echo 'max="' . ($product->product_in_stock $product->product_ordered) . '"'?> />
</div>

This part is crucial:

Code: [Select]
<?php echo 'max="' . ($product->product_in_stock $product->product_ordered) . '"'?>
It adds max parameter to quantity field. It calculates available quantity by subtracting ordered product quantity from quantity of products in stock.

Thanks to this no one will be able to add more products to cart than is really available  . No notifications are needed here :)
Само слога Славjанa спашава - Свуда пођи, својој кући дођи.

Studio 42

  • Contributing Developer
  • Sr. Member
  • *
  • Posts: 2743
  • Joomla & Virtuemart addon developper
    • Studio 42 - Virtuemart & Joomla extentions
  • VirtueMart Version: 2.6 &amp; 3.0.x.y
@siristru
Not exact answer.
If you have really a $maxOrder, this is never used.
so better solution should be :
if($product->product_in_stock - $product->product_ordered < $maxOrder) $maxOrder = $product->product_in_stock - $product->product_ordered;
to add before
Code: [Select]
<div class="quantity-box">
<input type="text" class="quantity-input js-recalculate" name="quantity[]"
data-errStr="<?php echo vmText::('COM_VIRTUEMART_WRONG_AMOUNT_ADDED')?>"
value="<?php echo $init?>" init="<?php echo $init?>" step="<?php echo $step?>" <?php echo $maxOrder?> />
</div>

Note: this is not right for shop not having stock check and should not be checked/modified, so it's not the right place to put this code


sandomatyas

  • Jr. Member
  • **
  • Posts: 167
I noticed that the original problem is still there in VM 3.2.4

As kmeyer wrote before let's assume you have a product, and the product_in_stock value is 10. You try to add 15 to cart, and you won't get any warning just a simple COM_VIRTUEMART_CART_PRODUCT_ADDED message where the quantity is 10 (instead 15!) and you got only 10 in the cart. After you try to add 1 or 10 or any you get the proper COM_VIRTUEMART_CART_PRODUCT_OUT_OF_QUANTITY message which you shold get also first time.
I tried to debug it a bit and found method checkForQuantities in class VirtueMartCart and there is this code part
Code: [Select]
if($productsleft>0){
$quantity = $productsleft;
$product->errorMsg = vmText::sprintf('COM_VIRTUEMART_CART_PRODUCT_OUT_OF_QUANTITY',$product->product_name,$quantity);
vmError($product->errorMsg);
}
Where $productsleft is 10, $quantity is 15 so $quantity will be 10 and according to this code I should get COM_VIRTUEMART_CART_PRODUCT_OUT_OF_QUANTITY message. I debugged it, this is the code part where $quantity is changing so I don't know why VM changes the message later

sandomatyas

  • Jr. Member
  • **
  • Posts: 167
anybody about this topic? It's very annoying in christmas sale :/