Compare commits
12 Commits
f365bff782
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6093a45761 | ||
|
|
7f0b92a7ff | ||
|
|
715acc4e97 | ||
|
|
859e4ebbe8 | ||
|
|
24b85763e5 | ||
|
|
a6cf6410b2 | ||
|
|
8c4e214e7b | ||
|
|
e227b24de5 | ||
|
|
79b10b20ea | ||
|
|
fa9d9b68b5 | ||
|
|
c23d0eeab0 | ||
|
|
14b47d40e8 |
@@ -32,6 +32,20 @@ if (! function_exists('translatable')) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Translate
|
||||
*/
|
||||
function tr(string $text, string $locale = 'tk'): string
|
||||
{
|
||||
$text = json_decode($text);
|
||||
|
||||
if ($text) {
|
||||
return $text->{$locale} ?? '';
|
||||
}
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
if (! function_exists('removeWhiteSpace')) {
|
||||
/**
|
||||
* Remove white sapce from string
|
||||
|
||||
@@ -27,11 +27,7 @@ class FilterController extends Controller
|
||||
public function index(FilterIndexRequest $request): JsonResponse
|
||||
{
|
||||
return response()->rest([
|
||||
'categories' => $this->categories()->map(fn ($category) => [
|
||||
'id' => $category->id,
|
||||
'parent_id' => $category->parent_id,
|
||||
'name' => $category->name,
|
||||
]),
|
||||
'categories' => $this->categories(),
|
||||
'brands' => $this->brands(),
|
||||
]);
|
||||
}
|
||||
@@ -42,19 +38,29 @@ class FilterController extends Controller
|
||||
private function categories()
|
||||
{
|
||||
if ($this->shouldFilterByCategory()) {
|
||||
return Category::find($this->request->category_id, ['id', 'parent_id'])->children()->get(['id', 'parent_id', 'name']);
|
||||
return Category::query()
|
||||
->find($this->request->category_id, ['id', 'parent_id'])
|
||||
->children()
|
||||
->where('is_visible', true)
|
||||
->ordered()
|
||||
->get(['id', 'parent_id', 'name'])
|
||||
->map(fn ($category) => [
|
||||
'id' => $category->id,
|
||||
'parent_id' => $category->parent_id,
|
||||
'name' => $category->name,
|
||||
]);
|
||||
}
|
||||
|
||||
if ($this->shouldFilterByCollection()) {
|
||||
return $this->categoriesFor();
|
||||
return $this->categoriesFor($this->request->collection_id, 'collection');
|
||||
}
|
||||
|
||||
if ($this->shouldFilterByBrand()) {
|
||||
return $this->filterByCategoryResource(Brand::find($this->request->brand_id));
|
||||
return $this->categoriesForBrand($this->request->brand_id);
|
||||
}
|
||||
|
||||
if ($this->shouldFilterByChannel()) {
|
||||
return $this->filterByCategoryResource(Channel::find($this->request->channel_id));
|
||||
return $this->categoriesFor($this->request->channel_id, 'channel');
|
||||
}
|
||||
|
||||
return Category::query()->where('is_visible', true)->ordered()->get(['id', 'parent_id', 'name']);
|
||||
@@ -63,72 +69,80 @@ class FilterController extends Controller
|
||||
private function brands()
|
||||
{
|
||||
if ($this->shouldFilterByBrand()) {
|
||||
return Brand::where('id', $this->request->brand_id)->get(['id', 'name']);
|
||||
return Brand::query()->where('id', $this->request->brand_id)->get(['id', 'name']);
|
||||
}
|
||||
|
||||
if ($this->shouldFilterByCategory()) {
|
||||
$brands = Category::find($this->request->category_id)->products()
|
||||
->where('products.is_visible', true)
|
||||
->where('products.parent_id', null)
|
||||
->where('products.stock', '>', 0)
|
||||
->distinct('products.brand_id')
|
||||
->pluck('products.brand_id');
|
||||
$categoryId = (int) $this->request->category_id;
|
||||
|
||||
return Brand::whereIntegerInRaw('id', $brands)->get(['id', 'name']);
|
||||
return DB::table('brands')
|
||||
->select('brands.id', 'brands.name')
|
||||
->join('products', 'products.brand_id', '=', 'brands.id')
|
||||
->join('product_has_relations', 'products.id', '=', 'product_has_relations.product_id')
|
||||
->where('product_has_relations.productable_type', 'category')
|
||||
->where('product_has_relations.productable_id', $categoryId)
|
||||
->where('products.is_visible', true)
|
||||
->whereNull('products.parent_id')
|
||||
->where('products.stock', '>', 0)
|
||||
->groupBy('brands.id', 'brands.name', 'brands.sort_order')
|
||||
->orderBy('brands.sort_order')
|
||||
->get();
|
||||
}
|
||||
|
||||
if ($this->shouldFilterByCollection()) {
|
||||
$brands = Collection::find($this->request->collection_id)->products()
|
||||
->where('products.is_visible', true)
|
||||
->where('products.parent_id', null)
|
||||
->where('products.stock', '>', 0)
|
||||
->distinct('products.brand_id')
|
||||
->pluck('products.brand_id');
|
||||
$collectionId = (int) $this->request->collection_id;
|
||||
|
||||
return Brand::whereIntegerInRaw('id', $brands)->get(['id', 'name']);
|
||||
return DB::table('brands')
|
||||
->select('brands.id', 'brands.name')
|
||||
->join('products', 'products.brand_id', '=', 'brands.id')
|
||||
->join('product_has_relations', 'products.id', '=', 'product_has_relations.product_id')
|
||||
->where('product_has_relations.productable_type', 'collection')
|
||||
->where('product_has_relations.productable_id', $collectionId)
|
||||
->where('products.is_visible', true)
|
||||
->whereNull('products.parent_id')
|
||||
->where('products.stock', '>', 0)
|
||||
->groupBy('brands.id', 'brands.name', 'brands.sort_order')
|
||||
->orderBy('brands.sort_order')
|
||||
->get();
|
||||
}
|
||||
|
||||
if ($this->shouldFilterByChannel()) {
|
||||
$channelId = (int) $this->request->channel_id;
|
||||
|
||||
return DB::table('brands')
|
||||
->select('brands.id', 'brands.name')
|
||||
->join('products', 'products.brand_id', '=', 'brands.id')
|
||||
->join('product_has_relations', 'products.id', '=', 'product_has_relations.product_id')
|
||||
->where('product_has_relations.productable_type', 'channel')
|
||||
->where('product_has_relations.productable_id', $channelId)
|
||||
->where('products.is_visible', true)
|
||||
->whereNull('products.parent_id')
|
||||
->where('products.stock', '>', 0)
|
||||
->groupBy('brands.id', 'brands.name', 'brands.sort_order')
|
||||
->orderBy('brands.sort_order')
|
||||
->get();
|
||||
}
|
||||
|
||||
return Brand::query()->where('is_visible', true)->ordered()->get(['id', 'name']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Filter by category
|
||||
*/
|
||||
private function filterByCategoryResource($resource)
|
||||
{
|
||||
$products = $resource->products()
|
||||
->where('products.is_visible', true)
|
||||
->where('products.parent_id', null)
|
||||
->where('products.stock', '>', 0)
|
||||
->distinct('products.id')
|
||||
->pluck('products.id');
|
||||
|
||||
return Category::where('is_visible', true)
|
||||
->ordered()
|
||||
->join('product_has_relations', 'categories.id', '=', 'product_has_relations.productable_id')
|
||||
->where('product_has_relations.productable_type', '=', 'category')
|
||||
->whereIntegerInRaw('product_has_relations.product_id', $products)
|
||||
->get(['categories.id', 'categories.parent_id', 'categories.name'])
|
||||
->unique('categories.id');
|
||||
}
|
||||
|
||||
/**
|
||||
* Categories for a resource
|
||||
*/
|
||||
private function categoriesFor($resource)
|
||||
private function categoriesFor(int $id, string $type)
|
||||
{
|
||||
return DB::table('categories as c')
|
||||
->select('c.id', 'c.parent_id', 'c.name')
|
||||
->where('c.is_visible', true)
|
||||
->whereExists(function ($query) {
|
||||
->whereExists(function ($query) use ($id, $type) {
|
||||
$query->select(DB::raw(1))
|
||||
->from('product_has_relations as phr_cat')
|
||||
->join('products as p', 'p.id', '=', 'phr_cat.product_id')
|
||||
->join('product_has_relations as phr_chan', 'phr_chan.product_id', '=', 'p.id')
|
||||
->whereColumn('phr_cat.productable_id', 'c.id')
|
||||
->where('phr_cat.productable_type', 'category')
|
||||
->where('phr_chan.productable_type', 'channel')
|
||||
->where('phr_chan.productable_id', 6)
|
||||
->where('phr_chan.productable_type', $type)
|
||||
->where('phr_chan.productable_id', $id)
|
||||
->where('p.is_visible', true)
|
||||
->whereNull('p.parent_id')
|
||||
->where('p.stock', '>', 0);
|
||||
@@ -137,7 +151,33 @@ class FilterController extends Controller
|
||||
->map(fn ($category) => [
|
||||
'id' => $category->id,
|
||||
'parent_id' => $category->parent_id,
|
||||
'name' => $category->name,
|
||||
'name' => tr($category->name),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Brands
|
||||
*/
|
||||
private function categoriesForBrand(int $id)
|
||||
{
|
||||
return DB::table('categories')
|
||||
->select('categories.id', 'categories.parent_id', 'categories.name')
|
||||
->join('product_has_relations', function ($join) {
|
||||
$join->on('categories.id', '=', 'product_has_relations.productable_id')
|
||||
->where('product_has_relations.productable_type', 'category');
|
||||
})
|
||||
->join('products', 'product_has_relations.product_id', '=', 'products.id')
|
||||
->where('products.brand_id', $id)
|
||||
->where('products.is_visible', true)
|
||||
->whereNull('products.parent_id')
|
||||
->where('products.stock', '>', 0)
|
||||
->where('categories.is_visible', true)
|
||||
->distinct()
|
||||
->get()
|
||||
->map(fn ($category) => [
|
||||
'id' => $category->id,
|
||||
'parent_id' => $category->parent_id,
|
||||
'name' => tr($category->name),
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
46
composer.lock
generated
46
composer.lock
generated
@@ -3307,31 +3307,31 @@
|
||||
},
|
||||
{
|
||||
"name": "maennchen/zipstream-php",
|
||||
"version": "3.2.2",
|
||||
"version": "3.1.2",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/maennchen/ZipStream-PHP.git",
|
||||
"reference": "77bebeb4c6c340bb3c11c843b2cffd8bbfde4d5e"
|
||||
"reference": "aeadcf5c412332eb426c0f9b4485f6accba2a99f"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/maennchen/ZipStream-PHP/zipball/77bebeb4c6c340bb3c11c843b2cffd8bbfde4d5e",
|
||||
"reference": "77bebeb4c6c340bb3c11c843b2cffd8bbfde4d5e",
|
||||
"url": "https://api.github.com/repos/maennchen/ZipStream-PHP/zipball/aeadcf5c412332eb426c0f9b4485f6accba2a99f",
|
||||
"reference": "aeadcf5c412332eb426c0f9b4485f6accba2a99f",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"ext-mbstring": "*",
|
||||
"ext-zlib": "*",
|
||||
"php-64bit": "^8.3"
|
||||
"php-64bit": "^8.2"
|
||||
},
|
||||
"require-dev": {
|
||||
"brianium/paratest": "^7.7",
|
||||
"ext-zip": "*",
|
||||
"friendsofphp/php-cs-fixer": "^3.86",
|
||||
"friendsofphp/php-cs-fixer": "^3.16",
|
||||
"guzzlehttp/guzzle": "^7.5",
|
||||
"mikey179/vfsstream": "^1.6",
|
||||
"php-coveralls/php-coveralls": "^2.5",
|
||||
"phpunit/phpunit": "^12.0",
|
||||
"phpunit/phpunit": "^11.0",
|
||||
"vimeo/psalm": "^6.0"
|
||||
},
|
||||
"suggest": {
|
||||
@@ -3373,7 +3373,7 @@
|
||||
],
|
||||
"support": {
|
||||
"issues": "https://github.com/maennchen/ZipStream-PHP/issues",
|
||||
"source": "https://github.com/maennchen/ZipStream-PHP/tree/3.2.2"
|
||||
"source": "https://github.com/maennchen/ZipStream-PHP/tree/3.1.2"
|
||||
},
|
||||
"funding": [
|
||||
{
|
||||
@@ -3381,7 +3381,7 @@
|
||||
"type": "github"
|
||||
}
|
||||
],
|
||||
"time": "2026-04-11T18:38:28+00:00"
|
||||
"time": "2025-01-27T12:07:53+00:00"
|
||||
},
|
||||
{
|
||||
"name": "markbaker/complex",
|
||||
@@ -4359,16 +4359,16 @@
|
||||
},
|
||||
{
|
||||
"name": "openspout/openspout",
|
||||
"version": "v4.32.0",
|
||||
"version": "v4.28.5",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/openspout/openspout.git",
|
||||
"reference": "41f045c1f632e1474e15d4c7bc3abcb4a153563d"
|
||||
"reference": "ab05a09fe6fce57c90338f83280648a9786ce36b"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/openspout/openspout/zipball/41f045c1f632e1474e15d4c7bc3abcb4a153563d",
|
||||
"reference": "41f045c1f632e1474e15d4c7bc3abcb4a153563d",
|
||||
"url": "https://api.github.com/repos/openspout/openspout/zipball/ab05a09fe6fce57c90338f83280648a9786ce36b",
|
||||
"reference": "ab05a09fe6fce57c90338f83280648a9786ce36b",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
@@ -4378,17 +4378,17 @@
|
||||
"ext-libxml": "*",
|
||||
"ext-xmlreader": "*",
|
||||
"ext-zip": "*",
|
||||
"php": "~8.3.0 || ~8.4.0 || ~8.5.0"
|
||||
"php": "~8.2.0 || ~8.3.0 || ~8.4.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"ext-zlib": "*",
|
||||
"friendsofphp/php-cs-fixer": "^3.86.0",
|
||||
"infection/infection": "^0.31.2",
|
||||
"phpbench/phpbench": "^1.4.1",
|
||||
"phpstan/phpstan": "^2.1.22",
|
||||
"phpstan/phpstan-phpunit": "^2.0.7",
|
||||
"phpstan/phpstan-strict-rules": "^2.0.6",
|
||||
"phpunit/phpunit": "^12.3.7"
|
||||
"friendsofphp/php-cs-fixer": "^3.68.3",
|
||||
"infection/infection": "^0.29.10",
|
||||
"phpbench/phpbench": "^1.4.0",
|
||||
"phpstan/phpstan": "^2.1.2",
|
||||
"phpstan/phpstan-phpunit": "^2.0.4",
|
||||
"phpstan/phpstan-strict-rules": "^2",
|
||||
"phpunit/phpunit": "^11.5.4"
|
||||
},
|
||||
"suggest": {
|
||||
"ext-iconv": "To handle non UTF-8 CSV files (if \"php-mbstring\" is not already installed or is too limited)",
|
||||
@@ -4436,7 +4436,7 @@
|
||||
],
|
||||
"support": {
|
||||
"issues": "https://github.com/openspout/openspout/issues",
|
||||
"source": "https://github.com/openspout/openspout/tree/v4.32.0"
|
||||
"source": "https://github.com/openspout/openspout/tree/v4.28.5"
|
||||
},
|
||||
"funding": [
|
||||
{
|
||||
@@ -4448,7 +4448,7 @@
|
||||
"type": "github"
|
||||
}
|
||||
],
|
||||
"time": "2025-09-03T16:03:54+00:00"
|
||||
"time": "2025-01-30T13:51:11+00:00"
|
||||
},
|
||||
{
|
||||
"name": "outl1ne/nova-multiselect-field",
|
||||
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
resources/docs/order/invoice/Копия invoice.docx
Normal file
BIN
resources/docs/order/invoice/Копия invoice.docx
Normal file
Binary file not shown.
Binary file not shown.
Binary file not shown.
Reference in New Issue
Block a user