Skip to content

Commit

Permalink
Fix multiple add to cart buttons on single page
Browse files Browse the repository at this point in the history
  • Loading branch information
dvesh3 committed Dec 21, 2021
1 parent 14f9154 commit 1b0303e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
5 changes: 3 additions & 2 deletions templates/product/detail.html.twig
Expand Up @@ -156,9 +156,10 @@
<p class="small text-muted mt-1">{{ 'general.available-in' | trans }} {{ ('attribute.' ~ product.saleInformation.saleInformation.availabilityType) | lower | trans }}</p>
{% endif %}
</div>
<form id="shop_add_to_cart_form" method="post" action="{{ path('shop-add-to-cart', { id: product.id }) }}">
<form id="shop_add_to_cart_form_{{ product.id }}" method="post" action="{{ path('shop-add-to-cart', { id: product.id }) }}">
<input type="hidden" name="_csrf_token" value="{{ csrf_token('addToCart') }}">
<a href="#" onclick="document.getElementById('shop_add_to_cart_form').submit();"
<a href="#"
onclick="document.getElementById('shop_add_to_cart_form_{{ product.id }}').submit();"
class="btn btn-success btn-block">{{ 'general.add-to-cart' | trans }}</a>
</form>

Expand Down
4 changes: 2 additions & 2 deletions templates/product/product_teaser.html.twig
Expand Up @@ -33,9 +33,9 @@
</a>
</div>
<div class="col p-1">
<form id="shop_add_to_cart_form" method="post" action="{{ path('shop-add-to-cart', { id: product.id }) }}">
<form id="shop_add_to_cart_form_{{ product.id }}" method="post" action="{{ path('shop-add-to-cart', { id: product.id }) }}">
<input type="hidden" name="_csrf_token" value="{{ csrf_token('addToCart') }}">
<a href="#" onclick="document.getElementById('shop_add_to_cart_form').submit();"
<a href="#" onclick="document.getElementById('shop_add_to_cart_form_{{ product.id }}').submit();"
class="btn btn-block btn-primary">{{ 'general.buy' | trans }} <i class=" ml-2"><img
src="/static/images/icons/cart.svg" height="20" width="auto"></i></a>
</form>
Expand Down

0 comments on commit 1b0303e

Please sign in to comment.