Custom User credit function for nopcommerce (1)

Source: Internet
Author: User
This function is a custom function, so it is not convenient to send all the code, and the function may have bugs. If you are interested, you can study it together, you can also visit www.nopchina.com or www.nopcommerce.org on the Chinese site or join the QQ Group 101675096 for discussion.
Nopcommerce is open source asp.net shop, from the end of 08 come out of the first version, as of the end of this article when the latest version is 1.40, interested students can go to http://www.nopcommerce.com to learn more.

Nopcommerce itself does not include the user credit function, at least 1.4 has not yet. It is basically the current user requirement and cannot be officially released. We can implement a simple user point, and the point history record is temporarily queried through SQL.

Let's take a look at the basic requirements and general procedures. First of all, this point is not as simple as buying something as thousands or even thousands of us. The point we define is a virtual currency, and the exchange rate is 1 with the main currency of the online store. Our goal is very simple, after each purchase, the user can add X yuan currency to the user's account. The name of this currency can be customized by the user. For example, the name of this online store is A $, that online store can be called Z $ or RMB. For the sake of simplicity, we stipulate that users can get 1% of the currency after each purchase (for better differentiation, the following should be replaced by "points ), and the points are deducted from the discount before calculation. For example, if a user buys something of 200 yuan, a discount of 10% is 20 yuan. In this case, the user needs to pay 180 yuan and the earned points are 180*1% = 1.8 yuan. Of course, this percentage can be changed at any time.

It should be noted that after a user places an order, the user does not get points immediately, but adds points to the user when the administrator updates the status after the online store receives the money. The administrator can also choose not to add points to this person, or add another amount of points to this person. The administrator can also directly modify the user points on the user management page. In order to deeply understand the concept of points, users must add points to email notifications after placing orders.

To sum up, the process we need is as follows:

1. the user places an order, checks out, and sends an email to notify the user that the order is successfully placed and the user can receive X Yuan points. This point can be used for the next shopping.
2. After the user pays, the Administrator adds points to the user.
3. the user obtains points and can use them next time.

We will first make necessary settings, including localization, global settings, and database modification.

Configuration-> all settings-> add new, add two settings, "RewardPercent" and "RewardPoint", respectively, as the percentage of points obtained and the currency symbol of points.

Content management-> localization-> add new, add two "Promotion. rewardMessageForGuest and Promotion. the RewardPointName is the prompt information of the guest user during checkout and the currency symbol after localization. In fact, this can be replaced by the point symbol above.

Then, we add a new table to the database.
Create table [dbo]. [Nop_RewardAudit] (
[RewardID] [int] IDENTITY (1, 1) not null,
[OrderID] [int] not null,
[RewardTime] [datetime] not null,
[Status] [nchar] (10) not null,
[Amount] [money] not null,
[RewardDetails] [nvarchar] (2000) NULL,
CONSTRAINT [PK_Nop_RewardAudit] PRIMARY KEY CLUSTERED
(
[RewardID] ASC
) WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, FILLFACTOR = 80) ON [PRIMARY]
) ON [PRIMARY]
This table is used as audit, but the audit interface has not yet been made, but the function is designed and can be added when it is free. Then add a money field to the customer table and order table respectively:

Alter table dbo. Nop_Customer SET (LOCK_ESCALATION = TABLE)

The order table is similar. I have no code. It should be okay if you add it yourself. Next, I have to modify several stored procedures for lauding. However, we strongly recommend that you change the stored procedures later to update users and insert orders.

Create procedure dbo. nop_mermerrewardpointcalculation
@ CID int,
@ OrderID int,
@ Points money,
@ Details nvarchar (2000)
AS
Update nop_customer
Set rewardPoint = rewardPoint + @ points
Where CustomerID = @ cID

Insert into Nop_RewardAudit
(OrderID, RewardTime, Status, Amount, RewardDetails)
Values
(@ OrderID, getdate (), ", @ points, @ details)

Also:
Create procedure dbo. Nop_CustomerSetRewardPoint
@ CID int,
@ OrderID int,
@ Points money,
@ Details nvarchar (2000)
AS
Update nop_customer
Set rewardPoint = @ points
Where CustomerID = @ cID

Insert into Nop_RewardAudit
(OrderID, RewardTime, Status, Amount, RewardDetails)
Values
(0, getdate (), ", @ points, @ details)
RETURN

Update user information:

Create procedure [dbo]. [Nop_CustomerUpdate]
(
@ CustomerId int,
@ CustomerGUID uniqueidentifier,
@ Email nvarchar (255 ),
@ PasswordHash nvarchar (255 ),
@ SaltKey nvarchar (255 ),
@ AffiliateID int,
@ BillingAddressID int,
@ ShippingAddressID int,
@ LastPaymentMethodID int,
@ LastAppliedCouponCode nvarchar (100 ),
@ LanguageID int,
@ CurrencyID int,
@ TaxDisplayTypeID int,
@ IsTaxExempt bit,
@ IsAdmin bit,
@ IsGuest bit,
@ IsForumModerator bit,
@ TotalForumPosts int,
@ Signature nvarchar (300 ),
@ AdminComment nvarchar (4000 ),
@ Active bit,
@ Deleted bit,
@ RegistrationDate datetime,
@ TimeZoneID nvarchar (200 ),
@ Username nvarchar (100 ),
@ AvatarID int,
@ RewardPoint money
)
AS
BEGIN

UPDATE [Nop_Customer]
SET
CustomerGUID = @ CustomerGUID,
Email = @ Email,
PasswordHash = @ PasswordHash,
SaltKey = @ SaltKey,
AffiliateID = @ AffiliateID,
BillingAddressID = @ BillingAddressID,
ShippingAddressID = @ ShippingAddressID,
LastPaymentMethodID = @ LastPaymentMethodID,
LastAppliedCouponCode = @ LastAppliedCouponCode,
LanguageID = @ LanguageID,
CurrencyID = @ CurrencyID,
TaxDisplayTypeID = @ TaxDisplayTypeID,
IsTaxExempt = @ IsTaxExempt,
IsAdmin = @ IsAdmin,
IsGuest = @ IsGuest,
IsForumModerator = @ IsForumModerator,
TotalForumPosts = @ TotalForumPosts,
[Signature] = @ Signature,
AdminComment = @ AdminComment,
Active = @ Active,
Deleted = @ Deleted,
RegistrationDate = @ RegistrationDate,
TimeZoneID = @ TimeZoneID,
Username = @ Username,
AvatarID = @ AvatarID,
RewardPoint = @ RewardPoint
WHERE
[CustomerId] = @ CustomerId

END

If Nop_OrderInsert is used, you don't need to add it again. It's not a problem to press the SP above.

This is the first release today. Continue sending the CS code tomorrow.

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.