Compare commits
4 Commits
62f8deb51f
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
82ed332637 | ||
|
|
bac2ad9a3e | ||
|
|
1b467108de | ||
|
|
774ac3c622 |
@@ -6,6 +6,7 @@ use App\Http\Controllers\Api\V1\Filters\Requests\FilterIndexRequest;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\Ecommerce\Channel\Channel;
|
||||
use App\Models\Ecommerce\Product\Brand\Brand;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use App\Models\Ecommerce\Product\Category\Category;
|
||||
use App\Models\Ecommerce\Product\Collection\Collection;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
@@ -45,7 +46,7 @@ class FilterController extends Controller
|
||||
}
|
||||
|
||||
if ($this->shouldFilterByCollection()) {
|
||||
return $this->filterByCategoryResource(Collection::find($this->request->collection_id));
|
||||
return $this->categoriesFor();
|
||||
}
|
||||
|
||||
if ($this->shouldFilterByBrand()) {
|
||||
@@ -62,29 +63,29 @@ class FilterController extends Controller
|
||||
private function brands()
|
||||
{
|
||||
if ($this->shouldFilterByBrand()) {
|
||||
return Brand::query()->where('id', $this->request->brand_id)->get(['id', 'name']);
|
||||
return Brand::where('id', $this->request->brand_id)->get(['id', 'name']);
|
||||
}
|
||||
|
||||
if ($this->shouldFilterByCategory()) {
|
||||
$brands = Category::query()->find($this->request->category_id)->products()
|
||||
$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');
|
||||
|
||||
return Brand::query()->whereIntegerInRaw('id', $brands)->get(['id', 'name']);
|
||||
return Brand::whereIntegerInRaw('id', $brands)->get(['id', 'name']);
|
||||
}
|
||||
|
||||
if ($this->shouldFilterByCollection()) {
|
||||
$brands = Collection::query()->find($this->request->collection_id)->products()
|
||||
$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');
|
||||
|
||||
return Brand::query()->whereIntegerInRaw('id', $brands)->get(['id', 'name']);
|
||||
return Brand::whereIntegerInRaw('id', $brands)->get(['id', 'name']);
|
||||
}
|
||||
|
||||
return Brand::query()->where('is_visible', true)->ordered()->get(['id', 'name']);
|
||||
@@ -102,12 +103,36 @@ class FilterController extends Controller
|
||||
->distinct('products.id')
|
||||
->pluck('products.id');
|
||||
|
||||
return Category::query()
|
||||
->distinct('categories.id')
|
||||
->where('is_visible', true)
|
||||
->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)
|
||||
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)
|
||||
{
|
||||
return DB::table('categories as c')
|
||||
->select('c.id', 'c.parent_id', 'c.name')
|
||||
->where('c.is_visible', true)
|
||||
->whereExists(function ($query) {
|
||||
$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('p.is_visible', true)
|
||||
->whereNull('p.parent_id')
|
||||
->where('p.stock', '>', 0);
|
||||
})
|
||||
->get()
|
||||
->map(fn ($category) => [
|
||||
'id' => $category->id,
|
||||
|
||||
48
modal.md
48
modal.md
@@ -1,48 +0,0 @@
|
||||
```html
|
||||
<component
|
||||
v-for="(rowField, j) in this.field.fields"
|
||||
:key="j"
|
||||
:is="`form-${rowField.component}`"
|
||||
:field="rowField"
|
||||
class="w-full"
|
||||
/>
|
||||
|
||||
<Modal
|
||||
:show="showModal"
|
||||
size="7xl"
|
||||
tabindex="-1"
|
||||
role="dialog"
|
||||
>
|
||||
<div>
|
||||
<ModalHeader v-text="'Headline of Modal'" class="bg-gray-100 dark:bg-gray-700" />
|
||||
|
||||
<ModalBody>
|
||||
<div class="px-4 py-5 sm:p-6">
|
||||
<ModalForm></ModalForm>
|
||||
</div>
|
||||
</ModalBody>
|
||||
|
||||
<ModalFooter>
|
||||
<div class="flex items-center ml-auto">
|
||||
<CancelButton
|
||||
component="button"
|
||||
type="button"
|
||||
dusk="cancel-action-button"
|
||||
class="ml-auto mr-3"
|
||||
@click="onClose"
|
||||
/>
|
||||
|
||||
<DefaultButton
|
||||
type="submit"
|
||||
@click="onSubmit"
|
||||
>
|
||||
Submit
|
||||
</DefaultButton>
|
||||
</div>
|
||||
</ModalFooter>
|
||||
</div>
|
||||
</Modal>
|
||||
```
|
||||
|
||||
"type": "composer",
|
||||
"url": "https://nova.laravel.com"
|
||||
Reference in New Issue
Block a user