From b1987eda08dbccf61cce73de6a538dddf71fd1c0 Mon Sep 17 00:00:00 2001 From: Kaloyan Nikolov Date: Mon, 19 Dec 2022 15:07:54 +0200 Subject: [PATCH] CustomerResource response changed. Backend customer edit view changed to show that there is no billing or shipping inforamtion if there is no any. --- app/Http/Resources/CustomerResource.php | 34 ++++++++++++-------- backend/src/views/Customers/CustomerView.vue | 10 ++++-- 2 files changed, 29 insertions(+), 15 deletions(-) diff --git a/app/Http/Resources/CustomerResource.php b/app/Http/Resources/CustomerResource.php index 118e52c..71626c1 100644 --- a/app/Http/Resources/CustomerResource.php +++ b/app/Http/Resources/CustomerResource.php @@ -21,17 +21,9 @@ public function toArray($request) { $shipping = $this->shippingAddress; $billing = $this->billingAddress; - return [ - 'id' => $this->user_id, - 'first_name' => $this->first_name, - 'last_name' => $this->last_name, - 'email' => $this->user->email, - 'phone' => $this->phone, - 'status' => $this->status === CustomerStatus::Active->value, - 'created_at' => (new \DateTime($this->created_at))->format('Y-m-d H:i:s'), - 'updated_at' => (new \DateTime($this->updated_at))->format('Y-m-d H:i:s'), - 'shippingAddress' => [ + if($shipping) { + $shipping = [ 'id' => $shipping->id, 'address1' => $shipping->address1, 'address2' => $shipping->address2, @@ -39,8 +31,10 @@ public function toArray($request) 'state' => $shipping->state, 'zipcode' => $shipping->zipcode, 'country_code' => $shipping->country->code, - ], - 'billingAddress' => [ + ]; + } + if($billing) { + $billing = [ 'id' => $billing->id, 'address1' => $billing->address1, 'address2' => $billing->address2, @@ -48,7 +42,21 @@ public function toArray($request) 'state' => $billing->state, 'zipcode' => $billing->zipcode, 'country_code' => $billing->country->code, - ] + ]; + } + + return [ + 'id' => $this->user_id, + 'first_name' => $this->first_name, + 'last_name' => $this->last_name, + 'email' => $this->user->email, + 'phone' => $this->phone, + 'status' => $this->status === CustomerStatus::Active->value, + 'created_at' => (new \DateTime($this->created_at))->format('Y-m-d H:i:s'), + 'updated_at' => (new \DateTime($this->updated_at))->format('Y-m-d H:i:s'), + + 'shippingAddress' => $shipping, + 'billingAddress' => $billing ]; } } diff --git a/backend/src/views/Customers/CustomerView.vue b/backend/src/views/Customers/CustomerView.vue index ebf8f74..f29ac6c 100644 --- a/backend/src/views/Customers/CustomerView.vue +++ b/backend/src/views/Customers/CustomerView.vue @@ -14,7 +14,7 @@

Billing Address

-
+
@@ -26,12 +26,15 @@
+

+ There are is no billing address +

Shipping Address

-
+
@@ -42,6 +45,9 @@
+

+ There are is no shipping address +