-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'improvement/paymentlink-methods-switch' into release-we…
…ek-07
- Loading branch information
Showing
2 changed files
with
63 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?xml version="1.0"?> | ||
<!-- | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
--> | ||
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd"> | ||
<body> | ||
<referenceBlock name="content"> | ||
<block name="mollie_paymentlink_javascript" template="Mollie_Payment::form/mollie_paymentlink_javascript.phtml" after="-" /> | ||
</referenceBlock> | ||
</body> | ||
</page> |
49 changes: 49 additions & 0 deletions
49
view/adminhtml/templates/form/mollie_paymentlink_javascript.phtml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<?php | ||
/* | ||
* Copyright Magmodules.eu. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
?> | ||
<script> | ||
document.addEventListener('DOMContentLoaded', function () { | ||
const saveSelectedMethods = () => { | ||
// Save the selected payment methods to local storage | ||
var paymentMethods = document.getElementById('mollie_methods_paymentlink_methods'); | ||
if (!paymentMethods) { | ||
return; | ||
} | ||
|
||
paymentMethods.addEventListener('change', function () { | ||
var selected = []; | ||
for (var i = 0; i < paymentMethods.options.length; i++) { | ||
if (paymentMethods.options[i].selected) { | ||
selected.push(paymentMethods.options[i].value); | ||
} | ||
} | ||
localStorage.setItem('mollie_paymentlink_methods', JSON.stringify(selected)); | ||
}); | ||
}; | ||
|
||
const setSelectedMethods = () => { | ||
var paymentMethods = document.getElementById('mollie_methods_paymentlink_methods'); | ||
const selectedMethods = JSON.parse(localStorage.getItem('mollie_paymentlink_methods')); | ||
if (!selectedMethods || !paymentMethods) { | ||
return; | ||
} | ||
|
||
for (var i = 0; i < paymentMethods.options.length; i++) { | ||
if (selectedMethods.indexOf(paymentMethods.options[i].value) !== -1) { | ||
paymentMethods.options[i].selected = true; | ||
} | ||
} | ||
}; | ||
|
||
saveSelectedMethods(); | ||
setSelectedMethods(); | ||
|
||
document.getElementById('order-billing_method').addEventListener('DOMSubtreeModified', () => { | ||
saveSelectedMethods(); | ||
setSelectedMethods(); | ||
}) | ||
}); | ||
</script> |