cart product adn super attributes

This commit is contained in:
merdan 2022-02-28 17:36:04 +05:00
parent 2392b68839
commit 749bd01b8a
1 changed files with 20 additions and 9 deletions

View File

@ -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){