diff --git a/app/Http/Resources/ProductResource.php b/app/Http/Resources/ProductResource.php index c5e80529..9a32f4bb 100644 --- a/app/Http/Resources/ProductResource.php +++ b/app/Http/Resources/ProductResource.php @@ -18,7 +18,9 @@ class ProductResource extends JsonResource 'description' => '', 'price' => 0, 'discountedPriceHt' => 0, - 'picture' => '' + 'picture' => '', + 'orderable_start' => '', + 'orderable_end' => '' ]; /** diff --git a/database/migrations/2022_10_10_103617_add_available_to_products.php b/database/migrations/2022_10_10_103617_add_available_to_products.php new file mode 100644 index 00000000..59deb146 --- /dev/null +++ b/database/migrations/2022_10_10_103617_add_available_to_products.php @@ -0,0 +1,32 @@ +boolean('availability')->nullable()->after('status'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('products', function (Blueprint $table) { + $table->dropColumn('availability'); + }); + } +} diff --git a/resources/views/front/sable/js/components/FilterComponent.vue b/resources/views/front/sable/js/components/FilterComponent.vue index e37ca9fc..db400f02 100644 --- a/resources/views/front/sable/js/components/FilterComponent.vue +++ b/resources/views/front/sable/js/components/FilterComponent.vue @@ -137,7 +137,10 @@
-
+

@@ -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 + } } } } diff --git a/resources/views/front/sable/product.blade.php b/resources/views/front/sable/product.blade.php index 53d1a518..0a0c693e 100644 --- a/resources/views/front/sable/product.blade.php +++ b/resources/views/front/sable/product.blade.php @@ -18,7 +18,7 @@ @endif

-
+

{{ $product->name }}

{!! $product->description !!}