From 9fac84a8827d28b663329edb815f26564e237542 Mon Sep 17 00:00:00 2001 From: Mekan1206 Date: Mon, 9 Feb 2026 23:15:56 +0500 Subject: [PATCH] Enhance product handling and seeding logic - Added a call to sync properties JSON in UpdateProductRelations job if the method exists. - Updated ProductFieldsForDetail to provide a default value of '-' for missing property values. - Simplified the insertion logic in ProductPropertyValuesSeeder by replacing 'tm' with 'tk' in the value field and removed commented-out code for clarity. --- .../Product/UpdateProductRelations.php | 5 +++++ .../Concerns/ProductFieldsForDetail.php | 4 ++-- .../new/ProductPropertyValuesSeeder.php | 18 +++--------------- 3 files changed, 10 insertions(+), 17 deletions(-) diff --git a/app/Jobs/Ecommerce/Product/UpdateProductRelations.php b/app/Jobs/Ecommerce/Product/UpdateProductRelations.php index 535b592..697f339 100644 --- a/app/Jobs/Ecommerce/Product/UpdateProductRelations.php +++ b/app/Jobs/Ecommerce/Product/UpdateProductRelations.php @@ -59,6 +59,11 @@ class UpdateProductRelations implements ShouldQueue 'product_custom_value' => in_array($attribute->type, ['text', 'number']) ? $this->properties[$attribute->slug] : null, ]); }); + + // sync properties json + if (method_exists($this->model, 'syncPropertiesJson')) { + $this->model->syncPropertiesJson(); + } }); } } diff --git a/app/Nova/Resources/Ecommerce/Product/Product/Concerns/ProductFieldsForDetail.php b/app/Nova/Resources/Ecommerce/Product/Product/Concerns/ProductFieldsForDetail.php index fe1c16e..c631c60 100644 --- a/app/Nova/Resources/Ecommerce/Product/Product/Concerns/ProductFieldsForDetail.php +++ b/app/Nova/Resources/Ecommerce/Product/Product/Concerns/ProductFieldsForDetail.php @@ -134,8 +134,8 @@ class ProductFieldsForDetail 'name' => $property->attribute->slug, 'type' => $property->attribute->type, 'default' => $property->attribute->type === 'select' - ? $property->values->first()->value?->id - : $property->values->first()->product_custom_value, + ? $property->values->first()->value?->id ?? '-' + : $property->values->first()->product_custom_value ?? '-', 'options' => $property->attribute->values->map(fn ($value) => [ 'label' => $value->value, 'value' => $value->id, diff --git a/database/seeders/new/ProductPropertyValuesSeeder.php b/database/seeders/new/ProductPropertyValuesSeeder.php index 8342877..0e28cc3 100644 --- a/database/seeders/new/ProductPropertyValuesSeeder.php +++ b/database/seeders/new/ProductPropertyValuesSeeder.php @@ -31,22 +31,10 @@ class ProductPropertyValuesSeeder extends Seeder DB::table($table)->insert([ 'id' => $data['id'], 'attribute_id' => $data['attribute_id'], - - // "name": "{\"en\": \"8 GB\", \"ru\": \"8 GB\", \"tm\": \"8 GB\"}", - // "description": null, - // "string_value": "Ci4wU42HuY", - // "text_value": null, - // "integer_value": null, - // "float_value": null, - // "boolean_value": null, - // "date_value": null, - // "datetime_value": null, - // "json_value": null, - // "image_value": null, - // "file_value": null, - // "created_at": "2025-06-10 16:12:32", - // "updated_at": "2025-06-10 16:12:34" + 'value' => str_replace('"tm"', '"tk"', $data['name']), ]); + + // "string_value": "Ci4wU42HuY", } }); }