-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b22344b
commit 4d25b1f
Showing
7 changed files
with
151 additions
and
98 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers\Api; | ||
|
||
use App\Enums\StockTypeEnum; | ||
use App\Events\Analytics\ProductView; | ||
use App\Facades\Sale; | ||
use App\Helpers\UrlHelper; | ||
use App\Http\Controllers\Controller; | ||
use App\Http\Requests\FilterRequest; | ||
use App\Models\Category; | ||
use App\Models\Product; | ||
use App\Services\CatalogService; | ||
use App\Services\FeedbackService; | ||
use App\Services\FilterService; | ||
use App\Services\GoogleTagManagerService; | ||
use App\Services\ProductService; | ||
use App\Services\Seo\CatalogSeoService; | ||
use App\Services\Seo\ProductSeoService; | ||
use App\Services\SliderService; | ||
use Illuminate\Http\JsonResponse; | ||
|
||
class CatalogController extends Controller | ||
{ | ||
public function index( | ||
FilterRequest $filterRequest, | ||
GoogleTagManagerService $gtmService, | ||
CatalogService $catalogService, | ||
// CatalogSeoService $seoService, | ||
): JsonResponse { | ||
if ($promocode = $filterRequest->get('promocode')) { | ||
Sale::applyPromocode($promocode); | ||
} | ||
|
||
$sort = $filterRequest->getSorting(); | ||
$currentFilters = $filterRequest->getFilters(); | ||
$currentCity = $filterRequest->getCity(); | ||
$searchQuery = $filterRequest->input('search'); | ||
UrlHelper::setCurrentFilters($currentFilters); | ||
UrlHelper::setCurrentCity($currentCity); | ||
|
||
$products = $catalogService->getProducts($currentFilters, $sort, $searchQuery); | ||
|
||
$sortingList = [ | ||
'rating' => 'по популярности', | ||
'newness' => 'новинки', | ||
'price-up' => 'по возрастанию цены', | ||
'price-down' => 'по убыванию цены', | ||
]; | ||
|
||
$category = end($currentFilters[Category::class])->getFilterModel(); | ||
$badges = $catalogService->getFilterBadges($currentFilters, $searchQuery); | ||
|
||
$gtmService->setForCatalog($products, $category, $searchQuery); | ||
|
||
$data = [ | ||
'products' => $products, | ||
'category' => $category, | ||
'currentFilters' => $currentFilters, | ||
'badges' => $badges, | ||
'filters' => app(FilterService::class)->getAll(), | ||
'sort' => $sort, | ||
'sortingList' => $sortingList, | ||
'searchQuery' => $searchQuery, | ||
]; | ||
|
||
if (!$products->isNotEmpty()) { | ||
$sliderService = new SliderService(); | ||
$data['simpleSliders'] = $sliderService->getSimple(); | ||
} | ||
// $seoService | ||
// ->setCurrentFilters($currentFilters) | ||
// ->setCurrentCity($currentCity) | ||
// ->setProducts($products) | ||
// ->generate(); | ||
|
||
return response()->json($data); | ||
} | ||
|
||
/** | ||
* Display the specified resource. | ||
*/ | ||
public function show( | ||
Product $product, | ||
// ProductService $productService, | ||
SliderService $sliderService, | ||
// ProductSeoService $seoService, | ||
FeedbackService $feedbackService, | ||
): array { | ||
$product->load([ | ||
'tags', | ||
'category', | ||
'countryOfOrigin', | ||
'availableSizes' => fn ($q) => $q->whereHas('stock', fn ($q) => $q->where('type', StockTypeEnum::SHOP)) | ||
->with(['stock' => fn ($q) => $q->orderBy('site_sorting', 'asc')->with('city')]), | ||
]); | ||
// $productService->addToRecent($product->id); | ||
|
||
// $seoService->setProduct($product)->generate(); // !!! | ||
|
||
event(new ProductView($product)); | ||
|
||
return [ | ||
'product' => $product, | ||
'feedbacks' => $feedbackService->getForProduct($product->id), | ||
'similarProducts' => $sliderService->getSimilarProducts($product->id), | ||
'productGroup' => $sliderService->getProductGroup($product->product_group_id), | ||
// 'recentProductsSlider' => $sliderService->getRecentProducts($productService), | ||
]; | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,18 @@ | ||
<?php | ||
|
||
use App\Facades\Device; | ||
use App\Http\Controllers\Api\AppController; | ||
use App\Http\Controllers\Api\ProductController; | ||
use App\Http\Controllers\Api\TemporaryController; | ||
use App\Http\Controllers\Api\CatalogController; | ||
use Illuminate\Http\Request; | ||
use Illuminate\Support\Facades\Route; | ||
|
||
Route::get('/user', function (Request $request) { | ||
return $request->user(); | ||
return [ | ||
'user' => $request->user(), | ||
'device' => Device::current(), | ||
]; | ||
})->middleware('auth:sanctum'); | ||
|
||
Route::get('app-init', [AppController::class, 'init']); | ||
Route::get('catalog/{path?}', [TemporaryController::class, 'catalog'])->where('path', '[a-zA-Z0-9/_-]+'); | ||
Route::get('product/{product:slug}', [ProductController::class, 'show'])->withTrashed()->name('product.show'); // ! test | ||
Route::get('catalog/{path?}', [CatalogController::class, 'index'])->where('path', '[a-zA-Z0-9/_-]+'); | ||
Route::get('product/{product:slug}', [CatalogController::class, 'show'])->withTrashed()->name('product.show'); |