From 749bd01b8a9cd6a62585f93aeb40be0c73fb7721 Mon Sep 17 00:00:00 2001 From: merdan Date: Mon, 28 Feb 2022 17:36:04 +0500 Subject: [PATCH] cart product adn super attributes --- .../Resources/Checkout/CartItemProduct.php | 29 +++++++++++++------ 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/packages/Sarga/API/Http/Resources/Checkout/CartItemProduct.php b/packages/Sarga/API/Http/Resources/Checkout/CartItemProduct.php index 7a15b70f4..9e287fb26 100644 --- a/packages/Sarga/API/Http/Resources/Checkout/CartItemProduct.php +++ b/packages/Sarga/API/Http/Resources/Checkout/CartItemProduct.php @@ -3,6 +3,7 @@ namespace Sarga\API\Http\Resources\Checkout; use Illuminate\Http\Resources\Json\JsonResource; +use Illuminate\Support\Facades\Log; use Sarga\API\Http\Resources\Catalog\ProductImage; class CartItemProduct extends JsonResource @@ -15,15 +16,25 @@ class CartItemProduct extends JsonResource */ public function toArray($request) { - return [ - 'id' => $this->id, - 'name' => $this->name, - 'images' => ProductImage::collection($this->images), - /* super attributes */ - $this->mergeWhen(!empty($this->parent && $this->parent->super_attributes), [ - 'super_attributes' => $this->super_attributes($this->parent->super_attributes), - ]), - ]; + try{ + return [ + 'id' => $this->id, + 'name' => $this->name, + 'images' => ProductImage::collection($this->images), + /* super attributes */ + $this->mergeWhen(!empty($this->parent && $this->parent->super_attributes), [ + 'super_attributes' => $this->super_attributes($this->parent->super_attributes), + ]), + ]; + }catch (\Exception $ex){ + Log::info($this); + return [ + 'id' => $this->id, + 'name' => $this->name, + 'images' => ProductImage::collection($this->images), + ]; + } + } private function super_attributes($attributes){