Products

Solutions

Resources

Partners

Community

About

New Community Website

Ordinarily, you'd be at the right spot, but we've recently launched a brand new community website... For the community, by the community.

Yay... Take Me to the Community!

Welcome to the DNN Community Forums, your preferred source of online community support for all things related to DNN.
In order to participate you must be a registered DNNizen

HomeHomeDNN Open Source...DNN Open Source...Module ForumsModule ForumsStoreStoreAdd Roles based on Products PurchasedAdd Roles based on Products Purchased
Previous
 
Next
New Post
12/24/2009 5:21 AM
 

I have seen requests for being able to add DNN Roles by Products posted in this forum before so I thought I would post this.   I added two triggers to the Store_Orders table and created a new table to store the ProductIDs (from the Store_Products table) and the RoleIDs (in the Roles table) that I want added for each product. There are no doubt better ways to code this than with triggers but I needed a quick and dirty solution.  This post is only intended for DBAs and SQL programmers with access to the DNN database and is just an idea that worked for me - not an out of the box solution.  I used Store (02.01.00) and DNN 04.07.00.

It is a cludgy solution at the moment since I need to manually add the product and role IDs to the table and if my products change I could be adding the wrong roles.  The triggers add the roles whenever the OrderStatus is changed to 7 (paid). I have also hard coded the portal ID to 0 since my site only has one portal.  The solution also uses triggers which can get you into trouble if you are not careful.  I have only flame tested the triggers but they seem to do what I need.  The triggers add roles for Host accounts as well which would not be needed.  Please only try this on a test system and create backups first.  Here is the code to create the two triggers and the extra table:

