FIX: Agregar o editar producto
This commit is contained in:
@ -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);
|
||||
|
Reference in New Issue
Block a user