set availability of a product

This commit is contained in:
Alexis Gousseau 2022-10-10 10:37:40 +02:00
parent 4c04cd7d29
commit ba1405ba8a
4 changed files with 58 additions and 3 deletions

View file

@ -18,7 +18,9 @@ class ProductResource extends JsonResource
'description' => '',
'price' => 0,
'discountedPriceHt' => 0,
'picture' => ''
'picture' => '',
'orderable_start' => '',
'orderable_end' => ''
];
/**

View file

@ -0,0 +1,32 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class AddAvailableToProducts extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('products', function (Blueprint $table) {
$table->boolean('availability')->nullable()->after('status');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('products', function (Blueprint $table) {
$table->dropColumn('availability');
});
}
}

View file

@ -137,7 +137,10 @@
</div>
<div v-else class="row m-0 g-4">
<!-- card article -->
<article v-for="(product, productIndex) in showedProducts" :key="productIndex" class="col-sm-4 rounded-4 p-3 m-0 position-relative card">
<article v-for="(product, productIndex) in showedProducts"
:key="productIndex"
class="col-sm-4 rounded-4 p-3 m-0 position-relative card"
v-bind:class="[!product.availability ? 'card-available-soon' : '']">
<div class="d-flex flex-row flex-lg-column justify-content-between align-items-center col-md-4 p-0 w-100 m-0">
<div class="position-relative text-center w-50 w-lg-100">
<p class="position-absolute top-50 start-50 translate-middle font-Barlow-bold title-small text-uppercase d-none text-center m-0">
@ -264,6 +267,7 @@
break
}
let product = Object.assign({}, this.products[id])
product.availability = this.getAvailability(product)
this.$set(this.showedProducts, k++, product)
}
@ -315,6 +319,23 @@
tags: this.tags.filter((tag) => tag.selected)
.map((tag) => tag.id),
};
},
// Return the availability of a product.
getAvailability(product) {
if(product.orderable_start != null && product.orderable_end != null){
let dateNow = new Date()
let dateStart = new Date(product.orderable_start)
let dateEnd = new Date(product.orderable_end)
if(dateNow > dateStart && dateNow < dateEnd) {
return true
}
else {
return false
}
}
else {
return true
}
}
}
}

View file

@ -18,7 +18,7 @@
@endif
</div>
<!-- PRODUCT'S DESCRIPTION -->
<div class="d-flex flex-column-reverse justify-content-between align-items-center flex-md-column justify-content-md-start p-2">
<div class="d-flex flex-column-reverse flex-md-column justify-content-between justify-content-md-start align-items-start p-2">
<div>
<h1 class="position-fixed position-lg-relative product-title text-center text-lg-start text-dark m-0">{{ $product->name }}</h1>
{!! $product->description !!}