View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

eCart solution to inventory control

Thread began 7/02/2009 1:01 pm by info374483 | Last modified 7/06/2009 1:53 pm by info374483 | 1628 views | 8 replies

CraigRBeta Tester

Inventory control for eCart4

It's been a few weeks since I did this, but I'm sure I can pick it up again.

I did this for paypal standard payments, but I think the same principles would apply whatever payment gateway is used.

What I can certainly do is give you a few pointers to help you achieve your objective. (Using php/mysql)

My Method...

To ensure that the stock level was updated ONLY when the order was completed and successful payment made, I run the update query on the stock table on the paypal IPN page.

In a nutshell, on my IPN page, there is a section which checks for a valid IPN, which then adds rows to the paypal payment and paypal cart tables.

In this section I run two additional queries...

the first loops through the cart items and sets the new stock qty for each item
the second updates the order status on my orders table.

In this instance, I don't need to worry about colours and sizes, so stock qty is held in my items table.
For your example, you would be updating a stock table

the query I used to update the inventory was something like this...

<?php

// initialize flag
$OK = false;
// create database connection
$conn = dbConnect('admin');

// Now update stock level in tblitem

for ($i = 1; $i <= $num_cart_items; $i++) {
$itemnumber = "item_number".$i;
$quantity = "quantity".$i;

$sqlstock = 'UPDATE tblitem SET StockQty = StockQty - ? WHERE ItemID = ?' ;


// initialize prepared statement
$stmt = $conn->stmt_init();
if ($stmt->prepare($sqlstock)) {
// bind parameters and execute statment
//$var1 = 'StockQty - '.$_POST[$quantity];
//$var2 = $_POST[$itemnumber];

$var1= $_POST[$quantity];
$var2 = $_POST[$itemnumber];



$stmt->bind_param('ii', $var1, $var2);
$OK = $stmt->execute();
}
}
// redirect if successful or display error
if ($OK) {
$result = ' Stock Level Updated ';
$result = nl2br($result);
}
else {
$result = $stmt->error;
}

?>

This uses the unique itemID to update the stock qty, you would need to change the parameters to filter for colour and size

I hope this helps.

Regards

Craig

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

Content

rating

Layout

rating

Ease of use

rating

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...