FIX: Agregar o editar producto
This commit is contained in:
@ -63,7 +63,7 @@ class Productos {
|
|||||||
$segmentos = json_decode(trim(file_get_contents($filename)));
|
$segmentos = json_decode(trim(file_get_contents($filename)));
|
||||||
return $view->render($response, 'admin.producto', compact('producto', 'segmentos'));
|
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();
|
$post = $request->getParsedBody();
|
||||||
/*$filename = implode(DIRECTORY_SEPARATOR, [
|
/*$filename = implode(DIRECTORY_SEPARATOR, [
|
||||||
$container->get('folders.data'),
|
$container->get('folders.data'),
|
||||||
@ -101,6 +101,13 @@ class Productos {
|
|||||||
$post['tamaño_max'],
|
$post['tamaño_max'],
|
||||||
'm²'
|
'm²'
|
||||||
]);
|
]);
|
||||||
|
$f = Carbon::today();
|
||||||
|
$post['publicacion'] = $producto->publicacion ?? implode(' ', [
|
||||||
|
$f->day,
|
||||||
|
'de',
|
||||||
|
ucfirst($f->locale('es')->isoFormat('MMMM')) . ',',
|
||||||
|
$f->year
|
||||||
|
]);
|
||||||
$producto->map((object) $post);
|
$producto->map((object) $post);
|
||||||
|
|
||||||
/*$status1 = false;
|
/*$status1 = false;
|
||||||
@ -145,7 +152,7 @@ class Productos {
|
|||||||
$segmentos = json_decode(trim(file_get_contents($filename)));
|
$segmentos = json_decode(trim(file_get_contents($filename)));
|
||||||
return $view->render($response, 'admin.productos.add', compact('segmentos'));
|
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();
|
$post = $request->getParsedBody();
|
||||||
|
|
||||||
/*$producto = (object) [];
|
/*$producto = (object) [];
|
||||||
@ -174,6 +181,14 @@ class Productos {
|
|||||||
$productos = json_decode(trim(file_get_contents($filename)));
|
$productos = json_decode(trim(file_get_contents($filename)));
|
||||||
$productos []= $producto;
|
$productos []= $producto;
|
||||||
file_put_contents($filename, json_encode($productos, \JSON_PRETTY_PRINT | \JSON_UNESCAPED_UNICODE | \JSON_UNESCAPED_SLASHES));*/
|
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);
|
$producto = $factory->create(Producto::class, (object) $post);
|
||||||
if (isset($post['destacado']) and $post['destacado'] == 'on') {
|
if (isset($post['destacado']) and $post['destacado'] == 'on') {
|
||||||
$producto->destacado(true);
|
$producto->destacado(true);
|
||||||
|
@ -16,7 +16,7 @@
|
|||||||
<div class="fields">
|
<div class="fields">
|
||||||
<div class="field">
|
<div class="field">
|
||||||
<label>Dirección</label>
|
<label>Dirección</label>
|
||||||
<input type="text" name="direccion" value="{{$producto->direccion->calle ?? ''}}" />
|
<input type="text" name="calle" value="{{$producto->direccion->calle ?? ''}}" />
|
||||||
</div>
|
</div>
|
||||||
<div class="field">
|
<div class="field">
|
||||||
<label>Comuna</label>
|
<label>Comuna</label>
|
||||||
|
@ -16,7 +16,7 @@
|
|||||||
<div class="fields">
|
<div class="fields">
|
||||||
<div class="field">
|
<div class="field">
|
||||||
<label>Dirección</label>
|
<label>Dirección</label>
|
||||||
<input type="text" name="direccion" />
|
<input type="text" name="calle" />
|
||||||
</div>
|
</div>
|
||||||
<div class="field">
|
<div class="field">
|
||||||
<label>Comuna</label>
|
<label>Comuna</label>
|
||||||
|
@ -136,7 +136,7 @@ class Producto extends Model {
|
|||||||
return $this->imagen;
|
return $this->imagen;
|
||||||
}
|
}
|
||||||
public function map($data): Model {
|
public function map($data): Model {
|
||||||
$this->id = $data->id;
|
$this->id = $data->id ?? null;
|
||||||
$this->nombre = $data->nombre;
|
$this->nombre = $data->nombre;
|
||||||
$this->segmento = $data->segmento;
|
$this->segmento = $data->segmento;
|
||||||
$this->direccion = new Direccion();
|
$this->direccion = new Direccion();
|
||||||
|
Reference in New Issue
Block a user