Forums / Templates, Stylesheets, Page Layout / Automatic Update of quantity in cart to available stock

Automatic Update of quantity in cart to available stock

Started by amirshawn80 on 11 Jan 2013, 10:00 AM · Views: 1,072

Results 1 to 3 of 3
11 Jan 2013, 10:00 AM
#1
amirshawn80 avatar

amirshawn80

New Zenner

Join Date:
Jun 2010
Posts:
27
Plugin Contributions:
0

Automatic Update of quantity in cart to available stock

Hi,

I've been searching for hours looking for a way to auto update the quantity of products in the cart. Let say I have 16 items available in stock, if someone adds 20 to their cart, I would like their quantity to automatically change to 16. There has to be some way of doing that, right? If nothing else, how can I show the amount of units in stock on the shopping cart page so the customer at least knows how many are available for purchase.

Thanks in advance!

Amir

20 Jan 2013, 2:36 AM
#2
amirshawn80 avatar

amirshawn80

New Zenner

Join Date:
Jun 2010
Posts:
27
Plugin Contributions:
0

Re: Automatic Update of quantity in cart to available stock

I wasn't able to get the automatic updating figured out, but I was able to set this up so at least it's showing the quantity available on the shopping cart page. My solution was to open /includes/modules/pages/shopping_cart/header_php.php look for:

  $showFixedQuantityAmount = $products[$i]['quantity'] . zen_draw_hidden_field('cart_quantity[]', $products[$i]['quantity']);

add this directly above that code:

$stockAvailable = zen_get_products_stock($products[$i]['id']);

look for this code:

 $productArray[$i] = array('attributeHiddenField'=>$attributeHiddenField,

add this line right after that line:

'stockAvailable'=>$stockAvailable,

Open the file tpl_shopping_cart_default.php

look for this code:

<th scope="col" id="scQuantityHeading"><?php echo TABLE_HEADING_QUANTITY; ?></th>

add this code directly below that:

<th scope="col" id="scAvailableQuantity"><?php echo TABLE_HEADING_AVAIL_QUANTITY; ?></th>

look for this code:

echo $product['quantityField'] . '<br /><span class="alert bold">' . $product['flagStockCheck'] . '</span><br /><br />' . $product['showMinUnits'];
  }
?>
       </td>

add this code directly below that:

 ```
<td class="availableQuantity"> <?php echo $product['stockAvailable'];?></td> ```

finally open up your english.php file either in your /includes/languages folder or in your template override folder add this definition in there:

define('TABLE_HEADING_AVAIL_QUANTITY', 'Available Qty');

Next I changed the Mark product out of stock alert in admin/configuration/stock to say this:

adjust to available quantity

I hope that helps anyone else who is trying to figure out how to show the quantity in stock on the shopping cart page. It would be nice if it would auto adjust to that quantity, but at least this way when someone has too many of an item in their cart they can at least see how many they can buy right there from the cart instead of having to go back to the product page.

20 Jan 2013, 2:59 PM
#3
ajeh avatar

ajeh

Oba-san

Join Date:
Sep 2003
Location:
Ohio
Posts:
62,757
Plugin Contributions:
1

Re: Automatic Update of quantity in cart to available stock

Thanks for the update that you have this working and for posting the detailed steps in how you have accomplished this to help others ... :smile:

Linda McGrath
If you have to think ... you haven't been zenned ...

**Did YOU buy the Zen Cart Team a cup of coffee and a donut today? Just click here to support the Zen Cart Team!!**

Are you using the latest? Perhaps you've a problem that's fixed in the latest version: [Upgrade today!]
Officially PayPal-Certified! Just click here

Try our Zen Cart Recommended Services - Hosting, Payment and more ...
Signup for our Announcements Forums to stay up to date on important changes and updates!