Skip to content

Commit

Permalink
Merge branch 'improvement/paymentlink-methods-switch' into release-we…
Browse files Browse the repository at this point in the history
…ek-07
  • Loading branch information
michielgerritsen committed Feb 19, 2024
2 parents a61588c + d4ee528 commit 1e5cf64
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 0 deletions.
14 changes: 14 additions & 0 deletions view/adminhtml/layout/sales_order_create_index.xml
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 view/adminhtml/templates/form/mollie_paymentlink_javascript.phtml
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>

0 comments on commit 1e5cf64

Please sign in to comment.