That is, when logging on to a website as a tourist, the shopping cart is stored as a cookie, and the shopping cart information is stored in the database as a logon user, if the shopping is completed as a tourist and then the shopping continues, the cookies will be stored in the database;
The stored procedures are as follows:
1. added items to the shopping cart by logged-on members:
CopyCode The Code is as follows:/* @ store_sum indicates the quantity of items to be added. When adding the product, check whether the sum of the self-owned quantity and the quantity to be added in the shopping cart exceeds the inventory */
Create proc ncp_cart_add
(
@ Store_id int,
@ Store_sum Int = 1,
@ Member_id int
)
As
Declare @ amount int
Declare @ nowamount int
Begin
Select @ amount = (select amount from ncp_store where id = @ store_id)
If exists (select 1 from [ncp_cart] Where store_id = @ store_id and member_id = @ member_id)
Begin
Select @ nowamount = (select store_sum + @ store_sum from ncp_cart where store_id = @ store_id and member_id = @ member_id)
If @ nowamount> @ amount
Return 0
Else
Update [ncp_cart] Set store_sum = store_sum + @ store_sum, addtime = getdate () Where store_id = @ store_id and member_id = @ member_id
Return 1
End
Else
Begin
Select @ nowamount = (select store_sum from ncp_cart where store_id = @ store_id and member_id = @ member_id)
If @ nowamount> @ amount
Return 0
Else
Insert into [ncp_cart] (store_id, store_sum, member_id) values (@ store_id, @ store_sum, @ member_id)
Return 1
End
End
Go
Ii. delete a shopping cart
Copy code The Code is as follows:/* If type is set to 1, only one is deleted when all values are deleted */
Create procedure ncp_cart_del
@ Type Int = 0,
@ Store_id int,
@ Member_id int
As
Begin
If @ type = 0
Delete from [ncp_cart] Where store_id = @ store_id and member_id = @ member_id
Else
Delete from [ncp_cart] Where member_id = @ member_id
End
Go