Here is how I have setup my checkout_success.php page to update my inventory database table upon successful transaction/purchase. I am using eCart 5.
1. In my inventory table, I have a column called "stockAmount". It is set up as int(11) default=1 null=yes. This column holds a numeric number that is representative of how many of the product I currently have in stock. In my case, I set the default to 1 since my website is selling rare books that only typically have 1 copy available at a time.
2. I edited my eCart Object to add a column for "stockAmount". Name: stockAmount, OutputType: number, Unique: no
3. I added the following calculation to my eCart Object. Name: subtractions, Output type: text, calculation formula: [stockAmount]-[Quantity]
4. On my checkout_success.php page, i made sure I had a require_once at the top to connect to my database as follows: <?php require_once('../Connections/myConn.php'); ?>
5. Then, directly before the image in the cart display on my checkout_success.php page, I added this code:
<!-- UPDATE INVENTORY CODE -->
$FinalStack = $hbCart->DisplayInfo("subtractions");
$idProduct = $hbCart->DisplayInfo("ID");
$varCurrentTimestamp = $_SERVER["REQUEST_TIME"];
$query_subtractions = "UPDATE hb_inventory SET stockAmount = $FinalStack, publish = 'N', featured = 'N', sold = 'Y', dateModified = $varCurrentTimestamp WHERE id_inventory = $idProduct" ;
$subtractions = mysql_query($query_subtractions, $hbConn) or die(mysql_error());
<!-- END UPDATE INVENTORY CODE -->
This effectively makes the following changes upon checkout success:
stockAmount is reduced by 1
publish is changed from Y to N unlisting the item from the website
featured is changes to N
sold is changed to N
dateModified is updated with the current unix timestamp
These changes are looped through all items in the order.
This code was adapted from Sade's code notes in this thread above. Thanks Eric/Sades for you help. I appreciate it.