stock control allowing negative numbers
Posted: Mon Jun 15, 2015 7:42 am
having a issue with an online cart. Items are being sold, being deducted of the stock amount but somehow more are being allowed to be sold and therfore getting getting minus numbers.
To start. I have a statement on the product detail page saying that if the stock is 0 dont show that product in the output
then in the checkout i have another statement that checks to quantity and if the request is more the user gets a prompt
in the head
i have a form value
then the error echoed
on the stock update page it is updated like
To start. I have a statement on the product detail page saying that if the stock is 0 dont show that product in the output
Code: Select all
website_Stock.Stock != 0
in the head
Code: Select all
$XC_invalidItems = "";
$XC_lim = "";
$iCol = array_search("Quantity",${$XCName}["ColNames"]);
$iSrc = array_search("Stock",${$XCName}["ColNames"]);
for ($iVal=0; $iVal<sizeof(${$XCName}["contents"][0]); $iVal++) {
if (${$XCName}["contents"][$iCol][$iVal] > ${$XCName}["contents"][$iSrc][$iVal]) {
if ($XC_invalidItems != "") $XC_invalidItems .= "-";
$XC_invalidItems .= (string) ($iVal+1);
if ($XC_lim != "") $XC_lim .= "-";
$XC_lim .= (string) ${$XCName}["contents"][$iSrc][$iVal];
}
}
if ($XC_invalidItems != "") {
$XC_invalidItems = "(".$XC_invalidItems.")";
$XC_lim = "(".$XC_lim.")";
$x_limErr = "The item(s) $XC_invalidItems exceed the available stock of $XC_lim";
}
Code: Select all
<input type="hidden" name="XC_Limit" value="<?php echo @$x_limErr; ?>" />Code: Select all
<?php if (isset($XC_limErr)) echo $XC_limErr; ?>Code: Select all
if ($paymentStatus == 'Completed') {
// UPDATE THE DATABASE
$oldStock = $row_rsUpdateStock['Stock'];
$stockSold = $row_rsUpdateStock['Quantity'];
$newStock = $oldStock - $stockSold;
$SKU = $row_rsUpdateStock['SKU'];
$UpdateQuery="UPDATE website_Stock SET Stock = '$newStock' WHERE website_Stock.SKU = '$SKU'";
$result = mysql_query($UpdateQuery);
}