How to edit a restricted access product template in Dawn 12.0?

Hi, I’ve created a simple one product website using Dawn.

I have 2 product templates, one for retail and one for wholesale.

I’ve managed to include what I need for very basic wholesale requirements without an app.

I’ve added this coding to theme.liquid which restricts access to the wholesale product page unless the customer is logged in and is tagged wholesale.

{% if template contains ‘product’ and request.path == ‘/products/wholesale’ %}
{% if customer and customer.tags contains ‘wholesale’ %}
{% comment %} Continue rendering the wholesale product page for logged-in wholesale customers {% endcomment %}
{% else %}
{% comment %} Redirect non-wholesale customers to the homepage or another page of your choice {% endcomment %}
{% assign redirect_url = ‘/’ %}

{% endif %}
{% endif %}

It works perfectly on the front end to restrict access as intended BUT it’s also preventing me from accessing the product template to edit it. Would appreciate any assistance in what to add to this coding to bypass the restriction to enable editing.

Thanks in advance.

Hey @BonzaDogTreats ,

Try what is shown here https://stackoverflow.com/questions/17470921/how-to-check-if-current-visitor-is-shops-admin.
Basically wrap you code around it to prevent the behaviour when logged in user is admin.

Thanks, my coding ability is quite basic, and I don’t really understand that thread.

Hey @BonzaDogTreats ,

Try and replace it with this. I haven’t tested this.

{% capture CFH %}{{ content_for_header  }}{% endcapture %}{{ CFH }}

{% if CFH contains 'designMode' %}
    {% assign admin = true %}
{% endif %}

{% if admin or template contains 'product' and request.path == '/products/wholesale' %}
{% if customer and customer.tags contains 'wholesale' %}
{% comment %} Continue rendering the wholesale product page for logged-in wholesale customers {% endcomment %}
{% else %}
{% comment %} Redirect non-wholesale customers to the homepage or another page of your choice {% endcomment %}
{% assign redirect_url = '/' %}

{% endif %}
{% endif %}

Thanks, unfortunately it didn’t work, the home page was stuck in a loop