From 8bab835d61fab3cd9bfdf1e358d05a80ebd092a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Munsch?= Date: Fri, 24 Mar 2023 13:37:50 +0100 Subject: [PATCH] Fixes #31 #32 Change incoInputs - Inco products servings are nullable and are now strings - Inco products servings type are nullable --- app/Enums/Product/DefaultProductType.php | 6 ++- ...nge_inco_servings_input_type_on_orders.php | 41 +++++++++++++++++++ resources/theme | 2 +- 3 files changed, 46 insertions(+), 3 deletions(-) create mode 100644 database/migrations/2023_03_24_132440_change_inco_servings_input_type_on_orders.php diff --git a/app/Enums/Product/DefaultProductType.php b/app/Enums/Product/DefaultProductType.php index 276de1f..f17946a 100644 --- a/app/Enums/Product/DefaultProductType.php +++ b/app/Enums/Product/DefaultProductType.php @@ -63,14 +63,16 @@ final class DefaultProductType extends BaseEnumRoutable ], 'servings' => [ 'label' => 'Portions', - 'inputType' => InputType::number(), + 'inputType' => InputType::string(), 'value' => '', - 'validate' => 'numeric|min:0' + 'required' => false, + 'validate' => 'nullable|string|max:35' ], 'servings_type' => [ 'label' => 'Type de portions', 'inputType' => InputType::string(), 'value' => '', + 'required' => false, 'validate' => 'nullable|string|max:150' ], ]; diff --git a/database/migrations/2023_03_24_132440_change_inco_servings_input_type_on_orders.php b/database/migrations/2023_03_24_132440_change_inco_servings_input_type_on_orders.php new file mode 100644 index 0000000..7941c42 --- /dev/null +++ b/database/migrations/2023_03_24_132440_change_inco_servings_input_type_on_orders.php @@ -0,0 +1,41 @@ +where('type', DefaultProductType::inco())->each(function (Product $product) { + $data = $product->data; + $value = $data['servings']['value']; + $valueSt = $data['servings_type']['value']; + + $data['servings'] = DefaultProductType::incoInputs()['servings']; + $data['servings_type'] = DefaultProductType::incoInputs()['servings_type']; + + $data['servings']['value'] = strval($value); + $data['servings_type']['value'] = strval($valueSt); + + $product->data = $data; + $product->saveQuietly(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + // Won't undo this. + } +} diff --git a/resources/theme b/resources/theme index ca1385e..74b13d4 160000 --- a/resources/theme +++ b/resources/theme @@ -1 +1 @@ -Subproject commit ca1385e4cac559380e326b714d4c0d7096873020 +Subproject commit 74b13d406df2c37ee2e77056615db53f019dd736