!120 Add sorting settings
* Fixed category sort order and filter by active. * Add sorting settings
This commit is contained in:
parent
2b7b0a9011
commit
9ecf31aecd
|
|
@ -158,7 +158,7 @@ class ProductController extends Controller
|
|||
'tax_classes' => $taxClasses,
|
||||
'weight_classes' => Weight::getWeightUnits(),
|
||||
'source' => [
|
||||
'categories' => CategoryRepo::flatten(locale()),
|
||||
'categories' => CategoryRepo::flatten(locale(), false),
|
||||
],
|
||||
'_redirect' => $this->getRedirect(),
|
||||
];
|
||||
|
|
|
|||
|
|
@ -55,14 +55,18 @@ class CategoryRepo
|
|||
}
|
||||
}
|
||||
|
||||
public static function flatten(string $locale, $separator = ' > '): array
|
||||
public static function flatten(string $locale, $includeInactive = true, $separator = ' > '): array
|
||||
{
|
||||
$sql = "SELECT cp.category_id AS id, TRIM(LOWER(GROUP_CONCAT(cd1.name ORDER BY cp.level SEPARATOR '{$separator}'))) AS name, c1.parent_id, c1.position";
|
||||
$sql .= ' FROM category_paths cp';
|
||||
$sql .= ' LEFT JOIN categories c1 ON (cp.category_id = c1.id)';
|
||||
$sql .= ' LEFT JOIN categories c2 ON (cp.path_id = c2.id)';
|
||||
$sql .= ' LEFT JOIN category_descriptions cd1 ON (cp.path_id = cd1.category_id)';
|
||||
$sql .= " WHERE cd1.locale = '" . $locale . "' GROUP BY cp.category_id ORDER BY name ASC";
|
||||
$sql .= " WHERE cd1.locale = '" . $locale . "' ";
|
||||
if (!$includeInactive) {
|
||||
$sql .= ' AND c1.active = 1 ';
|
||||
}
|
||||
$sql .= ' GROUP BY cp.category_id ORDER BY c1.position ASC';
|
||||
|
||||
return DB::select($sql);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@
|
|||
<x-admin-form-input-locale name="descriptions.*.name" title="{{ __('common.name') }}" :value="$descriptions" :required="true" />
|
||||
<x-admin-form-input-locale name="descriptions.*.content" title="{{ __('admin/builder.modules_content') }}" :value="$descriptions" />
|
||||
|
||||
{{-- <x-admin-form-select title="上级分类" name="parent_id" :value="old('parent_id', $category->parent_id ?? 0)" :options="$categories->toArray()" key="id" label="name" /> --}}
|
||||
<x-admin-form-input name="position" title="{{ __('common.sort_order') }}" :value="old('position', $category->position ?? 0)" />
|
||||
|
||||
<x-admin::form.row title="{{ __('admin/category.parent_category') }}">
|
||||
@php
|
||||
|
|
|
|||
Loading…
Reference in New Issue