diff --git a/packages/Sarga/API/Http/Resources/Checkout/CartItemProduct.php b/packages/Sarga/API/Http/Resources/Checkout/CartItemProduct.php new file mode 100644 index 000000000..b3fea7b28 --- /dev/null +++ b/packages/Sarga/API/Http/Resources/Checkout/CartItemProduct.php @@ -0,0 +1,52 @@ +product ? $this->product : $this; + return [ + 'id' => $this->id, + 'name' => $product->name, + 'images' => ProductImage::collection($product->images), + /* super attributes */ + $this->mergeWhen($product->parent, [ + 'super_attributes' => $this->super_attributes($product->parent->super_attributes), + ]), + ]; + } + + private function super_attributes($attributes){ + if(is_countable($attributes)){ + return $attributes->map(function($item, $key){ + return [ + 'code' => $item->code, + 'value' => $this->{$item->code}, + 'name' => $item->name, + 'label' => $item->options->where('id',$this->{$item->code})->first()->admin_name + ]; + })->toArray(); + }else{ + $item = $attributes; + return [ + 'code' => $item->code, + 'value' => $this->{$item->code}, + 'name' => $item->name, + 'label' => $item->options->where('id',$this->{$item->code})->first()->admin_name + ]; + } + + } +} \ No newline at end of file diff --git a/packages/Sarga/API/Http/Resources/Checkout/CartItemResource.php b/packages/Sarga/API/Http/Resources/Checkout/CartItemResource.php index 5771317ff..1c6bd6f67 100644 --- a/packages/Sarga/API/Http/Resources/Checkout/CartItemResource.php +++ b/packages/Sarga/API/Http/Resources/Checkout/CartItemResource.php @@ -45,7 +45,7 @@ class CartItemResource extends JsonResource ? $this->resource->additional : json_decode($this->resource->additional, true), 'child' => new self($this->child), - 'product' => $this->when($this->product_id, new ProductResource($this->product)), + 'product' => $this->when($this->product_id, new CartItemProduct($this->product)), ]; } }