That is, as a visitor to the site to log in as a cookie to store the shopping cart, and the identity of the logged-in user to enter the shopping cart information stored in the database, if the first to complete the shopping as tourists and then login to continue shopping, the cookies into the database;
The main stored procedures involved are as follows:
One: Members have been registered to add goods to the shopping cart function:
Copy Code code as follows:
/* @store_sum indicate the number of items to add, add and confirm whether the number of the cart is in excess of the quantity that will be added.
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
Two: The Shopping cart deletion function
Copy Code code as follows:
/* Type 1 is all deleted 0 o'clock just delete A/*
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