CREATE TABLE [dbo].[v05_Store_ProductRoles](
 [ProductRoleID] [int] IDENTITY(1,1) NOT NULL,
 [ProductID] [int] NOT NULL,
 [RoleID] [int] NOT NULL,
 CONSTRAINT [PK_v05_Store_ProductRoles] PRIMARY KEY CLUSTERED
(
 [ProductRoleID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]

GO

CREATE TRIGGER [dbo].[v05_Store_Orders_UT] ON [dbo].[Store_Orders]
FOR UPDATE
AS

IF  (SELECT OrderStatusID FROM INSERTED) = 7 --PAID
 BEGIN
  DECLARE @RC int
  DECLARE @PortalId int
  DECLARE @UserId int
  DECLARE @RoleId int
  DECLARE @EffectiveDate datetime
  DECLARE @ExpiryDate datetime
 
  DECLARE @myOrder int
  SELECT @myOrder = OrderID from INSERTED

  -- TODO: Set parameter values here.
  SELECT @PortalId = 0
  SELECT @UserId = UserID from INSERTED
 
  DECLARE ProductRoles CURSOR FOR
   SELECT RoleID FROM dbo.v05_Store_ProductRoles SPR
   inner join dbo.Store_OrderDetails SOD ON SPR.ProductID = SOD.ProductID
   WHERE SOD.OrderID = @myOrder
  OPEN ProductRoles
  FETCH NEXT FROM ProductRoles INTO @RoleID
  WHILE @@FETCH_STATUS = 0
  
  BEGIN
   EXECUTE @RC = [DotNetNuke].[dbo].[AddUserRole]
      @PortalId
     ,@UserId
     ,@RoleId
     ,@EffectiveDate
     ,@ExpiryDate
   FETCH NEXT FROM ProductRoles INTO @RoleID
  END
 
  CLOSE ProductRoles
  DEALLOCATE ProductRoles
 END
GO

CREATE TRIGGER [dbo].[v05_Store_Orders_IT] ON [dbo].[Store_Orders]
FOR INSERT
AS

IF  (SELECT OrderStatusID FROM INSERTED) = 7 --PAID
 
 BEGIN

  DECLARE @RC int
  DECLARE @PortalId int
  DECLARE @UserId int
  DECLARE @RoleId int
  DECLARE @EffectiveDate datetime
  DECLARE @ExpiryDate datetime
 
  DECLARE @myOrder int
  SELECT @myOrder = OrderID from INSERTED

  -- TODO: Set parameter values here.
  SELECT @PortalId = 0
  SELECT @UserId = UserID from INSERTED
 
  DECLARE ProductRoles CURSOR FOR
   SELECT RoleID FROM dbo.v05_Store_ProductRoles SPR
   inner join dbo.Store_OrderDetails SOD ON SPR.ProductID = SOD.ProductID
   WHERE SOD.OrderID = @myOrder
  OPEN ProductRoles
  FETCH NEXT FROM ProductRoles INTO @RoleID
  WHILE @@FETCH_STATUS = 0
  
  BEGIN
   EXECUTE @RC = [DotNetNuke].[dbo].[AddUserRole]
      @PortalId
     ,@UserId
     ,@RoleId
     ,@EffectiveDate
     ,@ExpiryDate
   FETCH NEXT FROM ProductRoles INTO @RoleID
  END
 
  CLOSE ProductRoles
  DEALLOCATE ProductRoles

 END
GO

 
New Post
3/3/2010 2:19 PM
 
Im going to test this on my server as this is what i need one question you add the product and roles in the table right?
 
New Post
3/3/2010 3:37 PM
 
Yes. Add the RoleID from the Roles table in DNN that you want to unlock along with the ProductID from the Store_Products table. You will need to update the table as you add or delete products or roles. Note that you can unlock as many roles as you want by simply listing multiple roles for the same product in the table. Whether you use PayPal IPN or the drop down list in the store to change the Status to Paid the trigger should still function because it operates at the table level. The portal is hard coded to 0 which is the root portal but if you run sub portals that will not work. I had this working in DNN 4.9 with Store 2.1.28 but I have had issues with PayPal IPN in version 5.2.1 of DNN. DNN 5.2.3 seems to have fixed the IPN issue along with the subscription link to PayPal in DNN itself. I am not done getting my site fully working on 5.2.3 yet but initial testing is promising. Please let me know how it goes?
 
New Post
3/15/2010 11:47 AM
 

I did all this but once the user pay on the return im getting this issue and i think its not finishing can you advice

Procedure or function 'AddUserRole' expects parameter '@CreatedByUserID', which was not supplied. The statement has been terminated.

 

 
New Post
3/15/2010 2:01 PM
 

Never Mind i Manage to fix it.

 I add the value to the triggers and works perfect i own you some beers. Here is my code.


CREATE TRIGGER [dbo].[v05_Store_Orders_UT] ON [dbo].[Store_Orders]
FOR UPDATE
AS

IF  (SELECT OrderStatusID FROM INSERTED) = 7 --PAID
 BEGIN
  DECLARE @RC int
  DECLARE @PortalId int
  DECLARE @UserId int
  DECLARE @RoleId int
  DECLARE @EffectiveDate datetime
  DECLARE @ExpiryDate datetime
  DECLARE  @CreatedByUserIDvarchar(20)
 
  DECLARE @myOrder int
  SELECT @myOrder = OrderID from INSERTED

  -- TODO: Set parameter values here.
  SET @CreatedByUSERID = (user_id())
  SELECT @PortalId = 0
  SELECT @UserId = UserID from INSERTED
 
  DECLARE ProductRoles CURSOR FOR
   SELECT RoleID FROM dbo.v05_Store_ProductRoles SPR
   inner join dbo.Store_OrderDetails SOD ON SPR.ProductID = SOD.ProductID
   WHERE SOD.OrderID = @myOrder
  OPEN ProductRoles
  FETCH NEXT FROM ProductRoles INTO @RoleID
  WHILE @@FETCH_STATUS = 0
  
  BEGIN
   EXECUTE @RC = [DotNetNuke].[dbo].[AddUserRole]
      @PortalId
     ,@UserId
     ,@RoleId
     ,@EffectiveDate
     ,@ExpiryDate
     ,@CreatedByUserID
   FETCH NEXT FROM ProductRoles INTO @RoleID
  END
 
  CLOSE ProductRoles
  DEALLOCATE ProductRoles
 END
GO

CREATE TRIGGER [dbo].[v05_Store_Orders_IT] ON [dbo].[Store_Orders]
FOR INSERT
AS

IF  (SELECT OrderStatusID FROM INSERTED) = 7 --PAID
 
 BEGIN

  DECLARE @RC int
  DECLARE @PortalId int
  DECLARE @UserId int
  DECLARE @RoleId int
  DECLARE @EffectiveDate datetime
  DECLARE @ExpiryDate datetime
  DECLARE @CreatedByUserID varchar(20)
 
  DECLARE @myOrder int
  SELECT @myOrder = OrderID from INSERTED

  -- TODO: Set parameter values here.
  SET @CreatedByUSERID = (user_id())
  SELECT @PortalId = 0
  SELECT @UserId = UserID from INSERTED
 
  DECLARE ProductRoles CURSOR FOR
   SELECT RoleID FROM dbo.v05_Store_ProductRoles SPR
   inner join dbo.Store_OrderDetails SOD ON SPR.ProductID = SOD.ProductID
   WHERE SOD.OrderID = @myOrder
  OPEN ProductRoles
  FETCH NEXT FROM ProductRoles INTO @RoleID
  WHILE @@FETCH_STATUS = 0
  
  BEGIN
   EXECUTE @RC = [DotNetNuke].[dbo].[AddUserRole]
      @PortalId
     ,@UserId
     ,@RoleId
     ,@EffectiveDate
     ,@ExpiryDate
     ,@CreatedByUserID
   FETCH NEXT FROM ProductRoles INTO @RoleID
  END
 
  CLOSE ProductRoles
  DEALLOCATE ProductRoles

 END
GO
 

 

 
Previous
 
Next
HomeHomeDNN Open Source...DNN Open Source...Module ForumsModule ForumsStoreStoreAdd Roles based on Products PurchasedAdd Roles based on Products Purchased


These Forums are dedicated to discussion of DNN Platform and Evoq Solutions.

For the benefit of the community and to protect the integrity of the ecosystem, please observe the following posting guidelines:

  1. No Advertising. This includes promotion of commercial and non-commercial products or services which are not directly related to DNN.
  2. No vendor trolling / poaching. If someone posts about a vendor issue, allow the vendor or other customers to respond. Any post that looks like trolling / poaching will be removed.
  3. Discussion or promotion of DNN Platform product releases under a different brand name are strictly prohibited.
  4. No Flaming or Trolling.
  5. No Profanity, Racism, or Prejudice.
  6. Site Moderators have the final word on approving / removing a thread or post or comment.
  7. English language posting only, please.
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out