close ad
 
Important WebAssist Announcement
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

Combining an onchange event, for product lookup, with inventory control?

Thread began 5/29/2014 8:49 am by Nathon Jones Web Design | Last modified 6/06/2014 9:30 am by Nathon Jones Web Design | 4650 views | 33 replies

Nathon Jones Web Design

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

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