Se agregan los campos por segmento
This commit is contained in:
@ -114,7 +114,15 @@ class Model {
|
||||
return $data;
|
||||
}
|
||||
protected function fillObject($data): BaseModel {
|
||||
$obj = new $this->class;
|
||||
$class = $this->class;
|
||||
if (strpos($class, 'Producto') !== false) {
|
||||
$segmento = str_replace(' ', '', $data->segmento);
|
||||
$class = implode("\\", [
|
||||
$class . 's',
|
||||
rtrim($segmento, 's')
|
||||
]);
|
||||
}
|
||||
$obj = new $class;
|
||||
$obj->map($data);
|
||||
$obj->setFactory($this);
|
||||
$obj->setImageFolder($this->image_folder);
|
||||
@ -139,6 +147,13 @@ class Model {
|
||||
}
|
||||
|
||||
public function create(string $class, $data) {
|
||||
if (strpos($class, 'Producto') !== false) {
|
||||
$segmento = str_replace(' ', '', $data->segmento);
|
||||
$class = implode("\\", [
|
||||
$class . 's',
|
||||
rtrim($segmento, 's')
|
||||
]);
|
||||
}
|
||||
$obj = new $class;
|
||||
$obj->map($data);
|
||||
$obj->setFactory($this);
|
||||
|
@ -47,9 +47,14 @@ abstract class Model implements \JsonSerializable {
|
||||
protected function getFilename(): string {
|
||||
$data = explode("\\", get_called_class());
|
||||
$folder = $this->factory->getFolder();
|
||||
$class = array_pop($data);
|
||||
$productos = ['Bodega', 'Oficina', 'Retail', 'Terreno'];
|
||||
if (array_search($class, $productos) !== false) {
|
||||
$class = 'Producto';
|
||||
}
|
||||
return implode(DIRECTORY_SEPARATOR, [
|
||||
$folder,
|
||||
str_replace(' ', '_', mb_strtolower(array_pop($data))) . 's.json'
|
||||
str_replace(' ', '_', mb_strtolower($class)) . 's.json'
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user