close ad
Databridge V2 with MySQLi support IS Now Available!
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues


Stock Management

Thread began 5/19/2011 9:58 am by hbibizadeh396670 | Last modified 5/20/2011 10:12 am by hbibizadeh396670 | 1442 views | 11 replies |


Stock Management


I have realised that I need some kind of stock management.

When the admin adds a product, they submit a quantity of stock in which they have to sell.

What I need to make my store do is reduce the quantity of stock each time a product is purchased.

For example, 14 should become 13 after purchase is complete.

In addition I am not sure how it would work on the product detail pages. If an items stock reaches 0, then the item should not be purchasable.

In the same way, if a products stock field is null then it has unlimited stock, and the Stock Management is not used. (Mainly For Digital Goods)

The last question I have is, if an item has a stock of 1, what happens if a user increases the quantity of the product to 2 or higher on the cart page.


Sign in to reply to this post

ijs174940Beta Tester

In the past when I have made carts that need this feature I added a dropdown box for the quantity with the loop limit set to the amount set in the admin, you could then use a simple if routine that shows "sorry out of stock" if the item reaches 0

On the admin side you could also set the stock limit to "no limit" so in the front end instead of a drop down you get a text field again controlled by a simple if statement

Regarding stock, after the cart has been completed you can add an update that subtracts the amount ordered from the appropriate column as in ($stock = ($stock - $purchased_amount)) but to do this you will need to set a unique Id for each transaction so if they leave the site to go to a payment gateway when they return the correct items can be found to update

Sign in to reply to this post


Thank you for your help and I appreciate your input.

I am using express checkout so the transaction or payment is always processed on my website and the transactions always have a unique ID.

This is exactly what I want to do, however I can’t figure out how to add the update behaviour that subtracts the amount ordered from the Stock Colum

($stock = ($stock - $purchased_amount))

Is this something I do in the eCart Object Calculations?

Thanks in advance.

Sign in to reply to this post

ijs174940Beta Tester

For this I would find it easier to add some simple PHP/MySQL but that just me.

1) You need to make sure the unique id get posted to the payment gateway and is also returned.

2) When the user arrives back at your site usually the "thank you order complete" you can add the code needed to that page.

3) Make a record set to filter the order from the orders db via the transaction Id sent back from the gateway, not the id for each item purchased.

4) Depending on how many matches or rows come back start a loop limited by the number of matches.

5) Inside the loop insert a update transaction eg..
($stock = ($stock - $purchased_amount))
$prod_unique_ref' = "#record set result for unique product id"
$updateSQL = sprintf("UPDATE products SET STOCK_LEVEL='$stock' WHERE Ref='$prod_unique_ref'");

6) This will go thru each item one by one and update the amount remaining.

There are more efficent ways of doing this but for just a simple update it does the job and it is easy to make and understand

Sign in to reply to this post




I am desperate to make this work but just don’t quite understand it.

I have several problems.

I am not completely sure how to create a loop, although I have tried. Details on what I have done are below.

Firstly, I am using express checkout so the payment transaction is always completed in my site.

When the transaction is complete I store information in two db files. Orders, OrderDetails.

Checkout works as follows, users add an item to their cart, click checkout, go to PayPal to enter details, return to my site, click checkout, payment is processed (Info inserted into database) and then redirects the user to the success page which has a order receipt.

I want to make the system subtract the quantity of each product purchased from the product stock value stored in my products table.

To do this I did:

On the checkout success page, I have a record set which joins the products, and order details tables.

I filter that based on the "eCart_OrderID" session variable.

Then and the very bottom of my code I tried to add your code (Not sure how to make a loop so not sure if this is correct):

($ProductStock = ($ProductStock - $DetailQuantity))
$DetailOrderID' = "#ProductID"
$updateSQL = sprintf("UPDATE products SET STOCK_LEVEL='$ProductStock' WHERE Ref='$DetailOrderID'");


ProductStock: Products table stock amount
DetailQuantity: Order Quantity for each product
DetailOrderID: Transaction ID
ProductID: Products ID

Could you please tell me what I am doing wrong?

Thank you for your help

Sign in to reply to this post

ijs174940Beta Tester

ok, can you paste the code from the success page so I can update the example I gave, the code was only an example it was not the exact code as this depends on your db cols.

Sign in to reply to this post


Thank you very much, its very kind of you.

Here is my file:

Attached Files
Sign in to reply to this post

ijs174940Beta Tester

Could you also send the page that updates the order db, as this page has no info for that in, with that I should be able to write it

Sign in to reply to this post


Sorry, yep sure I can

Here you go:


Attached Files
Sign in to reply to this post

ijs174940Beta Tester

Ok, will go thru it when I get back into the office tomorrrow, it is 9pm here and I am getting that look off the wife! the one that says "put the laptop down slowly and back away!"

Will have it sorted np

Sign in to reply to this post

Build websites with a little help from your friends

Your friends over here at WebAssist! These Dreamweaver extensions will assist you in building unlimited, custom websites.

Build websites from already-built web applications

These out-of-the-box solutions provide you proven, tested applications that can be up and running now.  Build a store, a gallery, or a web-based email solution.

Want your website pre-built and hosted?

Close Windowclose

Rate your experience or provide feedback on this page

Account or customer service questions?
Please user our contact form.

Need technical support?
Please visit support to ask a question





Ease of use


security code refresh image

We do not respond to comments submitted from this page directly, but we do read and analyze any feedback and will use it to help make your experience better in the future.

Close Windowclose

We were unable to retrieve the attached file

Close Windowclose

Attach and remove files

add attachmentAdd attachment
Close Windowclose

Enter the URL you would like to link to in your post

Close Windowclose

This is how you use right click RTF editing

Enable right click RTF editing option allows you to add html markup into your tutorial such as images, bulleted lists, files and more...

-- click to close --

Uploading file...