Access Levels - How to hide ?

  • Posts: 455
  • Thank you received: 35
1 year 5 months ago #346497

-- HikaShop version -- : 4.6.2
-- Joomla version -- : 3.10.11
-- PHP version -- : 7.4.33
-- Browser(s) name and version -- : Chrome

Hi guys,
as discussed here (point D). Use case example:

We have a normal free Registration that will add the users to the Registered A user group. When logged the user can buy:
- the Product B linked to Subscription Plan B (Type of relation - Renewal or Creation) that add users to the Registered B user group.
- the Product C linked to Subscription Plan C (Type of relation - Renewal or Creation) that add users to the Registered C user group.

Users will can migrate between Plans, but always just 1 Plan, so they will be added to Registered B user group OR Registered C user group.
While they will be always into the standard free Registered A user group.

Right now there is a way to set "Product > Restrictions and Dimensions > Access Level" defining when to show the Product, but there is no a way to choose "when to hide" the Product.
So, for example here, being that all users will always be added to the Registered A user group, there is no a way to hide the Product B (or Product C) when the Subscription B (or C) is active.
PS - Consider that, as Jerome suggest, we should use Variants to add Subscriptions Renewal options for that Product

Please, Do you have any tips and tricks suggestions ?

Please Log in or Create an account to join the conversation.

  • Posts: 81625
  • Thank you received: 13085
  • MODERATOR
1 year 5 months ago #346510

Hi,

I don't see a way to do that. For the "access level" setting of the product to be usable, the Registered A user group should be removed when the user is added to the B or C user groups and in that case you could restrict it to the Registered A user group only.

I guess that with custom PHP code on the show_default view file, you could manually check the user group of the current user and not display the content of the page when the user has the groups B or C. But besides custom coding I don't see a clean solution.
The code is not that complex.
Something like that at the beginning :

<?php
if($this->element->product_id == XX) {
 $class = hikashop_get('class.user');
 $data = $class->get(hikashop_loadUser());
 if(hikashop_isAllowed('YYY,ZZZ',$data->user_cms_id)){
  echo "Product not available for your user group";
  return;
 }
}
?>
where XXX is the id of the product A, and YYY et ZZZ the id of the user groups B and C

Please Log in or Create an account to join the conversation.

  • Posts: 455
  • Thank you received: 35
1 year 5 months ago #346530

Hi Nicolas,
really many thanks for your answer. In first of all I want to put in evidence here that from my point of view, right now, what I detailed in this topic is something due to the "Subscription > Type of relation - Renewal or Creation" missing mentioned on the point B of the linked topic.

Now, considering the available HikaSubscription features (right now), we'll have to "complicate" a little bit the Product Subscriptions creation:
- to create 1 Product for each Subscription (B, C, D)
- Each Product Subscriptions will have different Variants (that right now are hidden in the Product view and they will be available only from the Subscriptions control panel > Actions list)
- Each Product Variant will be a different renewal duration (right now the Renewal does not consider the quantity. Quantity is always 1 and also by using the "Type of relation - Renewal or Creation" would multiply the Subscriptions)

A - As you suggested, being that the need is limited to the 3 Products Subscription I could edit the Product show_default view file without the need to create different Layouts , Right ?

B - Please, Should be better to add the code around line 10 OR on around line 16 ?

C - Each Product ID should be checked for its specific User Group (I suppose by using the “elseif”)

D - In case of one positive User Group > Product ID has been found, instead of echo "Product not available for your user group", would be good to redirect directly to the Subscription control panel page index.php?option=com_hikaserial&view=subscription&layout=listing
From where the user will can use the Actions > Renewal options

Please Can you help on redefine the suggested code ?

