fix: 🐛 update promotion filtering system
This commit is contained in:
parent
caa157adaf
commit
0692ec70c5
4 changed files with 48 additions and 22 deletions
|
|
@ -5,6 +5,7 @@ namespace App\Http\Controllers;
|
|||
use App\Http\Requests\ProductsFilterRequest;
|
||||
use App\Http\Resources\ProductResource;
|
||||
use App\Models\Product;
|
||||
use App\Models\Promotion;
|
||||
use App\Models\Range;
|
||||
use App\Models\Tag;
|
||||
use Illuminate\Http\Request;
|
||||
|
|
@ -99,7 +100,8 @@ class ProductsController extends Controller
|
|||
} else {
|
||||
$ranges = Range::all();
|
||||
$tags = Tag::where('status', true)->get();
|
||||
return view('ranges', compact('products', 'ranges', 'tags', 'sessionFilter', 'filtersMenuIsOpen', 'brands'));
|
||||
$hasPromotion = Promotion::where('date_start', '<=', now())->where('date_end', '>=', now())->get();
|
||||
return view('ranges', compact('products', 'ranges', 'tags', 'sessionFilter', 'filtersMenuIsOpen', 'brands', 'hasPromotion'));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -116,7 +118,7 @@ class ProductsController extends Controller
|
|||
if (!empty($sessionFilter->search)) {
|
||||
$productsQuery->where('name', 'LIKE', '%' . $sessionFilter->search . '%');
|
||||
}
|
||||
if (!empty($sessionFilter->promotion)) {
|
||||
if (!empty($sessionFilter->promotions)) {
|
||||
$productsQuery->whereHas('promotions');
|
||||
}
|
||||
if (!empty($sessionFilter->ranges)) {
|
||||
|
|
|
|||
|
|
@ -0,0 +1,36 @@
|
|||
<?php
|
||||
|
||||
use App\Models\Tag;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class DeletePromotionTag extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
DB::table('product_tag')
|
||||
->where('tag_id', 13)
|
||||
->delete();
|
||||
|
||||
Tag::where('slug', 'promotion')->delete();
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
$promotion = new Tag();
|
||||
$promotion->label = "Promotion";
|
||||
$promotion->slug = Str::slug($promotion->label);
|
||||
$promotion->save();
|
||||
}
|
||||
}
|
||||
|
|
@ -22,24 +22,6 @@
|
|||
<!--</form>-->
|
||||
</div>
|
||||
<div class="accordion px-3" id="accordionFilters">
|
||||
<!-- Filter Promotions -->
|
||||
<!-- <div class="accordion-item rounded-0 border-0 bg-transparent mt-2">
|
||||
<h2 class="accordion-header" id="headingPromotions">
|
||||
<button class="accordion-button text-dark bg-transparent rounded-0 border-0 border-bottom border-3 border-secondary-subtle px-0 py-2 collapsed" type="button" data-bs-toggle="collapse" data-bs-target="#collapsePromotions" aria-expanded="true" aria-controls="collapsePromotions">
|
||||
<span class="title-small font-Barlow-bold">Promotions</span>
|
||||
</button>
|
||||
</h2>
|
||||
<div id="collapsePromotions" class="accordion-collapse collapse" aria-labelledby="headingPromotions" data-bs-parent="#accordionFilters">
|
||||
<div class="accordion-body p-0">
|
||||
<div class="form-check d-flex flex-row flex-lg-row-reverse justify-content-between align-items-center rounded-2 px-3 py-2 p-lg-0 mt-2 mb-0">
|
||||
<input v-on:click="updatedFilter()" v-model="hasPromotion" :disabled="loading" class="form-check-input m-0" type="checkbox" role="button" id="filterPromotions">
|
||||
<label class="form-check-label w-100 ps-3 pe-0 ps-lg-0 pe-lg-3" role="button" for="filterPromotions">
|
||||
Promotions
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div> -->
|
||||
<!-- Filter Ranges -->
|
||||
<div class="accordion-item rounded-0 border-0 bg-transparent mt-2">
|
||||
<h2 class="accordion-header" id="headingRanges">
|
||||
|
|
@ -103,6 +85,12 @@
|
|||
{{ tag.label }}
|
||||
</label>
|
||||
</div>
|
||||
<div class="form-check d-flex flex-row flex-lg-row-reverse justify-content-between align-items-center rounded-2 px-3 py-2 p-lg-0 mt-2 mb-0">
|
||||
<input v-on:click="updatedFilter()" v-model="hasPromotion" :disabled="loading" class="form-check-input m-0" type="checkbox" role="button" id="filterPromotions">
|
||||
<label class="form-check-label w-100 ps-3 pe-0 ps-lg-0 pe-lg-3" role="button" for="filterPromotions">
|
||||
Promotions
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
@ -181,7 +169,7 @@
|
|||
</template>
|
||||
|
||||
<script>
|
||||
import BasketButtons from './BasketButtons.vue';
|
||||
import BasketButtons from './BasketButtons.vue';
|
||||
export default {
|
||||
components: {
|
||||
BasketButtons
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@
|
|||
<section id="ranges" class="vue-apps">
|
||||
@php
|
||||
$dataComponent = [
|
||||
'hasPromotion' => request()->promotion ? true : false,
|
||||
'hasPromotion' => $hasPromotion ? true : false,
|
||||
'ranges' => $ranges,
|
||||
'brands' => $brands,
|
||||
'tags' => $tags,
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue