Bug 30979: Always show self-checkout when preference enabled

This patch updates the display logic such that if the truested
self-checkout option is enabled we always show the checkout button and
prompt a login when no user is found.

Signed-off-by: Silvia Meakins <smeakins@eso.org>
Signed-off-by: Kyle M Hall <kyle@bywatersolutions.com>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
This commit is contained in:
Martin Renvoize 2023-01-17 14:14:36 +00:00 committed by Tomas Cohen Arazi
parent 709255fdfa
commit d77006331b
Signed by: tomascohen
GPG key ID: 0A272EA1B2F3C15F
3 changed files with 27 additions and 3 deletions

View file

@ -81,7 +81,7 @@
</div> <!-- / .dropdown-menu -->
</li> <!-- / .nav-item.dropdown -->
[% END # / IF virtualshelves %]
[% IF ( Koha.Preference( 'OpacTrustedCheckout' ) && loggedinusername ) %]
[% IF Koha.Preference( 'OpacTrustedCheckout' ) %]
<li class="nav-item">
<a href="#" class="nav-link" title="Self check out" id="comenulink" role="button" data-toggle="modal" data-target="#checkoutModal">
<i id="checkout-icon" class="fa fa-barcode fa-icon-black" aria-hidden="true"></i> <span class="checkout-label">Self checkout</span>

View file

@ -117,7 +117,7 @@
[% END # /IF OpacLangSelectorMode == 'both' || OpacLangSelectorMode == 'footer' %]
[% END # / UNLESS is_popup %]
[% IF ( Koha.Preference( 'OpacTrustedCheckout' ) && loggedinusername ) %]
[% IF Koha.Preference( 'OpacTrustedCheckout' ) %]
[% INCLUDE 'modals/checkout.inc' %]
[% END %]
@ -305,7 +305,7 @@ $(document).ready(function() {
</script>
[% END %]
[% END %]
[% IF ( Koha.Preference( 'OpacTrustedCheckout' ) && loggedinusername ) %]
[% IF Koha.Preference( 'OpacTrustedCheckout' ) %]
[% Asset.js("js/modals/checkout.js") | $raw %]
[% END %]
[% KohaPlugins.get_plugins_opac_js | $raw %]

View file

@ -61,6 +61,30 @@ $(document).ready(function() {
$('#checkoutConfirm').replaceWith('<button type="submit" id="checkoutSubmit" class="btn btn-primary">Submit</button>');
};
// Before modal show, check login
$('#checkoutModal').on('show.bs.modal', function(e) {
// Redirect to login modal if not logged in
if (logged_in_user_id === "") {
let url = new URL(window.location.href);
url.searchParams.append('modal','checkout');
$('#modalAuth').append('<input type="hidden" name="return" value="' + url.href +'" />');
$('#loginModal').modal('show');
return false;
}
});
// Detect that we were redirected here after login and re-open modal
let urlParams = new URLSearchParams(window.location.search);
if (urlParams.has('modal')) {
let modal = urlParams.get('modal');
history.replaceState && history.replaceState(
null, '', location.pathname + location.search.replace(/[\?&]modal=[^&]+/, '').replace(/^&/, '?')
);
if (modal == 'checkout') {
$("#checkoutModal").modal('show');
}
}
// On modal show, clear any prior results and set focus
$('#checkoutModal').on('shown.bs.modal', function(e) {
$('#checkoutResults').replaceWith('<div id="checkoutResults"></div>');