From 29e49bd20993fea68e8531875ee9c131480b99c8 Mon Sep 17 00:00:00 2001 From: merdan Date: Thu, 16 Feb 2023 15:00:43 +0500 Subject: [PATCH] discounted prods --- .../Sarga/API/Http/Controllers/Wishlists.php | 2 +- .../API/Http/Resources/Catalog/Product.php | 20 ++----------------- .../Resources/Customer/WishListResource.php | 2 +- 3 files changed, 4 insertions(+), 20 deletions(-) diff --git a/packages/Sarga/API/Http/Controllers/Wishlists.php b/packages/Sarga/API/Http/Controllers/Wishlists.php index 92695145f..f10ddeb81 100644 --- a/packages/Sarga/API/Http/Controllers/Wishlists.php +++ b/packages/Sarga/API/Http/Controllers/Wishlists.php @@ -24,7 +24,7 @@ class Wishlists extends WishlistController $customer = $request->user(); return response([ - 'data' => WishListResource::collection($customer->wishlist_items()->get()), + 'data' => WishListResource::collection($customer->wishlist_items()->paginate(10)), ]); } diff --git a/packages/Sarga/API/Http/Resources/Catalog/Product.php b/packages/Sarga/API/Http/Resources/Catalog/Product.php index fdec42e38..2d3a5f913 100644 --- a/packages/Sarga/API/Http/Resources/Catalog/Product.php +++ b/packages/Sarga/API/Http/Resources/Catalog/Product.php @@ -16,7 +16,7 @@ class Product extends JsonResource */ public function toArray($request) { - $product = $this->product ? $this->product : $this; + $product = $this->product ?: $this; return [ /* product's information */ @@ -24,9 +24,6 @@ class Product extends JsonResource 'type' => $product->type, 'name' => $product->name, 'description' => $product->description, -// 'is_wishlisted' => $this->isWishlisted($product), //todo transfer to mobile -// 'is_item_in_cart' => \Cart::hasProduct($product),//todo transfer to mobile -// 'shop_title' => $this->shop_title, 'brand' => $product->brand->name ?? '', 'images' => ProductImage::collection($product->images), 'color_count' => $this->related_products->count(), @@ -49,7 +46,7 @@ class Product extends JsonResource $product = $variant->product; }else{ - $product = $this->product ? $this->product : $this; + $product = $this->product ?: $this; } $typeInstance = $product->getTypeInstance(); @@ -70,17 +67,4 @@ class Product extends JsonResource ), ]; } - -// private function isWishlisted($product):bool -// { -// $wishlist = false; -// -// if ($customer = auth('sanctum')->user() && $wishlist = auth('sanctum')->user()->wishlist_items) { -// $wishlist = $wishlist->filter(function ($item) use ($product) { -// return $item->product_id == $product->product_id; -// })->first(); -// } -// -// return $wishlist ? true : false; -// } } diff --git a/packages/Sarga/API/Http/Resources/Customer/WishListResource.php b/packages/Sarga/API/Http/Resources/Customer/WishListResource.php index fcc30b68d..8a47187f2 100644 --- a/packages/Sarga/API/Http/Resources/Customer/WishListResource.php +++ b/packages/Sarga/API/Http/Resources/Customer/WishListResource.php @@ -21,7 +21,7 @@ class WishListResource extends JsonResource 'created_at' => $this->created_at, 'updated_at' => $this->updated_at, 'old_price' => (double) core()->convertPrice($this->price), - 'old_price_formatted' => (double) core()->currency($this->price), + 'old_price_formatted' => core()->currency($this->price), ]; } } \ No newline at end of file