Skip to content

Commit d37d53e

Browse files
committed
HM-1: Fix for adding product variant
1 parent bb0c7c0 commit d37d53e

File tree

5 files changed

+74
-54
lines changed

5 files changed

+74
-54
lines changed
Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
sylius_twig_hooks:
22
hooks:
3-
'sylius_shop.product.show.content.info.summary.add_to_cart':
4-
submit:
5-
template: '@SyliusWishlistPlugin/Product/Show/_addToCart.html.twig'
3+
'sylius_shop.product.show.content.info.summary':
4+
add_to_wishlist:
5+
template: '@SyliusWishlistPlugin/Common/_addToWishlist.html.twig'
6+
priority: 10
7+
'sylius_shop.product.show.content.info.summary.add_to_wishlist':
8+
add_to_wishlist:
9+
template: '@SyliusWishlistPlugin/Common/AddToWishlist/_button.html.twig'
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
{% set is_user = app.user is not null %}
2+
{% set wishlists = is_user ? findAllByShopUserAndToken(app.user) : findAllByAnonymousAndChannel(sylius.channel) %}
3+
{% set is_single_wishlist = wishlists|length < 2 %}
4+
5+
{% set is_product_show_page = hookable_metadata.context.is_product_show_page|default(false) %}
6+
7+
{% if is_product_show_page %}
8+
{% set variant = hookable_metadata.context.variant %}
9+
{% set product = variant.product %}
10+
11+
{% set single_wishlist_path = path('sylius_wishlist_plugin_shop_wishlist_add_product_variant', {
12+
'wishlistId': wishlists[0].id,
13+
'variantId': variant.id,
14+
}) %}
15+
{% else %}
16+
{% set single_wishlist_path = path('sylius_wishlist_plugin_shop_locale_wishlist_add_product', {'productId': product.id}) %}
17+
{% endif %}
18+
19+
<div class="mb-3">
20+
{% if is_single_wishlist %}
21+
<a
22+
href="{{ single_wishlist_path }}"
23+
class="btn btn-icon btn-outline-secondary {% if not is_product_show_page %}w-100{% endif %}"
24+
data-product-name="{{ product.name }}"
25+
{{ sylius_test_html_attribute('wishlist-add-product') }}
26+
>
27+
{{ ux_icon('mdi:heart', {'class': 'icon icon-sm'}) }}
28+
{{ 'sylius_wishlist_plugin.ui.add_to_wishlist'|trans }}
29+
</a>
30+
{% else %}
31+
<div class="dropdown">
32+
<button class="btn btn-icon btn-outline-secondary dropdown-toggle {% if not is_product_show_page %}w-100{% endif %}"
33+
type="button" data-bs-toggle="dropdown" aria-expanded="false"
34+
>
35+
{{ ux_icon('mdi:heart', {'class': 'icon icon-sm'}) }}
36+
{{ 'sylius_wishlist_plugin.ui.add_to_wishlist'|trans }}
37+
</button>
38+
<ul class="dropdown-menu w-100" data-bb-wishlist-hrefs="hrefs-adding-variant">
39+
{% for wishlist in wishlists %}
40+
{% if is_product_show_page %}
41+
{% set path = path('sylius_wishlist_plugin_shop_wishlist_add_product_variant', {
42+
'wishlistId': wishlist.id,
43+
'variantId': variant.id,
44+
}) %}
45+
{% else %}
46+
{% set path = path('sylius_wishlist_plugin_shop_locale_wishlist_add_product_to_selected_wishlist', {
47+
'wishlistId': wishlist.id,
48+
'productId': product.id
49+
}) %}
50+
{% endif %}
51+
<li>
52+
<a
53+
href="{{ path }}"
54+
class="dropdown-item"
55+
data-product-name="{{ product.name }}"
56+
{{ sylius_test_html_attribute('wishlist-add-product') }}
57+
>
58+
<span>{{ wishlist.name }}</span>
59+
</a>
60+
</li>
61+
{% endfor %}
62+
</ul>
63+
</div>
64+
{% endif %}
65+
</div>
Lines changed: 1 addition & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1 @@
1-
{% if hookable_metadata.context.form is defined and hookable_metadata.context.form is not null %}
2-
{% set form = hookable_metadata.context.form %}
3-
{% set variant = form.cartItem.vars.value.variant %}
4-
{% set product = variant.product %}
5-
{% endif %}
6-
{% set isUser = app.user is not null %}
7-
{% set wishlists = isUser ? findAllByShopUserAndToken(app.user) : findAllByAnonymousAndChannel(sylius.channel) %}
8-
{% set isSingleWishlist = wishlists|length < 2 %}
9-
10-
<div class="mb-3">
11-
{% if isSingleWishlist %}
12-
<a
13-
href="{{ path('sylius_wishlist_plugin_shop_locale_wishlist_add_product', {'productId': product.id}) }}"
14-
class="btn btn-icon btn-outline-secondary w-100"
15-
data-product-name="{{ product.name }}"
16-
{{ sylius_test_html_attribute('wishlist-add-product') }}
17-
>
18-
{{ ux_icon('mdi:heart', {'class': 'icon icon-sm'}) }}
19-
{{ 'sylius_wishlist_plugin.ui.add_to_wishlist'|trans }}
20-
</a>
21-
{% else %}
22-
<div class="dropdown">
23-
<button class="btn btn-icon btn-outline-secondary w-100 dropdown-toggle" type="button" data-bs-toggle="dropdown" aria-expanded="false">
24-
{{ ux_icon('mdi:heart', {'class': 'icon icon-sm'}) }}
25-
{{ 'sylius_wishlist_plugin.ui.add_to_wishlist'|trans }}
26-
</button>
27-
<ul class="dropdown-menu w-100" data-bb-wishlist-hrefs="hrefs-adding-variant">
28-
{% for wishlist in wishlists %}
29-
<li>
30-
<a
31-
href="{{ path('sylius_wishlist_plugin_shop_locale_wishlist_add_product_to_selected_wishlist', {
32-
'wishlistId': wishlist.id,
33-
'productId': product.id
34-
}) }}"
35-
class="dropdown-item"
36-
data-product-name="{{ product.name }}"
37-
{{ sylius_test_html_attribute('wishlist-add-product') }}
38-
>
39-
<span>{{ wishlist.name }}</span>
40-
</a>
41-
</li>
42-
{% endfor %}
43-
</ul>
44-
</div>
45-
{% endif %}
46-
</div>
1+
{% hook 'add_to_wishlist' with {is_product_show_page: true} %}

templates/Product/Show/_addToCart.html.twig

Lines changed: 0 additions & 4 deletions
This file was deleted.

tests/Application/templates/bundles/SyliusShopBundle/product/common/card.html.twig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,5 @@
1616
{% endif %}
1717
</div>
1818
<hr>
19-
{% include '@SyliusWishlistPlugin/Common/_addToWishlist.html.twig' %}
19+
{% include '@SyliusWishlistPlugin/Common/AddToWishlist/_button.html.twig' %}
2020
</div>

0 commit comments

Comments
 (0)