Several SQL server stored procedures are used in the shopping cart system.

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.