where('is_active', 1) ->orderBy('sort_order', 'asc') ->get(); } /** * 카테고리별/전체 상품 목록 조회 (판매 기간 및 상태 검증 포함) */ // app/Repositories/Product/ProductRepository.php public function getActiveProducts($categoryIdOrSlug = null, $search = null) { $now = now(); $query = DB::table('gc_products as p') ->select('p.*', 'm.file_path as thumb_path') ->leftJoin('gc_media_library as m', 'p.thumbnail_media_id', '=', 'm.id') ->where('p.status', 'ACTIVE'); // 1. 검색어가 있을 경우 (통합 검색) if ($search) { $query->where(function ($q) use ($search) { // 상품명 검색 $q->where('p.name', 'LIKE', "%{$search}%"); // 카테고리 연관 검색 (이름, 슬러그, 해시태그 키워드) $q->orWhereExists(function ($sub) use ($search) { $sub->select(DB::raw(1)) ->from('gc_categories as c') ->whereColumn('c.id', 'p.category_id') ->where(function ($sq) use ($search) { $sq->where('c.name', 'LIKE', "%{$search}%") ->orWhere('c.slug', 'LIKE', "%{$search}%") ->orWhere('c.search_keywords', 'LIKE', "%{$search}%"); // # 제거된 검색어도 LIKE로 매칭 }); }); }); } if ($categoryIdOrSlug && !$search) { $categoryQuery = DB::table('gc_categories'); if (is_numeric($categoryIdOrSlug)) { $categoryQuery->where('id', $categoryIdOrSlug); } else { $categoryQuery->where('slug', $categoryIdOrSlug); } $targetCategory = $categoryQuery->first(); if ($targetCategory) { $categoryIds = DB::table('gc_categories') ->where('id', $targetCategory->id) ->orWhere('parent_id', $targetCategory->id) ->pluck('id'); $query->whereIn('p.category_id', $categoryIds); } } return $query->orderBy('p.id', 'desc')->get(); } public function getProductById(int $id) { return DB::table('gc_products as p') ->select('p.*', 'm.file_path as thumb_path') ->leftJoin('gc_media_library as m', 'p.thumbnail_media_id', '=', 'm.id') ->where('p.id', $id) ->where('p.status', 'ACTIVE') ->first(); } /** * 상품에 속한 권종(SKU) 목록 조회 */ public function getSkusByProductId(int $productId) { return DB::table('gc_product_skus') ->where('product_id', $productId) ->where('is_active', 1) ->orderBy('sort_order', 'asc') ->get(); } /** * 특정 결제 수단 정보 조회 */ public function getPaymentMethodsByIds(array $ids) { if (empty($ids)) return collect(); return DB::table('gc_payment_methods') ->whereIn('id', $ids) ->where('is_active', 1) ->orderBy('sort_order', 'asc') ->get(); } }