Bloody hell Bruce, what's going on, you guys are releasing features and you've already thought about what's required. Outrageous behaviour
.
.
/***********************************************************************
*
* getSectionStockSuspend - Call our server script to determine the real time stock
* levels of the products in the given section
* When the page is previewed from the desktop (within EC) we do not want to make
* server calls for RTS levels. Therefore in this case we are passing in the
* list of stock monitored products and their offline stock level in sProdRefs and
* sStockList parameters.
*
* Input: sURL - the ajax script URL to call
* sSID - the section ID list to be passed in to the ajax script
* sProdRefs - list of the products with stock monitoring on in this section
* sStockList - the stock level of the products in the list above
* sSuspendLevel - current suspend offset of the products in the list
*
* Actinic handle negative suspend levels by adding them to the stock level
* this code removes the compensation from the displayed value. In order to handle
* multiple negative suspend values, this code accepts an array of suspend levels.
*
* The suspend levels always come from the page not from the server.
*
************************************************************************/
function getSectionStockSuspend(sURL, sSID, sProdRefs, sStockList, sSuspendLevel)
{
var mapStockByRef = {};
var mapStockByLevel = sSuspendLevel;
//
// In case of preview use passed in data
//
if (sURL.indexOf("file://") == 0)
{
var arrProds = sProdRefs.split("|");
var arrStock = sStockList.split("|");
for (var i = 0; i < arrProds.length; i++)
{
var aRef = arrProds[i].split("!");
var sKey = aRef[aRef.length - 1];
mapStockByRef[sKey] = arrStock[i];
}
updateStockDisplayLevel(mapStockByRef,mapStockByLevel);
}
else
{
var ajaxRequest = new ajaxObject(sURL);
ajaxRequest.callback = function (responseText)
{
mapStockByRef = responseText.parseJSON();
updateStockDisplayLevel(mapStockByRef,mapStockByLevel);
}
ajaxRequest.update("ACTION=GETSECTIONSTOCK&SID="+sSID, "GET");
}
}
/***********************************************************************
*
* updateStockDisplayLevel - dynamically update the DOM tree depending on stock levels
*
* Input: mapStockByRef - product ref to stock level map
* mapStockByLevel - offeset to compensate for suspend setting
*
************************************************************************/
function updateStockDisplayLevel(mapStockByRef,mapStockByLevel)
{
//
// For each product reference set the stock level and enable/disable
// the controlling DIV tags in the page source
//
var arrStockElems= getStockNodes();
for (var nIndex = 0; nIndex < arrStockElems.length; nIndex++)
{
var aRef = arrStockElems[nIndex].id.split("_");
var sProdRef = aRef[aRef.length - 1];
var sIDStart = arrStockElems[nIndex].id.substring(0, arrStockElems[nIndex].id.length - sProdRef.length - 1);
if (mapStockByRef[sProdRef] != null)
{
// single value passed from web page.
var iStockLevel = mapStockByRef[sProdRef] - mapStockByLevel;
//
// The stock level
//
if (sIDStart == 'StockLevel')
{
if ( iStockLevel <= 0)
{
iStockLevel = 0;
}
arrStockElems[nIndex].innerHTML = iStockLevel;
}
//
// Out of stock
//
if (sIDStart == 'EnableIfOutOfStock')
{
if (iStockLevel <= 0)
{
arrStockElems[nIndex].style.visibility = "visible";
arrStockElems[nIndex].style.display = "inline";
}
else
{
arrStockElems[nIndex].style.visibility = "hidden";
arrStockElems[nIndex].style.display = "none";
}
}
if (sIDStart == 'RemoveIfOutOfStock')
{
if (iStockLevel <= 0)
{
arrStockElems[nIndex].innerHTML = "";
}
}
//
// In stock
//
if (sIDStart == 'EnableIfInStock')
{
if (iStockLevel > 0)
{
arrStockElems[nIndex].style.visibility = "visible";
arrStockElems[nIndex].style.display = "inline";
}
else
{
arrStockElems[nIndex].style.visibility = "hidden";
arrStockElems[nIndex].style.display = "none";
}
}
if (sIDStart == 'RemoveIfInStock')
{
if (iStockLevel > 0)
{
arrStockElems[nIndex].innerHTML = "";
}
}
//
// Generic flag to indicate ajax call went fine
//
if (sIDStart == 'EnableIfStockOk')
{
arrStockElems[nIndex].style.visibility = "visible";
arrStockElems[nIndex].style.display = "inline";
}
}
}
}
<actinic:block if="%3cactinic%3avariable%20name%3d%22RealTimeStockEnabled%22%20%2f%3e%20%26%26%20%3cactinic%3avariable%20name%3d%22DisplayRealStockLevel%22%20%2f%3e" > <span id="RemoveIfOutOfStock_<actinic:variable name="ProductReference" selectable="false" />" class="ActinicRTS" > <span id="EnableIfStockOk_<actinic:variable name="ProductReference" selectable="false" />" class="ActinicRTS" style="visibility: hidden; display: none;"> <span id="StockLevel_<actinic:variable name="ProductReference" selectable="false" />" class="ActinicRTS" style="display: inline;"></span> in stock. </span> </span> <span id="EnableIfOutOfStock_<actinic:variable name="ProductReference" selectable="false" />" class="ActinicRTS" style="visibility: hidden; display: none;"> <strong><span class="actrequired"><br /><Actinic:Variable Name="OutOfStock"/></span></strong> </span> </actinic:block>
<script language="javascript" type="text/javascript">
function displayStock()
{
var sProdRefs = "";
var sStockList = "";
var sSuspendLevel = "1000";
<actinic:block if="%3cactinic%3avariable%20name%3d%22IsPreviewMode%22%20%2f%3e" >
sProdRefs = "<actinic:variable name="RTSProductsInThisSection" selectable="false" />";
sStockList = "<actinic:variable name="RTSStocksInThisSection" selectable="false" />";
</actinic:block>
getSectionStockSuspend('<actinic:variable name="StockScriptCGIURL" selectable="false" />', '<actinic:variable name="SectionID" selectable="false" />', sProdRefs, sStockList,sSuspendLevel);
}
AttachEvent(window, "load", displayStock);
</script>
, but the stock levels change.
Comment