From 8d83e0239224669d92a284e3e7775052cfb61acb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Igor=20Ste=CC=A8pien=CC=81?= Date: Mon, 18 Sep 2023 00:14:02 +0200 Subject: [PATCH] Handle code submit for link via data attribute --- .../theme/core/cart/handler/voucher/codeLinkSubmitHandler.js | 5 +++-- templates/checkout/_partials/cart-voucher.tpl | 5 ++++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/_dev/js/theme/core/cart/handler/voucher/codeLinkSubmitHandler.js b/_dev/js/theme/core/cart/handler/voucher/codeLinkSubmitHandler.js index 9eddc338..f1a052e3 100644 --- a/_dev/js/theme/core/cart/handler/voucher/codeLinkSubmitHandler.js +++ b/_dev/js/theme/core/cart/handler/voucher/codeLinkSubmitHandler.js @@ -4,14 +4,15 @@ const codeLinkSubmitHandler = (event) => { const link = event.currentTarget; const input = document.querySelector('[name="discount_name"]'); const form = document.querySelector('.js-voucher-form'); + const code = link.dataset?.code; - if (input && form) { + if (input && form && code) { const formEvent = new Event('submit', { bubbles: true, cancelable: true, }); - input.value = link.textContent; + input.value = code; form.dispatchEvent(formEvent); } }; diff --git a/templates/checkout/_partials/cart-voucher.tpl b/templates/checkout/_partials/cart-voucher.tpl index eb6cd060..9deea9f6 100644 --- a/templates/checkout/_partials/cart-voucher.tpl +++ b/templates/checkout/_partials/cart-voucher.tpl @@ -88,7 +88,10 @@ {foreach from=$cart.discounts item=discount}
  • - {$discount.code} - {$discount.name} + + {$discount.code} + + - {$discount.name}
  • {/foreach}