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:
Copy codeThe Code is as follows:
/* @ Store_sum indicates the quantity of items to be added. When adding the item, check whether the sum of the existing quantity in the shopping cart and the quantity to be added 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 codeThe 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