Compare commits
10 Commits
c23d0eeab0
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6093a45761 | ||
|
|
7f0b92a7ff | ||
|
|
715acc4e97 | ||
|
|
859e4ebbe8 | ||
|
|
24b85763e5 | ||
|
|
a6cf6410b2 | ||
|
|
8c4e214e7b | ||
|
|
e227b24de5 | ||
|
|
79b10b20ea | ||
|
|
fa9d9b68b5 |
@@ -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')) {
|
if (! function_exists('removeWhiteSpace')) {
|
||||||
/**
|
/**
|
||||||
* Remove white sapce from string
|
* Remove white sapce from string
|
||||||
|
|||||||
@@ -27,11 +27,7 @@ class FilterController extends Controller
|
|||||||
public function index(FilterIndexRequest $request): JsonResponse
|
public function index(FilterIndexRequest $request): JsonResponse
|
||||||
{
|
{
|
||||||
return response()->rest([
|
return response()->rest([
|
||||||
'categories' => $this->categories()->map(fn ($category) => [
|
'categories' => $this->categories(),
|
||||||
'id' => $category->id,
|
|
||||||
'parent_id' => $category->parent_id,
|
|
||||||
'name' => $category->name,
|
|
||||||
]),
|
|
||||||
'brands' => $this->brands(),
|
'brands' => $this->brands(),
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
@@ -42,7 +38,17 @@ class FilterController extends Controller
|
|||||||
private function categories()
|
private function categories()
|
||||||
{
|
{
|
||||||
if ($this->shouldFilterByCategory()) {
|
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()) {
|
if ($this->shouldFilterByCollection()) {
|
||||||
@@ -50,11 +56,11 @@ class FilterController extends Controller
|
|||||||
}
|
}
|
||||||
|
|
||||||
if ($this->shouldFilterByBrand()) {
|
if ($this->shouldFilterByBrand()) {
|
||||||
return $this->filterByCategoryResource(Brand::find($this->request->brand_id));
|
return $this->categoriesForBrand($this->request->brand_id);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->shouldFilterByChannel()) {
|
if ($this->shouldFilterByChannel()) {
|
||||||
return $this->filterByCategoryResource($this->request->channel_id, 'category');
|
return $this->categoriesFor($this->request->channel_id, 'channel');
|
||||||
}
|
}
|
||||||
|
|
||||||
return Category::query()->where('is_visible', true)->ordered()->get(['id', 'parent_id', 'name']);
|
return Category::query()->where('is_visible', true)->ordered()->get(['id', 'parent_id', 'name']);
|
||||||
@@ -63,55 +69,63 @@ class FilterController extends Controller
|
|||||||
private function brands()
|
private function brands()
|
||||||
{
|
{
|
||||||
if ($this->shouldFilterByBrand()) {
|
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()) {
|
if ($this->shouldFilterByCategory()) {
|
||||||
$brands = Category::find($this->request->category_id)->products()
|
$categoryId = (int) $this->request->category_id;
|
||||||
->where('products.is_visible', true)
|
|
||||||
->where('products.parent_id', null)
|
|
||||||
->where('products.stock', '>', 0)
|
|
||||||
->distinct('products.brand_id')
|
|
||||||
->pluck('products.brand_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()) {
|
if ($this->shouldFilterByCollection()) {
|
||||||
$brands = Collection::find($this->request->collection_id)->products()
|
$collectionId = (int) $this->request->collection_id;
|
||||||
->where('products.is_visible', true)
|
|
||||||
->where('products.parent_id', null)
|
|
||||||
->where('products.stock', '>', 0)
|
|
||||||
->distinct('products.brand_id')
|
|
||||||
->pluck('products.brand_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']);
|
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
|
* Categories for a resource
|
||||||
*/
|
*/
|
||||||
@@ -137,7 +151,33 @@ class FilterController extends Controller
|
|||||||
->map(fn ($category) => [
|
->map(fn ($category) => [
|
||||||
'id' => $category->id,
|
'id' => $category->id,
|
||||||
'parent_id' => $category->parent_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),
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
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