Set Custom AffiliateId

For general questions and discussions specific to the AbleCommerce 7.0 Asp.Net product.
Post Reply
hbcondo
Lieutenant, Jr. Grade (LT JG)
Lieutenant, Jr. Grade (LT JG)
Posts: 28
Joined: Tue Jan 20, 2009 3:52 pm

Set Custom AffiliateId

Post by hbcondo » Fri Jan 23, 2009 12:39 am

According to the CommerceBuilder API, the Affiliate class appears to have two different ways to set an affiliate id,

1. Pass an integer through the Affiliate constructor
2. Assign an integer to the AffiliateId public property (set method is specified in documentation)

I tried both approaches by passing an Affiliate object using the Insert method of the AffiliateDataSource class and neither way uses the number I assign. When looking at the database table ac_Affiliates, it appears to use the identity (auto-generated) value. Is this by design? Am I not allowed to assign my own AffiliateId? Any information on this is appreciated. Thanks.

User avatar
AbleMods
Master Yoda
Master Yoda
Posts: 5170
Joined: Wed Sep 26, 2007 5:47 am
Location: Fort Myers, Florida USA

Re: Set Custom AffiliateId

Post by AbleMods » Fri Jan 23, 2009 6:49 am

hbcondo wrote:According to the CommerceBuilder API, the Affiliate class appears to have two different ways to set an affiliate id,

1. Pass an integer through the Affiliate constructor
2. Assign an integer to the AffiliateId public property (set method is specified in documentation)

I tried both approaches by passing an Affiliate object using the Insert method of the AffiliateDataSource class and neither way uses the number I assign. When looking at the database table ac_Affiliates, it appears to use the identity (auto-generated) value. Is this by design? Am I not allowed to assign my own AffiliateId? Any information on this is appreciated. Thanks.
You are allowed to assign an Affiliate, however you must keep your assignments within context.

The .Insert() method simply adds a new affiliate the table. It does not assign that affiliate code to the current context user. If there is an AffiliateId public parameter on a particular page, you can assign it within the code in that page. However if the code in that page does not save data, the assignment will be lost once the visitor navigates away from the page.

The affiliate must be assigned to the current user object browsing the site. So in your case, you would want to set Token.Instance.User.AffiliateId = <integer>. This will assign the affiliate Id you've designated to the current user context. It's a good idea to issue Token.Instance.User.Save() afterwards so that the affiliate assignment is persistent across their entire visit to your site.
Joe Payne
AbleCommerce Custom Programming and Modules http://www.AbleMods.com/
AbleCommerce Hosting http://www.AbleModsHosting.com/
Precise Fishing and Hunting Time Tables http://www.Solunar.com

hbcondo
Lieutenant, Jr. Grade (LT JG)
Lieutenant, Jr. Grade (LT JG)
Posts: 28
Joined: Tue Jan 20, 2009 3:52 pm

Re: Set Custom AffiliateId

Post by hbcondo » Fri Jan 23, 2009 1:09 pm

Thank you for the additional information. Yes, all I really want to do is create a new affiliate record in the database but use my own affiliateId value rather than the auto-generated one. I do not want the current user to be associated with the affiliate and I do not want the affiliate assignment to persist throughout the site so I don't think I want to use the Token instance.

In a nutshell, I have a list of users and I want each user to be an affiliate. Each user already has a unique id so I would like to use that same unique id as the affiliateid in AbleCommerce.

kastnerd
Commodore (COMO)
Commodore (COMO)
Posts: 474
Joined: Wed Oct 22, 2008 9:17 am

Re: Set Custom AffiliateId

Post by kastnerd » Fri Jan 23, 2009 2:11 pm

You looking for more of a referral then a affiliate id.

User avatar
AbleMods
Master Yoda
Master Yoda
Posts: 5170
Joined: Wed Sep 26, 2007 5:47 am
Location: Fort Myers, Florida USA

Re: Set Custom AffiliateId

Post by AbleMods » Fri Jan 23, 2009 2:58 pm

hbcondo wrote:Thank you for the additional information. Yes, all I really want to do is create a new affiliate record in the database but use my own affiliateId value rather than the auto-generated one. I do not want the current user to be associated with the affiliate and I do not want the affiliate assignment to persist throughout the site so I don't think I want to use the Token instance.

In a nutshell, I have a list of users and I want each user to be an affiliate. Each user already has a unique id so I would like to use that same unique id as the affiliateid in AbleCommerce.
Hmmm odd configuration. You won't be able to use the Affiliates table to do it since the table controls the AffiliateId value. At least not without modifying the table structure which I wouldn't recommend.

