Skip to content

Commit

Permalink
[Admin][Product] Add view in store button
Browse files Browse the repository at this point in the history
  • Loading branch information
mpysiak committed May 17, 2024
1 parent cb9ac59 commit 27a9529
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ twig_hooks:
'sylius_admin.product.show.content.header.title_block':
title:
template: '@SyliusAdmin/product/show/content/header/title_block/title.html.twig'

'sylius_admin.product.show.content.header.title_block.actions':
view_in_store:
template: '@SyliusAdmin/product/common/header/title_block/actions/view_in_store.html.twig'

'sylius_admin.product.show.content.page_body':
details:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,9 @@ twig_hooks:
method: 'PUT'

'sylius_admin.product.update.content.header.title_block.actions':
more:
template: '@SyliusAdmin/product/update/header/title_block/actions/more.html.twig'
priority: 32

'sylius_admin.product.update.content.header.title_block.actions.more':
view_in_store:
template: '@SyliusAdmin/product/update/header/title_block/actions/more/view_in_store.html.twig'
template: '@SyliusAdmin/product/common/header/title_block/actions/view_in_store.html.twig'
priority: 32

'sylius_admin.product.update.content.form':
side_navigation:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
{% from '@SyliusAdmin/shared/helper/icon.html.twig' import icon as _icon %}

{% set product = (hookable_metadata.context.resource) %}
{% set enabledChannels = product.channels|filter(channel => channel.enabled == true) %}

{% if sylius_bundle_loaded_checker('SyliusShopBundle') %}
{% if not product.enabled or enabledChannels|length < 1 %}
<a class="btn disabled" href="{{ (url is not defined) ? '#' : url|raw }}" target="_blank" {{ sylius_test_html_attribute('view-in-store') }}>
{{ _icon({ icon: 'arrow-up-right', class: 'icon icon-tabler' }) }}
{{ 'sylius.ui.view_in_store'|trans }}
</a>
{% elseif enabledChannels|length > 1 %}
<div class="dropdown">
<button class="btn dropdown-toggle" type="button" data-bs-toggle="dropdown" aria-expanded="false">
{{ 'sylius.ui.view_in_store'|trans }}
</button>
<ul class="dropdown-menu" {{ sylius_test_html_attribute('view-in-store') }}>
{% for channel in enabledChannels %}
{% set product_translation = sylius_product_translation(product, channel) %}
{% if product_translation is not null %}
{% set url = sylius_channel_url(path('sylius_shop_product_show', {'slug': product_translation.slug, '_locale': product_translation.locale}), channel) %}
{% endif %}

<li>
<a
class="dropdown-item{% if url is not defined %} disabled{% endif %}"
href="{{ (url is not defined) ? '#' : url|raw }}"
target="_blank"
>
{{ _icon({ icon: 'arrow-up-right', class: 'icon dropdown-item-icon icon-tabler' }) }}
{{ channel.name }} ({{ channel.code }})
</a>
</li>
{% endfor %}
</ul>
</div>
{% else %}
{% for channel in enabledChannels %}
{% set product_translation = sylius_product_translation(product, channel) %}
{% if product_translation is not null %}
{% set url = sylius_channel_url(path('sylius_shop_product_show', {'slug': product_translation.slug, '_locale': product_translation.locale}), channel) %}
{% endif %}

<a class="btn" href="{{ (url is not defined) ? '#' : url|raw }}" target="_blank" {{ sylius_test_html_attribute('view-in-store') }}>
{{ _icon({ icon: 'arrow-up-right', class: 'icon icon-tabler' }) }}
{{ 'sylius.ui.view_in_store'|trans }}
</a>
{% endfor %}
{% endif %}
{% endif %}
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,6 @@
<h1 class="page-title">{{ product.name }}</h1>
</div>
</div>
<div class="col-12 col-md-auto ms-auto d-print-none">
{% hook 'actions' %}
</div>

This file was deleted.

This file was deleted.

0 comments on commit 27a9529

Please sign in to comment.