<!--#include file="conn.asp"-->
<!--#include file="ajax_cart_set.asp"-->
<%
productId=request.form("productId")
colorId=request.form("colorId")
sizeId=request.form("sizeId")
num=request.form("quantity")

'总库存
set rs_s=server.CreateObject("adodb.recordset")
rs_s.open "select * from com_books where id="&productId,conn,1,1
danjia=rs_s("shopxphyjia")
danjifeng=rs_s("jifeng")
'kucun=rs_s("kucun")
shopxpptname=rs_s("titlecn")
rs_s.close
set rs_s=nothing

set rs_s=server.CreateObject("adodb.recordset")
rs_s.open "select * from com_PCR where proid="&productId&" and  colorid="&colorId&"  and  sizeid="&sizeId,conn,1,1
kucun=rs_s("kucun")
rs_s.close
set rs_s=nothing
if kucun<=0 then
'response.write "你选购的商品“"&shopxpptname&"”暂时缺货不能放到购物车里，请选购其它商品！"
response.write "{""result"":""success"",""data"":{""inventory"":0,""isEnough"":false}}"
response.end
end if

if num<>"" then
Quatity= cint(num)
else
Quatity=1
end if
if Quatity<=0 then
Quatity=1
end if

set rs=server.CreateObject("adodb.recordset")
rs.open "select shopxpptid,username,productcount,zonger,jifeng from shopxp_action where username='"&username&"' and shopxpptid="&productId&" and pro_color_id="&colorId&" and pro_size_id="&sizeId&" and zhuangtai=9",conn,1,3

	if kucun < Quatity then
	'response.write "你选购的商品只剩下“"&kucun&"”份！"
	response.write "{""result"":""success"",""data"":{""inventory"":"&kucun&",""isEnough"":false}}"
	response.end
	end if
	zonger=danjia*Quatity
	jifeng=danjifeng*Quatity 
	rs("zonger")=zonger
	rs("jifeng")=jifeng
	rs("productcount")=Quatity
	rs.update
	
	response.write "{""result"":""success"",""data"":{""promoRuleDescription"":""无优惠"",""actualSalePrice"":"&zonger&",""isEnough"":true}}"
	
	rs.close
	set rs=nothing
%>