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

rating

Updating stock from checkout success page

Thread began 3/08/2012 10:28 am by dallySP | Last modified 12/09/2013 1:52 pm by Jason Byrnes | 3228 views | 13 replies |

dallySP

Updating stock from checkout success page

Hi there,
Could you possibly tell me what code I would need to decriminate the stock level in my database by the ecart quantity field on arrival at the checkout success page, presuming there is one or more items in the cart?

Sign in to reply to this post

Jason ByrnesWebAssist

this will take some custom coding to accomplish. in the code examples i give, I am going to use the cart name eCart1, you will need to modify the cart code to match your cart object name.

it will require a recordset, an update behavior and an eCart loop around them.

first, you need to create a recordset to look up the current quntity, assuming the name of the table is "products", the ID columnn is name "productID", and the name of the stock column is "productStock", the recordset query would look like:

SELECT productStock FROM products WHERE productID = paramCartID

in the variables section create a new variable as:
name: paramCartID
type: integer
default value: -1
runTime value: $eCart1->DisplayInfo("ID")


then you need code to set a variable to hold the stock from the recordset minus the quantity in the cart, we'll use a get variable:

<?php $_GET['productStock'] = ($row_recordSetname['productStock'] - $eCart1->DisplayInfo("Quantity")); ?>

on the bindings panel, click the plus button and select URL Variable, set the name to productStock

Now you will need to add an update record behavior.

for the key column, select the productID column, for the valuer, click the lightning bolt and select the ID column from the cart object.

do not set a redirect.

on the second step of the update record wizard, select the productStock column, click the lightning bolt and select the productStock URL Variable.

you then need to add the cart loop around those pieces so the final code has this structure:

php:
<?php
while (!$eCart1->EOF())      {
?>
<product stock lookup recordset>
<set the productStock URL variable
<update record behavior>
<?php
  $eCart1
->MoveNext();
}
$eCart1->MoveFirst();
?>
Sign in to reply to this post

dallySP

Thats really helpful - thank you so much for your very comprehensive reply.
I've given it a go, but I think I've missed something or got some code snippet slightly wrong. My recordset is inventory. I'm looking up the record via the unique barcode (InvBarcode) and the Stock Field is InvInStock. I also called the url variable InvInStock. My code looks like this, but I'm getting a blank page in the browser. There are server behavious after this in the code, but when I strip this code chunk out the page still works, so I'm guessing its in here somewhere:

<?php
while (!$OkeefeCart->EOF()) {
?>
<?php
$BarcodeParam_rsInventory = "-1";
if (isset($OkeefeCart->DisplayInfo("Barcode"))) {
$BarcodeParam_rsInventory = (get_magic_quotes_gpc()) ? $OkeefeCart->DisplayInfo("Barcode") : addslashes($OkeefeCart->DisplayInfo("Barcode"));
}
mysql_select_db($database_cmsconn, $cmsconn);
$query_rsInventory = sprintf("SELECT * FROM inventory WHERE inventory.InvBarcode = %s", GetSQLValueString($BarcodeParam_rsInventory, "int"));
$rsInventory = mysql_query($query_rsInventory, $cmsconn) or die(mysql_error());
$row_rsInventory = mysql_fetch_assoc($rsInventory);
$totalRows_rsInventory = mysql_num_rows($rsInventory);?>
<?php $_GET['InvInStock'] = ($row_rsInventory['InvInStock'] - $OkeefeCart->DisplayInfo("Quantity")); ?>

<?php
// WA Application Builder Update
if (!$OkeefeCart->IsEmpty()) // Trigger
{
$WA_connection = $cmsconn;
$WA_table = "inventory";
$WA_redirectURL = "";
if (function_exists("rel2abs")) $WA_redirectURL = $WA_redirectURL?rel2abs($WA_redirectURL,dirname(__FILE__)):"";
$WA_keepQueryString = false;
$WA_indexField = "InvBarcode";
$WA_fieldNamesStr = "InvInStock";
$WA_fieldValuesStr = "".$_GET['InvInStock'] ."";
$WA_columnTypesStr = "none,none,NULL";
$WA_comparisonStr = "=";
$WA_fieldNames = explode("|", $WA_fieldNamesStr);
$WA_fieldValues = explode("|", $WA_fieldValuesStr);
$WA_columns = explode("|", $WA_columnTypesStr);

$WA_where_fieldValuesStr = "".$OkeefeCart->DisplayInfo("Barcode") ."";
$WA_where_columnTypesStr = "',none,''";
$WA_where_comparisonStr = "=";
$WA_where_fieldNames = explode("|", $WA_indexField);
$WA_where_fieldValues = explode("|", $WA_where_fieldValuesStr);
$WA_where_columns = explode("|", $WA_where_columnTypesStr);
$WA_where_comparisons = explode("|", $WA_where_comparisonStr);

$WA_connectionDB = $database_cmsconn;
mysql_select_db($WA_connectionDB, $WA_connection);
if (!session_id()) session_start();
$updateParamsObj = WA_AB_generateInsertParams($WA_fieldNames, $WA_columns, $WA_fieldValues, -1);
$WhereObj = WA_AB_generateWhereClause($WA_where_fieldNames, $WA_where_columns, $WA_where_fieldValues, $WA_where_comparisons );
$WA_Sql = "UPDATE `" . $WA_table . "` SET " . $updateParamsObj->WA_setValues . " WHERE " . $WhereObj->sqlWhereClause . "";
$MM_editCmd = mysql_query($WA_Sql, $WA_connection) or die(mysql_error());
if ($WA_redirectURL != "") {
if ($WA_keepQueryString && $WA_redirectURL != "" && isset($_SERVER["QUERY_STRING"]) && $_SERVER["QUERY_STRING"] !== "" && sizeof($_POST) > 0) {
$WA_redirectURL .= ((strpos($WA_redirectURL, '?') === false)?"?":"&").$_SERVER["QUERY_STRING"];
}
header("Location: ".$WA_redirectURL);
}
}
?>
<?php
$OkeefeCart->MoveNext();
}
$OkeefeCart->MoveFirst();
?>

