FIX: Agregar o editar producto

This commit is contained in:
2020-05-29 20:00:40 -04:00
parent 88df2f547a
commit 4796639b2e
4 changed files with 20 additions and 5 deletions

View File

@ -63,7 +63,7 @@ class Productos {
$segmentos = json_decode(trim(file_get_contents($filename)));
return $view->render($response, 'admin.producto', compact('producto', 'segmentos'));
}
public function do_edit(Request $request, Response $response, ModelFactory $factory, $producto): Response {
public function do_edit(Request $request, Response $response, Container $container, ModelFactory $factory, $producto): Response {
$post = $request->getParsedBody();
/*$filename = implode(DIRECTORY_SEPARATOR, [
$container->get('folders.data'),
@ -101,6 +101,13 @@ class Productos {
$post['tamaño_max'],
'm²'
]);
$f = Carbon::today();
$post['publicacion'] = $producto->publicacion ?? implode(' ', [
$f->day,
'de',
ucfirst($f->locale('es')->isoFormat('MMMM')) . ',',
$f->year
]);
$producto->map((object) $post);
/*$status1 = false;
@ -145,7 +152,7 @@ class Productos {
$segmentos = json_decode(trim(file_get_contents($filename)));
return $view->render($response, 'admin.productos.add', compact('segmentos'));
}
public function do_add(Request $request, Response $response, ModelFactory $factory): Response {
public function do_add(Request $request, Response $response, Container $container, ModelFactory $factory): Response {
$post = $request->getParsedBody();
/*$producto = (object) [];
@ -174,6 +181,14 @@ class Productos {
$productos = json_decode(trim(file_get_contents($filename)));
$productos []= $producto;
file_put_contents($filename, json_encode($productos, \JSON_PRETTY_PRINT | \JSON_UNESCAPED_UNICODE | \JSON_UNESCAPED_SLASHES));*/
$f = Carbon::today();
$post['publicacion'] = implode(' ', [
$f->day,
'de',
ucfirst($f->locale('es')->isoFormat('MMMM')) . ',',
$f->year
]);
$producto = $factory->create(Producto::class, (object) $post);
if (isset($post['destacado']) and $post['destacado'] == 'on') {
$producto->destacado(true);

View File

@ -16,7 +16,7 @@
<div class="fields">
<div class="field">
<label>Direcci&oacute;n</label>
<input type="text" name="direccion" value="{{$producto->direccion->calle ?? ''}}" />
<input type="text" name="calle" value="{{$producto->direccion->calle ?? ''}}" />
</div>
<div class="field">
<label>Comuna</label>

View File

@ -16,7 +16,7 @@
<div class="fields">
<div class="field">
<label>Direcci&oacute;n</label>
<input type="text" name="direccion" />
<input type="text" name="calle" />
</div>
<div class="field">
<label>Comuna</label>

View File

@ -136,7 +136,7 @@ class Producto extends Model {
return $this->imagen;
}
public function map($data): Model {
$this->id = $data->id;
$this->id = $data->id ?? null;
$this->nombre = $data->nombre;
$this->segmento = $data->segmento;
$this->direccion = new Direccion();