If you want each user to also be an "affiliate", can't you just tie whatever it is you want to the UserId instead of adding the extra layer of a go-between affiliateId value? It's simpler, less to manage and more compatible with how Able is designed.
Joe Payne
AbleCommerce Custom Programming and Modules http://www.AbleMods.com/
AbleCommerce Hosting http://www.AbleModsHosting.com/
Precise Fishing and Hunting Time Tables http://www.Solunar.com

hbcondo
Lieutenant, Jr. Grade (LT JG)
Lieutenant, Jr. Grade (LT JG)
Posts: 28
Joined: Tue Jan 20, 2009 3:52 pm

Re: Set Custom AffiliateId

Post by hbcondo » Fri Jan 23, 2009 4:11 pm

Sorry, I should have explained my configuration a little more. The user list is coming from a different database. The users in this list are not AbleCommerce users and they should not be logging into AbleCommerce. I just want them to be Affiliates of AbleCommerce.

Yes, modifying the SQL table will allow the use of a custom AffiliateId but as you mention, this isn't a good idea. According to the CommerceBuilder API, there is a set method (see attached screenshot) of the AffiliateId property so I really thought I could use this w/o any modifications to AbleCommerce.
AffiliateId_CommerceBuilderAPI.jpg
Btw, thanks for your prompt replies!

User avatar
jmestep
AbleCommerce Angel
Posts: 8164
Joined: Sun Feb 29, 2004 8:04 pm
Location: Dayton, OH
Contact:

Re: Set Custom AffiliateId

Post by jmestep » Sat Jan 24, 2009 8:17 am

The AffiliateID in the table is an autonumber field so you cannot enter a new number manually. You can use the Dataport utility on data from an Able 5 store and it will load the user and affiliate with the same id if you have assigned ids in the upload file and tell the dataport to renumber if necessary. It then turns off the autonumber in the tables and turns it back on when it is done. I was able to upload some test data and it assigned the same id to the user and affiliates table. If there was a user already there with the same id, it created a new one for what was uploaded.
I've attached the file that I used - it's a stripped down version of an Able 5 store export. Just make sure you select to import users and affiliates only.
Judy Estep
Web Developer
jestep@web2market.com
http://www.web2market.com
708-653-3100 x209
New search report plugin for business intelligence:
http://www.web2market.com/Search-Report ... -P154.aspx

User avatar
AbleMods
Master Yoda
Master Yoda
Posts: 5170
Joined: Wed Sep 26, 2007 5:47 am
Location: Fort Myers, Florida USA

Re: Set Custom AffiliateId

Post by AbleMods » Sat Jan 24, 2009 8:46 am

Ahhh ok that makes more sense, thank you.

I see why you thought you could set the AffiliateId now. The documentation is accurate, however it doesn't mention a key fact. It fails to tell you "NOTE: This is an auto-increment field and can only be set to an existing value in the table."

So you can indeed "set" the AffiliateId. But it can only be set to an AffiliateId value that already exists in the table.

Most (if not all of) Able's data classes are designed to use the Unique identifier field as a determination of whether the object being saved is "new" or "existing". If the AffiliateId is 0 when .Save() is called, the DAL assumes a new record and fires the SQL INSERT command. When the AffiliateId is any non-zero value, it assumes the record already exists because the SQL table is designed to auto-increment that same identifier. So the SQL UPDATE command is fired instead.

Once you get the hang of the design, it's really consistent everywhere else - so don't worry if it seems frustrating now. There's plenty of ways to work around something albeit some not as simple as others.

Judy's suggestion is a great one - she has far more experience with dataport than I do.
Joe Payne
AbleCommerce Custom Programming and Modules http://www.AbleMods.com/
AbleCommerce Hosting http://www.AbleModsHosting.com/
Precise Fishing and Hunting Time Tables http://www.Solunar.com

hbcondo
Lieutenant, Jr. Grade (LT JG)
Lieutenant, Jr. Grade (LT JG)
Posts: 28
Joined: Tue Jan 20, 2009 3:52 pm

Re: Set Custom AffiliateId

Post by hbcondo » Sun Jan 25, 2009 2:30 am

Wow, this is all really good feedback. I will definitely explorer these options and decide what solutions works best for us. I look forward to using other parts of the CommerceBuilder API.

Post Reply