From 24acbbfaf89473fd83604f1f14e53c5cd393daf7 Mon Sep 17 00:00:00 2001 From: Matt Blenkinsop Date: Mon, 30 Sep 2024 14:22:34 +0000 Subject: [PATCH] Bug 38010: Adjust vendor update logic This patch handles the embedded data that might also need updating when editing a vendor --- Koha/REST/V1/Acquisitions/Vendors.pm | 32 ++++++++++++++++++++++------ 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/Koha/REST/V1/Acquisitions/Vendors.pm b/Koha/REST/V1/Acquisitions/Vendors.pm index 0747f5bbf43..8cd8b02dcfe 100644 --- a/Koha/REST/V1/Acquisitions/Vendors.pm +++ b/Koha/REST/V1/Acquisitions/Vendors.pm @@ -87,10 +87,13 @@ Controller function that handles adding a new Koha::Acquisition::Bookseller obje sub add { my $c = shift->openapi->valid_input or return; - my $vendor = $c->req->json; - my $contacts = delete $vendor->{contacts}; - my $interfaces = delete $vendor->{interfaces}; - my $aliases = delete $vendor->{aliases}; + my $vendor = $c->req->json; + my $contacts = delete $vendor->{contacts}; + my $interfaces = delete $vendor->{interfaces}; + my $aliases = delete $vendor->{aliases}; + my $subscriptions = delete $vendor->{subscriptions}; + my $baskets = delete $vendor->{baskets}; + my $contracts = delete $vendor->{contracts}; my $vendor_to_store = Koha::Acquisition::Bookseller->new_from_api( $c->req->json ); @@ -124,15 +127,31 @@ Controller function that handles updating a Koha::Acquisition::Bookseller object sub update { my $c = shift->openapi->valid_input or return; - my $vendor = Koha::Acquisition::Booksellers->find( $c->param('vendor_id') ); + my $vendor_id = $c->param('vendor_id'); + my $vendor = Koha::Acquisition::Booksellers->find( $vendor_id ); return $c->render_resource_not_found("Vendor") unless $vendor; return try { - $vendor->set_from_api( $c->req->json ); + my $vendor_update = $c->req->json; + my $contacts = delete $vendor_update->{contacts}; + my $interfaces = delete $vendor_update->{interfaces}; + my $aliases = delete $vendor_update->{aliases}; + my $subscriptions = delete $vendor_update->{subscriptions}; + my $baskets = delete $vendor_update->{baskets}; + my $contracts = delete $vendor_update->{contracts}; + + $vendor->set_from_api($vendor_update); $vendor->store(); + foreach my $contact (@$contacts) { + $contact->{booksellerid} = $vendor_id; + Koha::Acquisition::Bookseller::Contact->new($contact)->store; + } + $vendor->aliases($aliases) if scalar($aliases) > 0; + $vendor->interfaces($interfaces) if scalar($interfaces) > 0; + return $c->render( status => 200, openapi => $c->objects->to_api($vendor), @@ -143,6 +162,7 @@ sub update { } + =head3 delete Controller function that handles deleting a Koha::Acquisition::Bookseller object -- 2.39.3 (Apple Git-146)