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.
This commit is contained in:
@@ -59,6 +59,11 @@ class UpdateProductRelations implements ShouldQueue
|
|||||||
'product_custom_value' => in_array($attribute->type, ['text', 'number']) ? $this->properties[$attribute->slug] : null,
|
'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();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -134,8 +134,8 @@ class ProductFieldsForDetail
|
|||||||
'name' => $property->attribute->slug,
|
'name' => $property->attribute->slug,
|
||||||
'type' => $property->attribute->type,
|
'type' => $property->attribute->type,
|
||||||
'default' => $property->attribute->type === 'select'
|
'default' => $property->attribute->type === 'select'
|
||||||
? $property->values->first()->value?->id
|
? $property->values->first()->value?->id ?? '-'
|
||||||
: $property->values->first()->product_custom_value,
|
: $property->values->first()->product_custom_value ?? '-',
|
||||||
'options' => $property->attribute->values->map(fn ($value) => [
|
'options' => $property->attribute->values->map(fn ($value) => [
|
||||||
'label' => $value->value,
|
'label' => $value->value,
|
||||||
'value' => $value->id,
|
'value' => $value->id,
|
||||||
|
|||||||
@@ -31,22 +31,10 @@ class ProductPropertyValuesSeeder extends Seeder
|
|||||||
DB::table($table)->insert([
|
DB::table($table)->insert([
|
||||||
'id' => $data['id'],
|
'id' => $data['id'],
|
||||||
'attribute_id' => $data['attribute_id'],
|
'attribute_id' => $data['attribute_id'],
|
||||||
|
'value' => str_replace('"tm"', '"tk"', $data['name']),
|
||||||
// "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"
|
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
// "string_value": "Ci4wU42HuY",
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user