E - (I don't know if it is simple to suggest to me)
When redirected to the Subscription control panel page, would be good to add / to show an Info Alert by calling a new Language String like:
"You have yet an active Subscription, Please, select the action Renewal that you want to process" ((it is just an example)

Please Log in or Create an account to join the conversation.

  • Posts: 81625
  • Thank you received: 13085
  • MODERATOR
1 year 5 months ago #346579

Hi,

A. and C. You could use the same view file yes. This means that you would have to add the code once for each product.
OR, you could also change the code a bit like this:

<?php
if(!empty($this->element->AAA)) {
 $class = hikashop_get('class.user');
 $data = $class->get(hikashop_loadUser());
 if(hikashop_isAllowed($this->element->AAA,$data->user_cms_id)){
  echo "Product not available for your user group";
  return;
 }
}
?>
where AAA would be the column name of a custom field where you would write "YYY,ZZZ" for product XXX, etc. That way, it could handle as many products as you want with only one piece of code.

B. You could add that code on line 0 of the view file, right at the beginning.

D. Sure. You could change that line by:
JFactory::getApplication()->redirect(hikaserial::completeLink('subscription&task=listing&Itemid=XXX'));
where XXX would be the id of a menu item of HikaSerial.
Or directly enter the SEF URL of the page like so:
JFactory::getApplication()->redirect('MY SEF URL');

E. Before the redirect line, you could add:
JFactory::getApplication()->enqueueMessage('You have yet an active Subscription, Please, select the action Renewal that you want to process');
That would display the message after the redirect on the subscriptions listing page.

Please Log in or Create an account to join the conversation.

  • Posts: 455
  • Thank you received: 35
1 year 5 months ago #346600

Hi Nicolas,
really Many Thanks!
I'm going to do some tests and I'll report here... About your last suggestions:

C - Very good, clever. So, you suggest to change the User Group check line:
- from: if(hikashop_isAllowed('YYY,ZZZ',$data->user_cms_id)){
- to: if(hikashop_isAllowed($this->element->AAA,$data->user_cms_id)){

Where YYY,ZZZ are the User Group ID >>> or AAA will be the custom field column name. Okay.
Where the Custom Field should be a "Table > Product" custom field
and "Product > Display > Front-end: No"

So Vendors from frontend won't see anything and when I'll need "to run" the redirection with specific subscription product I will have to add it from backend. Just it. Did I get it right ?

D - Which is the best solution from a SEF point of view? Change something ?
Maybe the first solution is better because it will be able to work directly even with the multi language feature activated?

E - To add the message into the Bootstrap Alert I should to include it into a div like:

<div class="alert alert-warning" role="alert">
  JFactory::getApplication()->enqueueMessage('You have yet an active Subscription, Please, select the action Renewal that you want to process');
</div>
Am I right ?

Please Log in or Create an account to join the conversation.

  • Posts: 81625
  • Thank you received: 13085
  • MODERATOR
1 year 5 months ago #346603

Hi,

C. Yes. Note however that there are two lines to change, not just one.

D. It doesn't change anything regarding SEO. It changes for the maintenance in the future. If you enter the full URL, then if you change the domain name of your website, or if you change the alias of the menu item to access that area, the URL will have to be updated in that custom code. If you let HikaSerial generate the SEF URL for you, it won't matter.

E. No. It's Joomla displaying the error message with the HTML it wants around it. You don't need to do anything in that regard.

Please Log in or Create an account to join the conversation.

  • Posts: 455
  • Thank you received: 35
1 year 5 months ago #346618

Hi Nicolas,

C - Sure!

D - Got it, thanks!

E - If some HikaShop users are interested on it, Many Thanks to your answer I suppose to have found it in this Joomla Documentation page
So, with:

JFactory::getApplication()->enqueueMessage('You have yet an active Subscription, Please, select the action Renewal that you want to process');
the default Alert Message will be shown.
While to show it as an Alert Warning (for example) the code should be:
JError::raiseWarning('You have yet an active Subscription, Please, select the action Renewal that you want to process');

Last edit: 1 year 5 months ago by joomleb.

Please Log in or Create an account to join the conversation.

  • Posts: 81625
  • Thank you received: 13085
  • MODERATOR
1 year 5 months ago #346622

Hi,

E. If I remember correctly, JError has been removed on Joomla 4. So I wouldn't recommand it.
If you want to display it as a warning, you should do it like this:

JFactory::getApplication()->enqueueMessage('You have yet an active Subscription, Please, select the action Renewal that you want to process', 'warning');

The following user(s) said Thank You: joomleb

Please Log in or Create an account to join the conversation.

  • Posts: 455
  • Thank you received: 35
1 year 5 months ago #346646

Hi Nicolas,
really Many Thanks, we're right in step J3 to J4 in our sites, you spared us the mistake!

Last edit: 1 year 5 months ago by joomleb.

Please Log in or Create an account to join the conversation.

Time to create page: 0.082 seconds
Powered by Kunena Forum