|
@@ -4,10 +4,10 @@ namespace Webkul\BagistoApi\Resolver;
|
|
|
|
|
|
|
|
use ApiPlatform\GraphQl\Resolver\QueryItemResolverInterface;
|
|
use ApiPlatform\GraphQl\Resolver\QueryItemResolverInterface;
|
|
|
use ApiPlatform\State\Pagination\PaginatorInterface;
|
|
use ApiPlatform\State\Pagination\PaginatorInterface;
|
|
|
-use Illuminate\Support\Facades\DB;
|
|
|
|
|
use Webkul\BagistoApi\Dto\ProductSearch\ProductSearchEdgeDto;
|
|
use Webkul\BagistoApi\Dto\ProductSearch\ProductSearchEdgeDto;
|
|
|
use Webkul\BagistoApi\Models\CategoryProducts;
|
|
use Webkul\BagistoApi\Models\CategoryProducts;
|
|
|
use Webkul\BagistoApi\State\ProductGraphQLProvider;
|
|
use Webkul\BagistoApi\State\ProductGraphQLProvider;
|
|
|
|
|
+use Webkul\Category\Models\Category;
|
|
|
|
|
|
|
|
class CategoryProductsResolver implements QueryItemResolverInterface
|
|
class CategoryProductsResolver implements QueryItemResolverInterface
|
|
|
{
|
|
{
|
|
@@ -30,14 +30,17 @@ class CategoryProductsResolver implements QueryItemResolverInterface
|
|
|
return new CategoryProducts;
|
|
return new CategoryProducts;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- $categoryId = DB::table('category_translations')
|
|
|
|
|
- ->where('slug', $categorySlug)
|
|
|
|
|
- ->value('category_id');
|
|
|
|
|
|
|
+ $locale = $args['locale'] ?? null;
|
|
|
|
|
+ $category = Category::query()
|
|
|
|
|
+ ->whereHas('translations', fn ($q) => $q->where('slug', $categorySlug))
|
|
|
|
|
+ ->first();
|
|
|
|
|
|
|
|
- if (! $categoryId) {
|
|
|
|
|
|
|
+ if (! $category) {
|
|
|
throw new \RuntimeException("Category not found for slug: {$categorySlug}");
|
|
throw new \RuntimeException("Category not found for slug: {$categorySlug}");
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ $categoryId = $category->id;
|
|
|
|
|
+
|
|
|
$filters = $this->parseFilter($args['filter'] ?? null);
|
|
$filters = $this->parseFilter($args['filter'] ?? null);
|
|
|
$filters['category_id'] = (int) $categoryId;
|
|
$filters['category_id'] = (int) $categoryId;
|
|
|
|
|
|
|
@@ -62,6 +65,11 @@ class CategoryProductsResolver implements QueryItemResolverInterface
|
|
|
$result = new CategoryProducts;
|
|
$result = new CategoryProducts;
|
|
|
$result->total_count = (int) $paginator->getTotalItems();
|
|
$result->total_count = (int) $paginator->getTotalItems();
|
|
|
|
|
|
|
|
|
|
+ // Attach category logo / banner / description.
|
|
|
|
|
+ $result->logo = $category->logo_url;
|
|
|
|
|
+ $result->banner = $category->banner_url;
|
|
|
|
|
+ $result->description = $category->translate($locale)?->description;
|
|
|
|
|
+
|
|
|
$offset = $this->resolveOffset($args, $result->total_count);
|
|
$offset = $this->resolveOffset($args, $result->total_count);
|
|
|
$limit = max(1, (int) ($args['first'] ?? $args['last'] ?? 30));
|
|
$limit = max(1, (int) ($args['first'] ?? $args['last'] ?? 30));
|
|
|
|
|
|