Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

determining prices on goods

Status
Not open for further replies.

meldrape

Programmer
May 12, 2001
516
US
I have an interesting situation. I'm using a canned software package for a shopping cart. I originally had figured out the individual price of an item quantity of 12 or over as such:

<%if acart(i,1)>=12 then
currentprice=(caseprice/12)
else
currentprice=currentprice
end if
%>

Of course this works. now the client tells me they don't want to break a case so I have to figure individual prices over the case price as the full price. i.e. if they order 13, then 12 will get the case price but the 13th item will be charged full price. How do I manipulate the code to handle this? Thoughts would be greatly appreciated. Thanks in advance.
 
Use the MOD operator.

13 mod 12 = 1.
15 mod 12 = 3.
25 mod 12 = 1.

Thanks,

Gabe
 
Thanks, Gabe. I'm not familiar with this but I just read some help on it. It's a great idea, but I'm not sure how to incorporate it into what I'm doing... Any thoughts? Thanks again.

 
I was jsut playing around but is the logic behind what you need. you could easily convert this over into the cart
<html>
<head>
<script language=&quot;vbscript&quot;>
function casePrice
dim varPrice1, varPrice2, varQty, varTotal
'if price is 12 use Price2
'else price > 12 then 12 = Price2 and up = reg Price1
'end if
varPrice1 = &quot;2.00&quot;
varPrice2 = &quot;1.00&quot;
varQty=cart.qty1.value
if varQty <= 11 then
varTotal = (varQty*varPrice1)
elseif varQty > 12 then
varTotal = ((12*varPrice2)+((varQty-12)*varPrice1))
end if
alert varTotal
end function
</script>
</head>
<body>
<form name=&quot;cart&quot;>
<input type=&quot;text size=&quot;2&quot; name=&quot;qty1&quot;>
<input type=&quot;button&quot; value=&quot;get price&quot; onClick=&quot;casePrice()&quot;>
</form>
</body>
</html> I help at your own risk, if I brake it sorry! But if I fixed it, let me know.[thumbsup2]
admin@onpntwebdesigns.com
 
run a check to see if the total is divisble by 12...if yes then amount/12 = number of cases charged at the case price...then

totalrequested-(#cases*12) = remainder to be priced at regular.

<%
dim cases, remainder, totalprice
if totalrequested > 12 then
cases=totalrequested/12
cases=cint(cases) 'take only the whole number
remainder = totalrequested - (cases*12)
totalprice = cases*pricepercase + remainder*unitprice
else
totalprice=totalrequested*unitprice
end if

hth

Bastien

There are many ways to skin this cat,
but it still tastes like chicken
 
Try something like this:

dim nWholeCase, nPieces, nPricePerCase, nPricePerPiece, nTotalPrice, nItemsOrdered

nItemsOrdered = 25
nPricePerCase = 10
nPricePerPiece = 2


nWholeCase = int(nItemsOrdered/12)
nPieces = nItemsOrdered mod 12

nTotalPrice = (nPricePerCase * nWholeCase) + (nPricePerPiece * nPieces)
 
Thanks so much to all of you. I will try these methods and let you know which one works best. Thanks again.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top