Bug 36868: (follow-up) Fix deletion when nothing is in the cart, and make DB update better

Signed-off-by: Pedro Amorim <pedro.amorim@openfifth.co.uk>
This commit is contained in:
Lucas Gass 2026-07-17 18:53:12 +00:00 committed by Pedro Amorim
parent fac6a1adfe
commit 9b5f75a79e
No known key found for this signature in database
GPG Key ID: 06B75BA7F3894D55
3 changed files with 21 additions and 2 deletions

View File

@ -8,14 +8,21 @@ return {
my ($args) = @_;
my ( $dbh, $out ) = @$args{qw(dbh out)};
# Do your stuff here
my $exists = $dbh->selectrow_array(
q{SELECT 1 FROM systempreferences WHERE variable = 'AutoDeleteFromCartWhenHoldPlaced'});
if ($exists) {
say_warning( $out, "System preference 'AutoDeleteFromCartWhenHoldPlaced' already exists, skipping" );
return;
}
$dbh->do(
q{
INSERT IGNORE INTO systempreferences ( `variable`, `value`, `options`, `explanation`, `type` ) VALUES
('AutoDeleteFromCartWhenHoldPlaced', '','', 'Automatically delete items from cart when a hold is placed','Choice')
}
);
say_success( $out, "Added new system preference 'AutoDeleteFromCartWhenHoldPlaced'" );
say $out "Added new system preference 'AutoDeleteFromCartWhenHoldPlaced'";
},
};

View File

@ -269,6 +269,12 @@ function delSingleRecord(biblionumber) {
var valCookie = readCookie(nameCookie);
var arrayRecords = valCookie.split("/");
var pos = jQuery.inArray(biblionumber, arrayRecords);
// the cart is empty, bail
if (pos <= 0) {
return;
}
arrayRecords.splice(pos, 1);
valCookie = arrayRecords.join("/");
writeCookie(nameCookie, valCookie);

View File

@ -235,6 +235,12 @@ function delSingleRecord(biblionumber) {
var arrayRecords = valCookie.split("/");
var pos = jQuery.inArray(biblionumber, arrayRecords);
arrayRecords.splice(pos, 1);
//if cart is empty, bail
if (pos <= -1) {
return;
}
valCookie = arrayRecords.join("/");
writeCookie(nameCookie, valCookie);
updateBasket(arrayRecords.length - 1);