|
|
@@ -4,6 +4,7 @@ namespace Webkul\Shop\Http\Controllers\API;
|
|
|
|
|
|
use Illuminate\Http\JsonResponse;
|
|
|
use Webkul\Category\Repositories\CategoryRepository;
|
|
|
+use Webkul\Core\Repositories\ChannelRepository;
|
|
|
use Webkul\Product\Repositories\ProductRepository;
|
|
|
use Webkul\Theme\Repositories\ThemeCustomizationRepository;
|
|
|
|
|
|
@@ -16,19 +17,25 @@ class HomeController extends APIController
|
|
|
protected ThemeCustomizationRepository $themeCustomizationRepository,
|
|
|
protected CategoryRepository $categoryRepository,
|
|
|
protected ProductRepository $productRepository,
|
|
|
+ protected ChannelRepository $channelRepository,
|
|
|
) {}
|
|
|
|
|
|
/**
|
|
|
* 获取首页完整数据
|
|
|
*
|
|
|
* GET /api/home
|
|
|
+ * Header: X-Channel: default|wap
|
|
|
*
|
|
|
* @return JsonResponse
|
|
|
*/
|
|
|
public function index(): JsonResponse
|
|
|
{
|
|
|
- $channel = core()->getCurrentChannel();
|
|
|
- $locale = core()->getRequestedLocaleCode();
|
|
|
+ $locale = core()->getRequestedLocaleCode();
|
|
|
+
|
|
|
+ // 通过 X-Channel header 区分 PC(default) / M(wap) 端
|
|
|
+ $channelCode = request()->header('X-Channel', 'default');
|
|
|
+ $channel = $this->channelRepository->findOneByField('code', $channelCode)
|
|
|
+ ?: core()->getCurrentChannel();
|
|
|
|
|
|
// 1. 获取主题自定义数据(banner、分类轮播、产品轮播等)
|
|
|
$customizations = $this->themeCustomizationRepository
|
|
|
@@ -55,6 +62,7 @@ class HomeController extends APIController
|
|
|
return response()->json([
|
|
|
'success' => true,
|
|
|
'data' => [
|
|
|
+ 'channel' => $channel->code,
|
|
|
'sections' => $sections,
|
|
|
'categories' => $this->formatCategoryTree($categories),
|
|
|
],
|