diff --git a/common/Controller/Web/Admin/Productos.php b/common/Controller/Web/Admin/Productos.php index 34b6d73..11e4c0d 100644 --- a/common/Controller/Web/Admin/Productos.php +++ b/common/Controller/Web/Admin/Productos.php @@ -285,7 +285,7 @@ class Productos { $status = $producto->addImagen($file); $output = [ - 'informacion' => $id, + 'informacion' => $producto->id, 'estado' => $status ]; $response->getBody()->write(json_encode($output)); diff --git a/resources/views/admin/producto.blade.php b/resources/views/admin/producto.blade.php index 4cdde03..274044e 100644 --- a/resources/views/admin/producto.blade.php +++ b/resources/views/admin/producto.blade.php @@ -105,11 +105,11 @@
- +
- +
@@ -202,6 +202,9 @@ }, formatInput: false, onChange: function(a, b) { + if (typeof a == 'undefined') { + a = new Date() + } $(this).find('input').val(('0' + (a.getMonth() + 1)).slice(-2) + '/' + a.getFullYear()) } }) diff --git a/src/Producto.php b/src/Producto.php index 5e9396a..4b8c257 100644 --- a/src/Producto.php +++ b/src/Producto.php @@ -77,20 +77,18 @@ class Producto extends Model { public function imagenes() { if ($this->imagenes === null) { $folder = $this->image_folder; + $this->imagenes = []; if (!file_exists($folder)) { - $this->imagenes = []; - return []; + return $this->imagenes; } - if (file_exists($folder)) { - $files = new \DirectoryIterator($folder); - foreach ($files as $file) { - if ($file->isDir()) { - continue; - } - $this->imagenes []= $file->getFilename(); + $files = new \DirectoryIterator($folder); + foreach ($files as $file) { + if ($file->isDir()) { + continue; } - sort($this->imagenes); + $this->imagenes []= $file->getFilename(); } + sort($this->imagenes); } return $this->imagenes; } @@ -112,14 +110,14 @@ class Producto extends Model { public function deleteImagen(string $file) { $filename = implode(DIRECTORY_SEPARATOR, [ $this->image_folder, - $imagen + $file ]); if (!file_exists($filename)) { return false; } $status = unlink($filename); - if (count(scandir($dir)) == 2) { + if (count(scandir($this->image_folder)) == 2) { rmdir($this->image_folder); } return $status;