Portal Engine Questions on portal engine and web parts.
Version 4.x > Portal Engine > Assign discount level to already created users View modes: 
User avatar
Member
Member
sandip.patil-acapteam - 6/19/2009 7:41:07 AM
   
Assign discount level to already created users
Hi
In discount level module: After creating new level, admin will assign this level by editing or adding new customer in 'Customer' tab.
My problem is that i have created one role called 'Partner institutes' in site and under that 2 user are there,How to assign this user this discount level.

User avatar
Kentico Support
Kentico Support
kentico_radekm - 7/1/2009 4:07:23 AM
   
RE:Assign discount level to already created users
Hello.

Do you want to make customers from all your old users, or only from the two in "Partners institute" role?
If for all, it you be possible to do using our API. I would send you guide how to achieve it. If for these two users only, unfortunately there is not some build-in feature, how to make user as customer, or how to add existing user into Customers section in your CMSDesk->Tools-> E-commerce.
I have consulted this issue with our e-commerce developer and he thinks that the quickest way will be, if these two users register themselves as customers on your e-commerce site (just put some product into cart and fill first name, user name,... Then do not need to finish order). Then you will see them under Customer tab and will be able to assign discount level to them. I am sorry for no more-native way how to achieve it.

Best Regards,
Radek Macalik

User avatar
Member
Member
charize - 4/1/2011 4:48:28 AM
   
RE:Assign discount level to already created users
Hi can you also send me the API on how to programatically set old users to a particular discount level.

Thanks :)

User avatar
Kentico Support
Kentico Support
kentico_zdenekc - 4/5/2011 2:04:49 PM
   
RE:Assign discount level to already created users
Hello,

You can set the customer's (not the User) discount level by getting the CustomerInfo object and setting its CustomerDiscountLevelID property.

That can be obtained like:

DiscountLevelInfo dli = DiscountLevelInfoProvider.GetDiscountLevelInfo("discountLevenCodeName");

After checking it for null -- if (dli != null) --
you can select older customers by comparing CustomerCreated datetime property in the where condition of the CustomerInfoProvider method GetCustomers like:

DataSet oldCustomers = CustomerInfoProvider.GetCustomers("CustomerCreated < '1/1/2010 00:00:00'", "");

Then, you can loop through this DataSet:
if (!DataHelper.DataSourceIsEmpty(oldCustomers) && (oldCustomers.Tables[0].Rows.Count > 1))
{
foreach (DataRow dr in oldCustomers.Tables[0])
{
ci = new CustomerInfo(dr);
ci.CustomerDiscountLevelID = dli.DiscountLevelID;
CustomerInfoProvider.SetCustomerInfo(ci);
}
}

And that should be all...

Regards,
Zdenek