Sign in to reply to this post

Jason ByrnesWebAssist

a blank page means a php error. you need to turn error reporting on.

add the following code at line 1:

php:
<?php

error_reporting
(E_ALL);
ini_set('display_errors','on');
?>




once we know the error, we can start troubleshooting it.

Sign in to reply to this post

dallySP

hmm - well its something in the recordset selection code. I've changed it so it selects the record by ID rather than barcode as I thought this might be giving me the problem, but its still occurring. This is the error report from my apache error log:
PHP Fatal error: Can't use method return value in write context in C:\\wamp\\www\\okeefe\\public_html\\checkout_success.php on line 358

and this is the code chunk to which it refers (line 358 being the 3rd line down):
<?php
$paramInvID_rsInventory = "-1";
if (isset($OkeefeCart->DisplayInfo("InvID"))) {
$paramInvID_rsInventory = (get_magic_quotes_gpc()) ? $OkeefeCart->DisplayInfo("InvID") : addslashes($OkeefeCart->DisplayInfo("InvID"));
}
mysql_select_db($database_cmsconn, $cmsconn);
$query_rsInventory = sprintf("SELECT * FROM inventory WHERE inventory.InvID=%s", GetSQLValueString($paramInvID_rsInventory, "int"));
$rsInventory = mysql_query($query_rsInventory, $cmsconn) or die(mysql_error());
$row_rsInventory = mysql_fetch_assoc($rsInventory);
$totalRows_rsInventory = mysql_num_rows($rsInventory);
?>

Sign in to reply to this post

Jason ByrnesWebAssist

ok, just before the recordset code block add this:

php:
<?php $_GET['Barcode'] = $OkeefeCart->DisplayInfo("Barcode"); ?>




then in the recordset, set the runtime value for the paramInvID parameter to use the Querystring variable:
$_GET['Barcode']

Sign in to reply to this post

Vinicios Nussemeyer

Updating stock from checkout success page

Hello dallySP

I followed all the steps of the post to update the inventory of the items in the db but could not.
I looked around the forum eCart but have not found the right solution. Use the eCart 5. You could do? I have to create inventory table in MySQL? Or I can just work with the column ProductStock in the table Products? I have to put the Recordset and the update on that page?
Please, if you have the solution send me an email please. I am a long time trying to do this and when I bought the eCart thought this function was native but found that it is not.
Thank you for your attention.

Sign in to reply to this post

Jason ByrnesWebAssist

you can use the product stock column of the products table for this.

where to put the code for this depends on the gateway you are using.

for most local checkout methods, this code can go on the confirm page. If you would like one on one help with accomplishing this, we can assist you in a screen sharing using a Premiere support appointment.

Sign in to reply to this post

toms016390756

Thanks! Jason




Sign in to reply to this post

Jason ByrnesWebAssist

you're welcome.

Sign in to reply to this post
loading

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