Issue with Product Group Restrictions and Subscriptions
Issue with Product Group Restrictions and Subscriptions
I have a site in which users can purchase subscriptions. The subscriptions will give specific member prices and some products will be member only.
I created a User Group and gave it Authorized User permissions.
Next, I created a Subscription product and assigned it to the previously created subscription group.
Then I create a product and select Group Restrictions: Enabled. Only _Default appears in this box.
I go back to the subscription product that I created and the group has now disappeared from the drop down.
I created a User Group and gave it Authorized User permissions.
Next, I created a Subscription product and assigned it to the previously created subscription group.
Then I create a product and select Group Restrictions: Enabled. Only _Default appears in this box.
I go back to the subscription product that I created and the group has now disappeared from the drop down.
May
Re: Issue with Product Group Restrictions and Subscriptions
May,
I'm having some trouble following the steps to reproduce.
Question - You created a group and gave it Authorized User permission, then you say this group did not appear on the product editing page where you can enable group restrictions. Now, here is where I have to wonder if the group you created might have additional permissions set? When I tested this, the new group I created appears for the product. So, let's work through this issue first and then we can address any other problems.
Thanks
Katie
I'm having some trouble following the steps to reproduce.
Question - You created a group and gave it Authorized User permission, then you say this group did not appear on the product editing page where you can enable group restrictions. Now, here is where I have to wonder if the group you created might have additional permissions set? When I tested this, the new group I created appears for the product. So, let's work through this issue first and then we can address any other problems.
Thanks
Katie
Thank you for choosing AbleCommerce!
http://help.ablecommerce.com - product support
http://wiki.ablecommerce.com - developer support
http://help.ablecommerce.com - product support
http://wiki.ablecommerce.com - developer support
Re: Issue with Product Group Restrictions and Subscriptions
The user group I created only had Authorized permissions.
I went back today and tried the process over but didn't even get as far.
Here's what I did:
1. Create user group and give Authorized User Permissions
2. Create Product
Name: Test Membership
Price: 30.00
Shippable: no
3. Click Save and Edit
4.Add subscription plan:
Subscription Name: Test Membership
Subscriber Group: Group I created in step 1 is not there
I went back today and tried the process over but didn't even get as far.
Here's what I did:
1. Create user group and give Authorized User Permissions
2. Create Product
Name: Test Membership
Price: 30.00
Shippable: no
3. Click Save and Edit
4.Add subscription plan:
Subscription Name: Test Membership
Subscriber Group: Group I created in step 1 is not there
May
Re: Issue with Product Group Restrictions and Subscriptions
If you remove the 'Authorized User' permissions from the group, it should work.
I need to ask the dev team why this group has been restricted from the listing. There may be a reason, but I'm not sure as of yet.
If you use this group exclusively for subscriptions/member access to a product, then it shouldn't be a problem to remove the permission.
I need to ask the dev team why this group has been restricted from the listing. There may be a reason, but I'm not sure as of yet.
If you use this group exclusively for subscriptions/member access to a product, then it shouldn't be a problem to remove the permission.
Thank you for choosing AbleCommerce!
http://help.ablecommerce.com - product support
http://wiki.ablecommerce.com - developer support
http://help.ablecommerce.com - product support
http://wiki.ablecommerce.com - developer support
Re: Issue with Product Group Restrictions and Subscriptions
If I remove it from the Authorized User role, it is in the drop down under subscriptions.
However, if I go into a product and enable Group Restrictions it is not in the list box.
This is an important feature for this site, how can this be fixed? Thank you.
ETA: The code that brings up that list box actually says: LoadNonSubscriptionGroups
However, if I go into a product and enable Group Restrictions it is not in the list box.
This is an important feature for this site, how can this be fixed? Thank you.
ETA: The code that brings up that list box actually says: LoadNonSubscriptionGroups
May
Re: Issue with Product Group Restrictions and Subscriptions
This 'LoadNonSubscriptionGroups' (This is in the backend code) method should be modified (or a new method can be added) so that it should 'LoadNonAdminGroups' for the store irrespective of subscription/non-subscriptions groups, something like this:
One more update is required to make it work properly that is:
Locate the BindSubscriptionGroup() method on Admin/Products/EditSubscription.aspx.cs and replace with the below code:
Code: Select all
public IList<Group> LoadNonAdminGroups()
{
IList<Group> groups = NHibernateHelper.CreateCriteria<Group>()
.Add(Restrictions.Eq("Store.Id", AbleContext.Current.StoreId))
.AddOrder(Order.Asc("Name"))
.List<Group>();
// ALL NON ADMIN GROUPS
return groups.FindAll(grp => !grp.IsInRole(Role.AllAdminRoles)) as IList<Group>;
}
Locate the BindSubscriptionGroup() method on Admin/Products/EditSubscription.aspx.cs and replace with the below code:
Code: Select all
private void BindSubscriptionGroup()
{
SubscriptionGroup.Items.Clear();
SubscriptionGroup.Items.Add(new ListItem(string.Empty));
IList<CommerceBuilder.Users.Group> groupCol = GroupDataSource.LoadAll("Name");
CommerceBuilder.Users.Group group;
for (int i = groupCol.Count - 1; i >= 0; i--)
{
group = groupCol[i];
if (group.Roles.Count > 0 && group.IsInRole(Role.AllAdminRoles) || Group.DefaultUserGroupName.Equals(group.Name))
{
groupCol.RemoveAt(i);
}
}
SubscriptionGroup.DataSource = groupCol;
SubscriptionGroup.DataBind();
}
Re: Issue with Product Group Restrictions and Subscriptions
Thank you. Another issue I'm realizing though... I want everyone to see this product - but only members can purchase it. I figured on the front end I could just hide the add to cart button if the user doesn't have a subscription. Enabling group restrictions on the product and associated with the subscriber groups makes the products not show for anon and no subscribers.
May
Re: Issue with Product Group Restrictions and Subscriptions
I'm sorry May, but this will require a customization. The product membership feature limits who can see (and purchase) the product. The subscription group feature simply adds the purchaser to the applicable group and removes them when the subscription expires.I want everyone to see this product - but only members can purchase it
I would guess that the customization would be relatively simple though. You are just going to want to remove the code that decides to show products based on membership groups, and make it specific to the Add to Cart buttons.
Thank you for choosing AbleCommerce!
http://help.ablecommerce.com - product support
http://wiki.ablecommerce.com - developer support
http://help.ablecommerce.com - product support
http://wiki.ablecommerce.com - developer support
Re: Issue with Product Group Restrictions and Subscriptions
What I did was add a bit column to ac_products called isVisibleToAll. So far it works ok for the SQL queries:'
I saw it wasn't working for the featured products though so I'm looking at ProductRepository, GetFeaturedProducts.
I'm a bit lost with this syntax... how do I add "OR" ?
Code: Select all
if (user.UserGroups.Count > 0)
{
string groups = string.Join(",", (from ug in AbleContext.Current.User.UserGroups select ug.GroupId).ToList<int>().ToArray());
selectQuery.Append(" AND ( P.EnableGroups = 0 OR (EXISTS(SELECT PG.GroupId FROM ac_ProductGroups AS PG WHERE PG.ProductId = P.ProductId AND PG.GroupId IN (" + groups + ")) OR P.isVisibleToAll=1)) ");
}
else
{
selectQuery.Append(" AND (P.EnableGroups = 0 OR P.isVisibleToAll=1) ");
}
I'm a bit lost with this syntax... how do I add "OR" ?
Code: Select all
if (user.UserGroups.Count > 0)
{
Disjunction disjunction = new Disjunction();
int[] groupIds = (from ug in user.UserGroups select ug.GroupId).ToList<int>().ToArray();
DetachedCriteria secondCriteria = DetachedCriteria.For<ProductGroup>("PG")
.Add(Restrictions.EqProperty("PG.Product.Id", "P.Id"))
.Add(Restrictions.In("PG.Group.Id", groupIds))
.SetProjection(Projections.Property("PG.Group.Id"));
disjunction.Add(Restrictions.Eq("P.EnableGroups", false));
disjunction.Add(Subqueries.Exists(secondCriteria));
criteria.Add(disjunction);
}
else
{
criteria.Add(Restrictions.Eq("P.EnableGroups", false));
}
May
Re: Issue with Product Group Restrictions and Subscriptions
Disjunction takes the criterion and ORs them together. Use the disjunction to add an OR and then add it to criteria something like this for example:
Here, the above code will ORs the EnableGroups and isVisibleToAll and then added to the main criteria query i.e.
Hope this helps.
Code: Select all
disjunction.Add(Restrictions.Eq("P.EnableGroups", false));
disjunction.Add(Restrictions.Eq("P.isVisibleToAll", true));
criteria.Add(disjunction);
Code: Select all
P.EnableGroups = false OR P.isVisibleToAll = true
Re: Issue with Product Group Restrictions and Subscriptions
BTW, make customizations/updates keeping upgrades in mind. I suggest not to push yourself to a situation where the future upgrades get harder for you.
Re: Issue with Product Group Restrictions and Subscriptions
Thank you so much for your help. I'm trying not to make too many changes but unfortunately they are necessary.
May