@@ -39,8 +39,9 @@ discard block |
||
| 39 | 39 | |
| 40 | 40 | $retorno = $this->uploadImage($image); |
| 41 | 41 | |
| 42 | - if (!$retorno['status']) |
|
| 43 | - $this->Session->setFlash('Não foi possivel salvar a imagem tente novamente'); |
|
| 42 | + if (!$retorno['status']) { |
|
| 43 | + $this->Session->setFlash('Não foi possivel salvar a imagem tente novamente'); |
|
| 44 | + } |
|
| 44 | 45 | |
| 45 | 46 | $dados['imagem'] = $retorno['nome']; |
| 46 | 47 | $dados['id_usuario'] = $this->instancia; |
@@ -115,8 +116,9 @@ discard block |
||
| 115 | 116 | if (!empty($image['name'])) { |
| 116 | 117 | $retorno = $this->uploadImage($image); |
| 117 | 118 | |
| 118 | - if (!$retorno['status']) |
|
| 119 | - $this->Session->setFlash('Não foi possivel salvar a imagem tente novamente'); |
|
| 119 | + if (!$retorno['status']) { |
|
| 120 | + $this->Session->setFlash('Não foi possivel salvar a imagem tente novamente'); |
|
| 121 | + } |
|
| 120 | 122 | |
| 121 | 123 | $dados['imagem'] = $retorno['nome']; |
| 122 | 124 | } |
@@ -224,8 +226,9 @@ discard block |
||
| 224 | 226 | |
| 225 | 227 | $returnUpload = move_uploaded_file($image['tmp_name'], $dir . $nameImage); |
| 226 | 228 | |
| 227 | - if (!$returnUpload) |
|
| 228 | - return array('nome' => null, 'status' => false); |
|
| 229 | + if (!$returnUpload) { |
|
| 230 | + return array('nome' => null, 'status' => false); |
|
| 231 | + } |
|
| 229 | 232 | |
| 230 | 233 | return array('nome' => $nameImage, 'status' => true); |
| 231 | 234 | } |
@@ -324,8 +327,7 @@ discard block |
||
| 324 | 327 | { |
| 325 | 328 | $this->Session->setFlash("O arquivo está na fila para ser importado, iremos enviar um e-mail quando terminar."); |
| 326 | 329 | $this->redirect("/produto/listar_cadastros"); |
| 327 | - } |
|
| 328 | - else |
|
| 330 | + } else |
|
| 329 | 331 | { |
| 330 | 332 | $this->Session->setFlash("Ocorreu um erro, tente novamente."); |
| 331 | 333 | $this->redirect("/produto/listar_cadastros"); |
@@ -60,11 +60,11 @@ discard block |
||
| 60 | 60 | |
| 61 | 61 | $this->Session->setFlash('Produto salvo com sucesso!'); |
| 62 | 62 | |
| 63 | - return $this->redirect('/produto/listar_cadastros'); |
|
| 63 | + return $this->redirect('/produto/listar_cadastros'); |
|
| 64 | 64 | } else { |
| 65 | 65 | $this->Session->setFlash('Ocorreu um erro ao salva o produto!'); |
| 66 | 66 | |
| 67 | - return $this->redirect('/produto/listar_cadastros'); |
|
| 67 | + return $this->redirect('/produto/listar_cadastros'); |
|
| 68 | 68 | } |
| 69 | 69 | } |
| 70 | 70 | |
@@ -75,17 +75,17 @@ discard block |
||
| 75 | 75 | |
| 76 | 76 | $query = array ( |
| 77 | 77 | 'joins' => array( |
| 78 | - array( |
|
| 79 | - 'table' => 'produtos', |
|
| 80 | - 'alias' => 'Produto', |
|
| 81 | - 'type' => 'LEFT', |
|
| 82 | - 'conditions' => array( |
|
| 83 | - 'Variacao.produto_id = Produto.id', |
|
| 84 | - ), |
|
| 85 | - ) |
|
| 78 | + array( |
|
| 79 | + 'table' => 'produtos', |
|
| 80 | + 'alias' => 'Produto', |
|
| 81 | + 'type' => 'LEFT', |
|
| 82 | + 'conditions' => array( |
|
| 83 | + 'Variacao.produto_id = Produto.id', |
|
| 84 | + ), |
|
| 85 | + ) |
|
| 86 | 86 | ), |
| 87 | - 'conditions' => array('Variacao.produto_id' => $id, 'Variacao.ativo' => 1), |
|
| 88 | - 'fields' => array('Produto.id, Variacao.*'), |
|
| 87 | + 'conditions' => array('Variacao.produto_id' => $id, 'Variacao.ativo' => 1), |
|
| 88 | + 'fields' => array('Produto.id, Variacao.*'), |
|
| 89 | 89 | ); |
| 90 | 90 | |
| 91 | 91 | $variacoes = $this->set('variacoes', $this->Variacao->find('all', $query)); |
@@ -142,10 +142,10 @@ discard block |
||
| 142 | 142 | $objVariacaoController->s_adicionar_variacao($variacoes, $id, $this->instancia); |
| 143 | 143 | |
| 144 | 144 | $this->Session->setFlash('Produto editado com sucesso!','default','good'); |
| 145 | - return $this->redirect('/produto/listar_cadastros'); |
|
| 145 | + return $this->redirect('/produto/listar_cadastros'); |
|
| 146 | 146 | } else { |
| 147 | 147 | $this->Session->setFlash('Ocorreu um erro ao editar o produto!','default','good'); |
| 148 | - return $this->redirect('/produto/listar_cadastros'); |
|
| 148 | + return $this->redirect('/produto/listar_cadastros'); |
|
| 149 | 149 | } |
| 150 | 150 | } |
| 151 | 151 | |
@@ -259,107 +259,107 @@ discard block |
||
| 259 | 259 | include(APP . 'Vendor/PHPExcel/PHPExcel.php'); |
| 260 | 260 | include(APP . 'Vendor/PHPExcel/PHPExcel/IOFactory.php'); |
| 261 | 261 | |
| 262 | - $objPHPExcel = new PHPExcel(); |
|
| 263 | - // Definimos o estilo da fonte |
|
| 264 | - $objPHPExcel->getActiveSheet()->getStyle('A1')->getFont()->setBold(true); |
|
| 262 | + $objPHPExcel = new PHPExcel(); |
|
| 263 | + // Definimos o estilo da fonte |
|
| 264 | + $objPHPExcel->getActiveSheet()->getStyle('A1')->getFont()->setBold(true); |
|
| 265 | 265 | |
| 266 | - $objPHPExcel->getActiveSheet()->getRowDimension('1')->setRowHeight(40); |
|
| 266 | + $objPHPExcel->getActiveSheet()->getRowDimension('1')->setRowHeight(40); |
|
| 267 | 267 | |
| 268 | - // Criamos as colunas |
|
| 269 | - $objPHPExcel->setActiveSheetIndex(0) |
|
| 270 | - ->setCellValue('A1', "Nome do Produto") |
|
| 271 | - ->setCellValue('B1', "Preço ") |
|
| 272 | - ->setCellValue("C1", "Peso Bruto") |
|
| 273 | - ->setCellValue("D1", "Peso Liquido") |
|
| 274 | - ->setCellValue("E1", "Estoque") |
|
| 275 | - ->setCellValue("F1", "Descrição"); |
|
| 268 | + // Criamos as colunas |
|
| 269 | + $objPHPExcel->setActiveSheetIndex(0) |
|
| 270 | + ->setCellValue('A1', "Nome do Produto") |
|
| 271 | + ->setCellValue('B1', "Preço ") |
|
| 272 | + ->setCellValue("C1", "Peso Bruto") |
|
| 273 | + ->setCellValue("D1", "Peso Liquido") |
|
| 274 | + ->setCellValue("E1", "Estoque") |
|
| 275 | + ->setCellValue("F1", "Descrição"); |
|
| 276 | 276 | |
| 277 | - // Podemos renomear o nome das planilha atual, lembrando que um único arquivo pode ter várias planilhas |
|
| 278 | - $objPHPExcel->getActiveSheet()->setTitle('Listagem de produtos'); |
|
| 277 | + // Podemos renomear o nome das planilha atual, lembrando que um único arquivo pode ter várias planilhas |
|
| 278 | + $objPHPExcel->getActiveSheet()->setTitle('Listagem de produtos'); |
|
| 279 | 279 | |
| 280 | - // Cabeçalho do arquivo para ele baixar |
|
| 281 | - header('Content-Type: application/vnd.ms-excel'); |
|
| 282 | - header('Content-Disposition: attachment;filename="planilha_importacao_exemplo.xls"'); |
|
| 283 | - header('Cache-Control: max-age=0'); |
|
| 284 | - // Se for o IE9, isso talvez seja necessário |
|
| 285 | - header('Cache-Control: max-age=1'); |
|
| 280 | + // Cabeçalho do arquivo para ele baixar |
|
| 281 | + header('Content-Type: application/vnd.ms-excel'); |
|
| 282 | + header('Content-Disposition: attachment;filename="planilha_importacao_exemplo.xls"'); |
|
| 283 | + header('Cache-Control: max-age=0'); |
|
| 284 | + // Se for o IE9, isso talvez seja necessário |
|
| 285 | + header('Cache-Control: max-age=1'); |
|
| 286 | 286 | |
| 287 | - // Acessamos o 'Writer' para poder salvar o arquivo |
|
| 288 | - $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5'); |
|
| 287 | + // Acessamos o 'Writer' para poder salvar o arquivo |
|
| 288 | + $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5'); |
|
| 289 | 289 | |
| 290 | - // Salva diretamente no output, poderíamos mudar arqui para um nome de arquivo em um diretório ,caso não quisessemos jogar na tela |
|
| 291 | - $objWriter->save('php://output'); |
|
| 290 | + // Salva diretamente no output, poderíamos mudar arqui para um nome de arquivo em um diretório ,caso não quisessemos jogar na tela |
|
| 291 | + $objWriter->save('php://output'); |
|
| 292 | 292 | |
| 293 | - exit; |
|
| 294 | - } |
|
| 293 | + exit; |
|
| 294 | + } |
|
| 295 | 295 | |
| 296 | - public function importar_produtos_planilha() { |
|
| 297 | - if (!isset($_FILES['arquivo']['tmp_name']) && empty($_FILES['arquivo']['tmp_name'])) |
|
| 298 | - { |
|
| 296 | + public function importar_produtos_planilha() { |
|
| 297 | + if (!isset($_FILES['arquivo']['tmp_name']) && empty($_FILES['arquivo']['tmp_name'])) |
|
| 298 | + { |
|
| 299 | 299 | $this->Session->setFlash("Erro ao subir a planilha, tente novamente."); |
| 300 | 300 | $this->redirect("/produto/listar_cadastros"); |
| 301 | - } |
|
| 301 | + } |
|
| 302 | 302 | |
| 303 | - $typesPermissions = ['application/vnd.ms-excel']; |
|
| 303 | + $typesPermissions = ['application/vnd.ms-excel']; |
|
| 304 | 304 | |
| 305 | - if (!in_array($_FILES['arquivo']['type'], $typesPermissions)) |
|
| 306 | - { |
|
| 305 | + if (!in_array($_FILES['arquivo']['type'], $typesPermissions)) |
|
| 306 | + { |
|
| 307 | 307 | $this->Session->setFlash("O arquivo deve ser no formato .xls."); |
| 308 | 308 | $this->redirect("/produto/listar_cadastros"); |
| 309 | - } |
|
| 309 | + } |
|
| 310 | 310 | |
| 311 | - $caminho = APP . 'webroot/uploads/produto/planilhas/' . uniqid() . '.xls'; |
|
| 311 | + $caminho = APP . 'webroot/uploads/produto/planilhas/' . uniqid() . '.xls'; |
|
| 312 | 312 | |
| 313 | - $inputFileName = $_FILES['arquivo']['tmp_name']; |
|
| 313 | + $inputFileName = $_FILES['arquivo']['tmp_name']; |
|
| 314 | 314 | |
| 315 | - move_uploaded_file($inputFileName, $caminho); |
|
| 315 | + move_uploaded_file($inputFileName, $caminho); |
|
| 316 | 316 | |
| 317 | - $data = [ |
|
| 318 | - 'caminho' => $caminho, |
|
| 319 | - 'usuario_id' => $this->instancia, |
|
| 320 | - 'processado' => 0, |
|
| 321 | - 'ativo' => 1 |
|
| 322 | - ]; |
|
| 317 | + $data = [ |
|
| 318 | + 'caminho' => $caminho, |
|
| 319 | + 'usuario_id' => $this->instancia, |
|
| 320 | + 'processado' => 0, |
|
| 321 | + 'ativo' => 1 |
|
| 322 | + ]; |
|
| 323 | 323 | |
| 324 | - $this->loadModel('QueueProduct'); |
|
| 324 | + $this->loadModel('QueueProduct'); |
|
| 325 | 325 | |
| 326 | - if ($this->QueueProduct->save($data)) |
|
| 327 | - { |
|
| 326 | + if ($this->QueueProduct->save($data)) |
|
| 327 | + { |
|
| 328 | 328 | $this->Session->setFlash("O arquivo está na fila para ser importado, iremos enviar um e-mail quando terminar."); |
| 329 | 329 | $this->redirect("/produto/listar_cadastros"); |
| 330 | - } |
|
| 331 | - else |
|
| 332 | - { |
|
| 330 | + } |
|
| 331 | + else |
|
| 332 | + { |
|
| 333 | 333 | $this->Session->setFlash("Ocorreu um erro, tente novamente."); |
| 334 | 334 | $this->redirect("/produto/listar_cadastros"); |
| 335 | - } |
|
| 336 | - } |
|
| 335 | + } |
|
| 336 | + } |
|
| 337 | 337 | |
| 338 | - public function processar_planilhas_na_fila() { |
|
| 339 | - $this->loadModel('QueueProduct'); |
|
| 338 | + public function processar_planilhas_na_fila() { |
|
| 339 | + $this->loadModel('QueueProduct'); |
|
| 340 | 340 | |
| 341 | - $planilhas = $this->QueueProduct->loadPlanilhasNotProcesseds(); |
|
| 341 | + $planilhas = $this->QueueProduct->loadPlanilhasNotProcesseds(); |
|
| 342 | 342 | |
| 343 | - $response = []; |
|
| 344 | - foreach ($planilhas as $planilha) { |
|
| 345 | - $response[] = $this->processar_planilhas($planilha['caminho'], $planilha['usuario_id'], $planilha['id']); |
|
| 346 | - } |
|
| 343 | + $response = []; |
|
| 344 | + foreach ($planilhas as $planilha) { |
|
| 345 | + $response[] = $this->processar_planilhas($planilha['caminho'], $planilha['usuario_id'], $planilha['id']); |
|
| 346 | + } |
|
| 347 | 347 | |
| 348 | - return $response; |
|
| 349 | - } |
|
| 348 | + return $response; |
|
| 349 | + } |
|
| 350 | 350 | |
| 351 | - public function processar_planilhas($inputFileName, $usuarioId, $planilhaId) { |
|
| 351 | + public function processar_planilhas($inputFileName, $usuarioId, $planilhaId) { |
|
| 352 | 352 | include(APP . 'Vendor/PHPExcel/PHPExcel.php'); |
| 353 | 353 | include(APP . 'Vendor/PHPExcel/PHPExcel/IOFactory.php'); |
| 354 | 354 | |
| 355 | - $objPHPExcel = new PHPExcel(); |
|
| 355 | + $objPHPExcel = new PHPExcel(); |
|
| 356 | 356 | |
| 357 | 357 | try { |
| 358 | - $inputFileType = PHPExcel_IOFactory::identify($inputFileName); |
|
| 359 | - $objReader = PHPExcel_IOFactory::createReader($inputFileType); |
|
| 360 | - $objPHPExcel = $objReader->load($inputFileName); |
|
| 358 | + $inputFileType = PHPExcel_IOFactory::identify($inputFileName); |
|
| 359 | + $objReader = PHPExcel_IOFactory::createReader($inputFileType); |
|
| 360 | + $objPHPExcel = $objReader->load($inputFileName); |
|
| 361 | 361 | } catch(Exception $e) { |
| 362 | - die('Error loading file "' . pathinfo($inputFileName, PATHINFO_BASENAME) . '": ' . $e->getMessage()); |
|
| 362 | + die('Error loading file "' . pathinfo($inputFileName, PATHINFO_BASENAME) . '": ' . $e->getMessage()); |
|
| 363 | 363 | } |
| 364 | 364 | |
| 365 | 365 | $dados = []; |
@@ -413,39 +413,39 @@ discard block |
||
| 413 | 413 | |
| 414 | 414 | echo json_encode(array('sucess' => true)); |
| 415 | 415 | exit; |
| 416 | - } |
|
| 416 | + } |
|
| 417 | 417 | |
| 418 | - public function processar_lista_produtos($dados) { |
|
| 419 | - $errors = []; |
|
| 418 | + public function processar_lista_produtos($dados) { |
|
| 419 | + $errors = []; |
|
| 420 | 420 | |
| 421 | - foreach ($dados as $dado) { |
|
| 422 | - $this->loadModel('Produto'); |
|
| 421 | + foreach ($dados as $dado) { |
|
| 422 | + $this->loadModel('Produto'); |
|
| 423 | 423 | |
| 424 | - $existProduto = $this->Produto->find('all', |
|
| 425 | - array( |
|
| 426 | - 'conditions' => array( |
|
| 427 | - 'Produto.sku' => $dado['sku'], |
|
| 428 | - 'Produto.ativo' => 1 |
|
| 429 | - ) |
|
| 430 | - ) |
|
| 431 | - ); |
|
| 432 | - |
|
| 433 | - if (isset($existProduto) && !empty($existProduto)) |
|
| 434 | - { |
|
| 435 | - $this->Produto->id = $existProduto[0]['Produto']['id']; |
|
| 436 | - $this->Produto->save($dado); |
|
| 437 | - continue; |
|
| 438 | - } |
|
| 424 | + $existProduto = $this->Produto->find('all', |
|
| 425 | + array( |
|
| 426 | + 'conditions' => array( |
|
| 427 | + 'Produto.sku' => $dado['sku'], |
|
| 428 | + 'Produto.ativo' => 1 |
|
| 429 | + ) |
|
| 430 | + ) |
|
| 431 | + ); |
|
| 432 | + |
|
| 433 | + if (isset($existProduto) && !empty($existProduto)) |
|
| 434 | + { |
|
| 435 | + $this->Produto->id = $existProduto[0]['Produto']['id']; |
|
| 436 | + $this->Produto->save($dado); |
|
| 437 | + continue; |
|
| 438 | + } |
|
| 439 | 439 | |
| 440 | 440 | $this->Produto->create(); |
| 441 | 441 | |
| 442 | - if (!$this->Produto->save($dado)) |
|
| 443 | - { |
|
| 444 | - $errors[] = $dado; |
|
| 445 | - } |
|
| 446 | - } |
|
| 442 | + if (!$this->Produto->save($dado)) |
|
| 443 | + { |
|
| 444 | + $errors[] = $dado; |
|
| 445 | + } |
|
| 446 | + } |
|
| 447 | 447 | |
| 448 | - return $errors; |
|
| 449 | - } |
|
| 448 | + return $errors; |
|
| 449 | + } |
|
| 450 | 450 | |
| 451 | 451 | } |
@@ -2,7 +2,7 @@ discard block |
||
| 2 | 2 | |
| 3 | 3 | ini_set('max_execution_time', 300); |
| 4 | 4 | |
| 5 | -class ProdutoController extends AppController{ |
|
| 5 | +class ProdutoController extends AppController { |
|
| 6 | 6 | |
| 7 | 7 | public function listar_cadastros() { |
| 8 | 8 | $this->layout = 'wadmin'; |
@@ -20,7 +20,7 @@ discard block |
||
| 20 | 20 | public function listar_cadastros_ajax() { |
| 21 | 21 | $this->layout = 'ajax'; |
| 22 | 22 | |
| 23 | - $aColumns = array( 'sku', 'imagem', 'nome', 'preco', 'estoque' ); |
|
| 23 | + $aColumns = array('sku', 'imagem', 'nome', 'preco', 'estoque'); |
|
| 24 | 24 | |
| 25 | 25 | $conditions = array('conditions' => |
| 26 | 26 | array( |
@@ -31,26 +31,26 @@ discard block |
||
| 31 | 31 | |
| 32 | 32 | $allProdutos = $this->Produto->find('all', $conditions); |
| 33 | 33 | |
| 34 | - if ( isset( $_GET['iDisplayStart'] ) && $_GET['iDisplayLength'] != '-1' ) |
|
| 34 | + if (isset($_GET['iDisplayStart']) && $_GET['iDisplayLength'] != '-1') |
|
| 35 | 35 | { |
| 36 | 36 | $conditions['offset'] = $_GET['iDisplayStart']; |
| 37 | 37 | $conditions['limit'] = $_GET['iDisplayLength']; |
| 38 | 38 | } |
| 39 | 39 | |
| 40 | - if ( isset( $_GET['iSortCol_0'] ) ) |
|
| 40 | + if (isset($_GET['iSortCol_0'])) |
|
| 41 | 41 | { |
| 42 | - for ( $i=0 ; $i < intval( $_GET['iSortingCols'] ) ; $i++ ) |
|
| 42 | + for ($i = 0; $i < intval($_GET['iSortingCols']); $i++) |
|
| 43 | 43 | { |
| 44 | - if ( $_GET[ 'bSortable_' . intval($_GET['iSortCol_' . $i]) ] == "true" ) |
|
| 44 | + if ($_GET['bSortable_'.intval($_GET['iSortCol_'.$i])] == "true") |
|
| 45 | 45 | { |
| 46 | - $conditions['order'] = array('Produto.' . $aColumns[intval($_GET['iSortCol_' . $i])] => $_GET['sSortDir_'.$i]); |
|
| 46 | + $conditions['order'] = array('Produto.'.$aColumns[intval($_GET['iSortCol_'.$i])] => $_GET['sSortDir_'.$i]); |
|
| 47 | 47 | } |
| 48 | 48 | } |
| 49 | 49 | } |
| 50 | 50 | |
| 51 | - if ( isset( $_GET['sSearch'] ) && !empty( $_GET['sSearch'] ) ) |
|
| 51 | + if (isset($_GET['sSearch']) && ! empty($_GET['sSearch'])) |
|
| 52 | 52 | { |
| 53 | - $conditions['conditions']['Produto.nome LIKE '] = '%' . $_GET['sSearch'] . '%'; |
|
| 53 | + $conditions['conditions']['Produto.nome LIKE '] = '%'.$_GET['sSearch'].'%'; |
|
| 54 | 54 | } |
| 55 | 55 | |
| 56 | 56 | $produtos = $this->Produto->find('all', $conditions); |
@@ -62,19 +62,19 @@ discard block |
||
| 62 | 62 | "aaData" => array() |
| 63 | 63 | ); |
| 64 | 64 | |
| 65 | - foreach ( $produtos as $i => $produto ) |
|
| 65 | + foreach ($produtos as $i => $produto) |
|
| 66 | 66 | { |
| 67 | 67 | $row = array(); |
| 68 | 68 | |
| 69 | - for ( $i=0 ; $i < count($aColumns) ; $i++ ) |
|
| 69 | + for ($i = 0; $i < count($aColumns); $i++) |
|
| 70 | 70 | { |
| 71 | 71 | $value = $produto['Produto'][$aColumns[$i]]; |
| 72 | 72 | |
| 73 | 73 | if ($aColumns[$i] == "imagem") |
| 74 | 74 | { |
| 75 | - $value = '<img src="/uploads/produto/imagens/' . $produto['Produto'][$aColumns[$i]] . '" width="120" height="120">'; |
|
| 75 | + $value = '<img src="/uploads/produto/imagens/'.$produto['Produto'][$aColumns[$i]].'" width="120" height="120">'; |
|
| 76 | 76 | |
| 77 | - if (!isset($produto['Produto'][$aColumns[$i]]) || empty($produto['Produto'][$aColumns[$i]])) |
|
| 77 | + if ( ! isset($produto['Produto'][$aColumns[$i]]) || empty($produto['Produto'][$aColumns[$i]])) |
|
| 78 | 78 | { |
| 79 | 79 | $value = '<img src="/images/no_image.png" width="120" height="120">'; |
| 80 | 80 | } |
@@ -106,15 +106,15 @@ discard block |
||
| 106 | 106 | } |
| 107 | 107 | |
| 108 | 108 | public function s_adicionar_cadastro() { |
| 109 | - $dados = $this->request->data('dados'); |
|
| 109 | + $dados = $this->request->data('dados'); |
|
| 110 | 110 | |
| 111 | 111 | $variacoes = $this->request->data('variacao'); |
| 112 | 112 | |
| 113 | - $image = $_FILES['imagem']; |
|
| 113 | + $image = $_FILES['imagem']; |
|
| 114 | 114 | |
| 115 | 115 | $retorno = $this->uploadImage($image); |
| 116 | 116 | |
| 117 | - if (!$retorno['status']) |
|
| 117 | + if ( ! $retorno['status']) |
|
| 118 | 118 | $this->Session->setFlash('Não foi possivel salvar a imagem tente novamente'); |
| 119 | 119 | |
| 120 | 120 | $dados['imagem'] = $retorno['nome']; |
@@ -122,7 +122,7 @@ discard block |
||
| 122 | 122 | $dados['ativo'] = 1; |
| 123 | 123 | $dados['id_alias'] = $this->id_alias(); |
| 124 | 124 | |
| 125 | - if($this->Produto->save($dados)) { |
|
| 125 | + if ($this->Produto->save($dados)) { |
|
| 126 | 126 | $produto_id = $this->Produto->getLastInsertId(); |
| 127 | 127 | |
| 128 | 128 | require 'VariacaoController.php'; |
@@ -146,7 +146,7 @@ discard block |
||
| 146 | 146 | |
| 147 | 147 | $this->loadModel('Variacao'); |
| 148 | 148 | |
| 149 | - $query = array ( |
|
| 149 | + $query = array( |
|
| 150 | 150 | 'joins' => array( |
| 151 | 151 | array( |
| 152 | 152 | 'table' => 'produtos', |
@@ -189,12 +189,12 @@ discard block |
||
| 189 | 189 | |
| 190 | 190 | $variacoes = $this->request->data('variacao'); |
| 191 | 191 | |
| 192 | - $image = $_FILES['imagem']; |
|
| 192 | + $image = $_FILES['imagem']; |
|
| 193 | 193 | |
| 194 | - if (!empty($image['name'])) { |
|
| 194 | + if ( ! empty($image['name'])) { |
|
| 195 | 195 | $retorno = $this->uploadImage($image); |
| 196 | 196 | |
| 197 | - if (!$retorno['status']) |
|
| 197 | + if ( ! $retorno['status']) |
|
| 198 | 198 | $this->Session->setFlash('Não foi possivel salvar a imagem tente novamente'); |
| 199 | 199 | |
| 200 | 200 | $dados['imagem'] = $retorno['nome']; |
@@ -214,10 +214,10 @@ discard block |
||
| 214 | 214 | $objVariacaoController->desativar_variacoes($id); |
| 215 | 215 | $objVariacaoController->s_adicionar_variacao($variacoes, $id, $this->instancia); |
| 216 | 216 | |
| 217 | - $this->Session->setFlash('Produto editado com sucesso!','default','good'); |
|
| 217 | + $this->Session->setFlash('Produto editado com sucesso!', 'default', 'good'); |
|
| 218 | 218 | return $this->redirect('/produto/listar_cadastros'); |
| 219 | 219 | } else { |
| 220 | - $this->Session->setFlash('Ocorreu um erro ao editar o produto!','default','good'); |
|
| 220 | + $this->Session->setFlash('Ocorreu um erro ao editar o produto!', 'default', 'good'); |
|
| 221 | 221 | return $this->redirect('/produto/listar_cadastros'); |
| 222 | 222 | } |
| 223 | 223 | } |
@@ -259,7 +259,7 @@ discard block |
||
| 259 | 259 | ) |
| 260 | 260 | ); |
| 261 | 261 | |
| 262 | - if (!$this->validar_estoque($retorno)) { |
|
| 262 | + if ( ! $this->validar_estoque($retorno)) { |
|
| 263 | 263 | return false; |
| 264 | 264 | } |
| 265 | 265 | |
@@ -271,7 +271,7 @@ discard block |
||
| 271 | 271 | } |
| 272 | 272 | |
| 273 | 273 | public function validar_estoque($produto) { |
| 274 | - if (empty($produto) && !isset($produto)) { |
|
| 274 | + if (empty($produto) && ! isset($produto)) { |
|
| 275 | 275 | return false; |
| 276 | 276 | } |
| 277 | 277 | |
@@ -283,11 +283,11 @@ discard block |
||
| 283 | 283 | } |
| 284 | 284 | |
| 285 | 285 | public function calcular_preco_produto_venda($preco, $qnt) { |
| 286 | - if (empty($preco) || !isset($preco)) { |
|
| 286 | + if (empty($preco) || ! isset($preco)) { |
|
| 287 | 287 | return false; |
| 288 | 288 | } |
| 289 | 289 | |
| 290 | - if (!is_numeric($qnt)) { |
|
| 290 | + if ( ! is_numeric($qnt)) { |
|
| 291 | 291 | return false; |
| 292 | 292 | } |
| 293 | 293 | |
@@ -298,12 +298,12 @@ discard block |
||
| 298 | 298 | |
| 299 | 299 | public function uploadImage(&$image) { |
| 300 | 300 | $type = substr($image['name'], -4); |
| 301 | - $nameImage = uniqid() . md5($image['name']) . $type; |
|
| 302 | - $dir = APP . 'webroot/uploads/produto/imagens/'; |
|
| 301 | + $nameImage = uniqid().md5($image['name']).$type; |
|
| 302 | + $dir = APP.'webroot/uploads/produto/imagens/'; |
|
| 303 | 303 | |
| 304 | - $returnUpload = move_uploaded_file($image['tmp_name'], $dir . $nameImage); |
|
| 304 | + $returnUpload = move_uploaded_file($image['tmp_name'], $dir.$nameImage); |
|
| 305 | 305 | |
| 306 | - if (!$returnUpload) |
|
| 306 | + if ( ! $returnUpload) |
|
| 307 | 307 | return array('nome' => null, 'status' => false); |
| 308 | 308 | |
| 309 | 309 | return array('nome' => $nameImage, 'status' => true); |
@@ -329,8 +329,8 @@ discard block |
||
| 329 | 329 | } |
| 330 | 330 | |
| 331 | 331 | public function exportar_excel_exemplo() { |
| 332 | - include(APP . 'Vendor/PHPExcel/PHPExcel.php'); |
|
| 333 | - include(APP . 'Vendor/PHPExcel/PHPExcel/IOFactory.php'); |
|
| 332 | + include(APP.'Vendor/PHPExcel/PHPExcel.php'); |
|
| 333 | + include(APP.'Vendor/PHPExcel/PHPExcel/IOFactory.php'); |
|
| 334 | 334 | |
| 335 | 335 | $objPHPExcel = new PHPExcel(); |
| 336 | 336 | // Definimos o estilo da fonte |
@@ -367,7 +367,7 @@ discard block |
||
| 367 | 367 | } |
| 368 | 368 | |
| 369 | 369 | public function importar_produtos_planilha() { |
| 370 | - if (!isset($_FILES['arquivo']['tmp_name']) && empty($_FILES['arquivo']['tmp_name'])) |
|
| 370 | + if ( ! isset($_FILES['arquivo']['tmp_name']) && empty($_FILES['arquivo']['tmp_name'])) |
|
| 371 | 371 | { |
| 372 | 372 | $this->Session->setFlash("Erro ao subir a planilha, tente novamente."); |
| 373 | 373 | $this->redirect("/produto/listar_cadastros"); |
@@ -375,13 +375,13 @@ discard block |
||
| 375 | 375 | |
| 376 | 376 | $typesPermissions = ['application/vnd.ms-excel']; |
| 377 | 377 | |
| 378 | - if (!in_array($_FILES['arquivo']['type'], $typesPermissions)) |
|
| 378 | + if ( ! in_array($_FILES['arquivo']['type'], $typesPermissions)) |
|
| 379 | 379 | { |
| 380 | 380 | $this->Session->setFlash("O arquivo deve ser no formato .xls."); |
| 381 | 381 | $this->redirect("/produto/listar_cadastros"); |
| 382 | 382 | } |
| 383 | 383 | |
| 384 | - $caminho = APP . 'webroot/uploads/produto/planilhas/' . uniqid() . '.xls'; |
|
| 384 | + $caminho = APP.'webroot/uploads/produto/planilhas/'.uniqid().'.xls'; |
|
| 385 | 385 | |
| 386 | 386 | $inputFileName = $_FILES['arquivo']['tmp_name']; |
| 387 | 387 | |
@@ -422,17 +422,17 @@ discard block |
||
| 422 | 422 | } |
| 423 | 423 | |
| 424 | 424 | public function processar_planilhas($inputFileName, $usuarioId, $planilhaId) { |
| 425 | - include(APP . 'Vendor/PHPExcel/PHPExcel.php'); |
|
| 426 | - include(APP . 'Vendor/PHPExcel/PHPExcel/IOFactory.php'); |
|
| 425 | + include(APP.'Vendor/PHPExcel/PHPExcel.php'); |
|
| 426 | + include(APP.'Vendor/PHPExcel/PHPExcel/IOFactory.php'); |
|
| 427 | 427 | |
| 428 | 428 | $objPHPExcel = new PHPExcel(); |
| 429 | 429 | |
| 430 | 430 | try { |
| 431 | - $inputFileType = PHPExcel_IOFactory::identify($inputFileName); |
|
| 432 | - $objReader = PHPExcel_IOFactory::createReader($inputFileType); |
|
| 433 | - $objPHPExcel = $objReader->load($inputFileName); |
|
| 434 | - } catch(Exception $e) { |
|
| 435 | - die('Error loading file "' . pathinfo($inputFileName, PATHINFO_BASENAME) . '": ' . $e->getMessage()); |
|
| 431 | + $inputFileType = PHPExcel_IOFactory::identify($inputFileName); |
|
| 432 | + $objReader = PHPExcel_IOFactory::createReader($inputFileType); |
|
| 433 | + $objPHPExcel = $objReader->load($inputFileName); |
|
| 434 | + } catch (Exception $e) { |
|
| 435 | + die('Error loading file "'.pathinfo($inputFileName, PATHINFO_BASENAME).'": '.$e->getMessage()); |
|
| 436 | 436 | } |
| 437 | 437 | |
| 438 | 438 | $dados = []; |
@@ -479,7 +479,7 @@ discard block |
||
| 479 | 479 | |
| 480 | 480 | $errors = $this->processar_lista_produtos($dados); |
| 481 | 481 | |
| 482 | - if (isset($errors) && !empty($errors)) |
|
| 482 | + if (isset($errors) && ! empty($errors)) |
|
| 483 | 483 | { |
| 484 | 484 | $this->QueueProduct->planilhaProcessedIncomplete($planilhaId); |
| 485 | 485 | } |
@@ -505,7 +505,7 @@ discard block |
||
| 505 | 505 | ) |
| 506 | 506 | ); |
| 507 | 507 | |
| 508 | - if (isset($existProduto) && !empty($existProduto)) |
|
| 508 | + if (isset($existProduto) && ! empty($existProduto)) |
|
| 509 | 509 | { |
| 510 | 510 | $this->Produto->id = $existProduto[0]['Produto']['id']; |
| 511 | 511 | $this->Produto->save($dado); |
@@ -514,7 +514,7 @@ discard block |
||
| 514 | 514 | |
| 515 | 515 | $this->Produto->create(); |
| 516 | 516 | |
| 517 | - if (!$this->Produto->save($dado)) |
|
| 517 | + if ( ! $this->Produto->save($dado)) |
|
| 518 | 518 | { |
| 519 | 519 | $errors[] = $dado; |
| 520 | 520 | } |