In the pricelookup.php ajax file I added this to the rsAddtoCartLookup recordset:
LEDstock - (SELECT Coalesce(SUM(LEDDetailQuantity),0) FROM LEDorder INNER JOIN LEDdetail ON LEDdetail.LEDDetailOrderID = LEDorder.LEDOrderID WHERE LEDOrderDate > LEDProductUpdateDate AND LEDDetailLEDid = LEDid) AS RemainingInventory
I then edited the code that creates the colon separate string, on the same page, from this:
<?php echo($row_rsAddToCartLookup['LEDprice']); ?>:<?php echo($row_rsAddToCartLookup['LEDproductcode']); ?>
...to this:
<?php echo($row_rsAddToCartLookup['LEDprice']); ?>:<?php echo($row_rsAddToCartLookup['LEDproductcode']); ?>:<?php echo($row_rsAddToCartLookup['RemainingInventory']); ?>
Checking with Firebug the price lookup ajax function now returns:
6.00:LWP0002:1997
...and this changes as I change selections in the drop-down menus so I'm confident that the price lookup ajax function is working correctly in that it is returning the correct product code, price and corresponding inventory.
So...in order to utilise this as part of the inventory control I've been trying to implement (ahem) I now need to capture/display the inventory value so that I can, for example, use it to hide the Add to Cart button if the value is 0.
I also need to prevent a user from entering a value in the quantity field, on both the Add to Cart and View Cart pages, that is higher than the available inventory.
Capturing/Displaying the inventory value returned by the price lookup ajax function
Is this where I need to change the updatePriceDisplay function? I've referenced the 2 index (naming it productStock) in the updatePriceDisplay function like so...
<script>
function updatePrice() {
silent_submit(document.getElementById("LEDCart_1_ATC"),updatePriceDisplay,"pricelookup.php",false);
}
function updatePriceDisplay() {
var colorVal = "NA";
var dimmerVal = "NA";
var sensorVal = "NA";
var priceInfo = (silent_form[1]).split(":");
if(priceInfo[1] !="") { document.getElementById("productCode").innerHTML = priceInfo[1]; }
if(priceInfo[0] !="") { document.getElementById("productPrice").innerHTML = "£" + priceInfo[0] + " inc. vat"; }
if(priceInfo[2] !="") { document.getElementById("productStock").innerHTML = priceInfo[2]; }
if (document.getElementById("LEDCart_1_Colour_Add").tagName == "SELECT") colorVal = document.getElementById("LEDCart_1_Colour_Add").options[document.getElementById("LEDCart_1_Colour_Add").selectedIndex].value;
if (document.getElementById("LEDCart_1_Dimmable_Add").tagName == "SELECT") dimmerVal = document.getElementById("LEDCart_1_Dimmable_Add").options[document.getElementById("LEDCart_1_Dimmable_Add").selectedIndex].value;
if (document.getElementById("LEDCart_1_Sensor_Add").tagName == "SELECT") sensorVal = document.getElementById("LEDCart_1_Sensor_Add").options[document.getElementById("LEDCart_1_Sensor_Add").selectedIndex].value;
if(priceInfo[0] == "") {
if (colorVal == "" || dimmerVal == "" || sensorVal == "") {
//document.getElementById("LEDCart_1_ATCButton").style.display = "none"
} else {
document.getElementById("productPrice").innerHTML = "<span class='red'>Currently Unavailable</span>";
document.getElementById("LEDCart_1_ATCButton").style.display = "none"
}
} else {
document.getElementById("LEDCart_1_ATCButton").style.display = "inline"
}
}
</script>
...but I'm not clear how I then display this on the Add to Cart page. Looking at how the other elements are displayed on the page, productCode for example, it uses an id like so...
<span id="productCode"><?php echo $row_rsPROD['LEDproductcode']; ?></span>
I would appreciate your help in understanding the theory here.
Preventing a user entering a value in the quantity fields that is higher than the available inventory
You have described adding a hidden form element to the page as follows:
<input type="hidden" name="remaingQuantity" id="remaingQuantity" value="0" />
Once I've established how to capture and display the inventory value that's returned by the price lookup ajax function, should I then use that value in the hidden form element...
<input type="hidden" name="remainingQuantity" id="remainingQuantity" value="<inventory value from price lookup ajax function>" />
This form element is what is binded to the AvailableQuantity column I've created in the eCart object and you'd then said to create a calculation as follows (this was in the "arguing" thread - http://www.webassist.com/forums/posts.php?id=34517) but I was wondering if that was a rogue " at the end?
abs([Quantity] > [AvailableQuantity])?[Quantity] = [AvailableQuantity]:"
Can I ask you to explain what the calculation above is doing though? What is abs, for example?
Thank you for your support and assistance.
NJ