Skip to content

Instantly share code, notes, and snippets.

@raholland79
Created September 22, 2011 18:58
Show Gist options
  • Save raholland79/1235675 to your computer and use it in GitHub Desktop.
Save raholland79/1235675 to your computer and use it in GitHub Desktop.
function check_stock(what,partnum)
{
var soption;
var i;
var product_availability='<font color="green"><b>In Stock - </b></font><font color="black">Ships Next Business Day</font>';
var backordermode='0';
var avail_instock='<font color="green"><b>In Stock - </b></font><font color="black">Ships Next Business Day</font>';
var avail_outofstock='<font color="black">Out of Stock</font>';
var avail_backorder='<font color="black">Ships in 2-5 days</font>';
var optionfound=0;
if (inventoryarray1299.length==0) //if there is no advanced options, don't look for stock
{
return true;
}
else
{
for(i=0;i<inventoryarray1299.length;i++)
{
soption=inventoryarray1299[i];
field_array=soption.split("-");
//Dynamic Part for advanced options
if (typeof((idarray1299)) != "undefined")
{
soptionid=idarray1299[i];
aoprice=aopricearray1299[i];
if (field_array[0]==partnum)
{
if (soptionid != '')
changeid(soptionid);
if (aoprice != '0')
changeprice(aoprice);
}
}
if ((field_array[0]==partnum))
{
changecontent("product_inventory",field_array[1]);
if (eval(GetValue(what,"qty-0"))>field_array[1])
{
optionfound=optionfound+1;
if (backordermode==1)
{
changecontent("availability",avail_backorder);
return true;
optionfound=optionfound+1;
}
else
{
changecontent("availability",avail_outofstock);
alert("The options you selected are not currently available.");
optionfound=optionfound+2;
return false;
}
}
}
}
if (optionfound==0)
{
changecontent("availability",product_availability);
return true;
}
if (optionfound==1)
{
changecontent("availability",avail_instock);
return true;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment