@@ -9,7 +9,6 @@ |
||
| 9 | 9 | |
| 10 | 10 | require_once(ROOT . DS . 'vendor' . DS . 'autoload.php'); |
| 11 | 11 | |
| 12 | -use FastShipping\Lib\Tracking; |
|
| 13 | 12 | use FastShipping\Lib\Shipping; |
| 14 | 13 | |
| 15 | 14 | class LojaController extends AppController { |
@@ -22,20 +22,20 @@ discard block |
||
| 22 | 22 | public function loadProducts($id_categoria = null, $id_produto = null) { |
| 23 | 23 | $this->loadModel('Produto'); |
| 24 | 24 | |
| 25 | - $params = array('conditions' => |
|
| 26 | - array( |
|
| 27 | - 'Produto.ativo' => 1, |
|
| 28 | - 'Produto.id_usuario' => $this->Session->read('Usuario.id') |
|
| 29 | - ) |
|
| 30 | - ); |
|
| 25 | + $params = array('conditions' => |
|
| 26 | + array( |
|
| 27 | + 'Produto.ativo' => 1, |
|
| 28 | + 'Produto.id_usuario' => $this->Session->read('Usuario.id') |
|
| 29 | + ) |
|
| 30 | + ); |
|
| 31 | 31 | |
| 32 | - if ($id_categoria != null) { |
|
| 33 | - $params['conditions']['Produto.categoria_id'] = $id_categoria; |
|
| 34 | - } |
|
| 32 | + if ($id_categoria != null) { |
|
| 33 | + $params['conditions']['Produto.categoria_id'] = $id_categoria; |
|
| 34 | + } |
|
| 35 | 35 | |
| 36 | - if ($id_produto != null) { |
|
| 37 | - $params['conditions']['Produto.id'] = $id_produto; |
|
| 38 | - } |
|
| 36 | + if ($id_produto != null) { |
|
| 37 | + $params['conditions']['Produto.id'] = $id_produto; |
|
| 38 | + } |
|
| 39 | 39 | |
| 40 | 40 | $produtos = $this->Produto->find('all', $params); |
| 41 | 41 | |
@@ -43,17 +43,17 @@ discard block |
||
| 43 | 43 | } |
| 44 | 44 | |
| 45 | 45 | public function loadBanners($id_banner = null) { |
| 46 | - $this->loadModel('Banner'); |
|
| 46 | + $this->loadModel('Banner'); |
|
| 47 | 47 | |
| 48 | - $params = array('conditions' => |
|
| 49 | - array('ativo' => 1, |
|
| 50 | - 'usuario_id' => $this->Session->read('Usuario.id') |
|
| 51 | - ) |
|
| 52 | - ); |
|
| 48 | + $params = array('conditions' => |
|
| 49 | + array('ativo' => 1, |
|
| 50 | + 'usuario_id' => $this->Session->read('Usuario.id') |
|
| 51 | + ) |
|
| 52 | + ); |
|
| 53 | 53 | |
| 54 | - $banners = $this->Banner->find('all', $params); |
|
| 54 | + $banners = $this->Banner->find('all', $params); |
|
| 55 | 55 | |
| 56 | - return $banners; |
|
| 56 | + return $banners; |
|
| 57 | 57 | } |
| 58 | 58 | |
| 59 | 59 | public function addCart() { |
@@ -63,26 +63,26 @@ discard block |
||
| 63 | 63 | $this->redirect('/'); |
| 64 | 64 | } |
| 65 | 65 | |
| 66 | - if (!$this->validateProduct($produto)) { |
|
| 67 | - $this->Session->setFlash('Quantidade de produtos escolhidas é maior do que a disponivel!'); |
|
| 68 | - $this->redirect('/'); |
|
| 69 | - } |
|
| 66 | + if (!$this->validateProduct($produto)) { |
|
| 67 | + $this->Session->setFlash('Quantidade de produtos escolhidas é maior do que a disponivel!'); |
|
| 68 | + $this->redirect('/'); |
|
| 69 | + } |
|
| 70 | 70 | |
| 71 | 71 | $cont = count($this->Session->read('Produto')); |
| 72 | 72 | |
| 73 | 73 | $this->Session->write('Produto.'.$produto['id'].'.id' , $produto['id']); |
| 74 | - $this->Session->write('Produto.'.$produto['id'].'.quantidade' , $produto['quantidade']); |
|
| 75 | - $this->Session->write('Produto.'.$produto['id'].'.variacao', $produto['variacao']); |
|
| 74 | + $this->Session->write('Produto.'.$produto['id'].'.quantidade' , $produto['quantidade']); |
|
| 75 | + $this->Session->write('Produto.'.$produto['id'].'.variacao', $produto['variacao']); |
|
| 76 | 76 | |
| 77 | 77 | $this->redirect('/cart'); |
| 78 | 78 | } |
| 79 | 79 | |
| 80 | 80 | public function removeProductCart() { |
| 81 | - if ( ($this->Session->read('Produto.' . $this->params['id'])) !== null ) { |
|
| 82 | - $this->Session->delete( 'Produto.' . $this->params['id'] ); |
|
| 83 | - } |
|
| 81 | + if ( ($this->Session->read('Produto.' . $this->params['id'])) !== null ) { |
|
| 82 | + $this->Session->delete( 'Produto.' . $this->params['id'] ); |
|
| 83 | + } |
|
| 84 | 84 | |
| 85 | - $this->redirect('/cart'); |
|
| 85 | + $this->redirect('/cart'); |
|
| 86 | 86 | } |
| 87 | 87 | |
| 88 | 88 | public function clearCart() { |
@@ -90,310 +90,310 @@ discard block |
||
| 90 | 90 | } |
| 91 | 91 | |
| 92 | 92 | public function loadProductsAndValuesCart() { |
| 93 | - $this->loadModel('Produto'); |
|
| 94 | - $this->loadModel('Variacao'); |
|
| 93 | + $this->loadModel('Produto'); |
|
| 94 | + $this->loadModel('Variacao'); |
|
| 95 | 95 | |
| 96 | - $productsSession = $this->Session->read('Produto'); |
|
| 96 | + $productsSession = $this->Session->read('Produto'); |
|
| 97 | 97 | |
| 98 | - (float) $total = 0.00; |
|
| 99 | - $produtos = array(); |
|
| 100 | - foreach ($productsSession as $indice => $item) { |
|
| 101 | - $produto = $this->Produto->find('all', |
|
| 102 | - array('conditions' => |
|
| 103 | - array('Produto.ativo' => 1, |
|
| 104 | - 'Produto.id' => $item['id'] |
|
| 105 | - ) |
|
| 106 | - ) |
|
| 107 | - ); |
|
| 98 | + (float) $total = 0.00; |
|
| 99 | + $produtos = array(); |
|
| 100 | + foreach ($productsSession as $indice => $item) { |
|
| 101 | + $produto = $this->Produto->find('all', |
|
| 102 | + array('conditions' => |
|
| 103 | + array('Produto.ativo' => 1, |
|
| 104 | + 'Produto.id' => $item['id'] |
|
| 105 | + ) |
|
| 106 | + ) |
|
| 107 | + ); |
|
| 108 | 108 | |
| 109 | - $total += $produto[0]['Produto']['preco'] * $item['quantidade']; |
|
| 109 | + $total += $produto[0]['Produto']['preco'] * $item['quantidade']; |
|
| 110 | 110 | |
| 111 | - $produto[0]['Produto']['quantidade'] = $item['quantidade']; |
|
| 111 | + $produto[0]['Produto']['quantidade'] = $item['quantidade']; |
|
| 112 | 112 | |
| 113 | - $variacao = $this->Variacao->find('all', |
|
| 114 | - array('conditions' => |
|
| 115 | - array('Variacao.id' => $item['variacao']) |
|
| 116 | - ), |
|
| 117 | - array('fields' => |
|
| 118 | - array('Variacao.nome_variacao') |
|
| 119 | - ) |
|
| 120 | - ); |
|
| 113 | + $variacao = $this->Variacao->find('all', |
|
| 114 | + array('conditions' => |
|
| 115 | + array('Variacao.id' => $item['variacao']) |
|
| 116 | + ), |
|
| 117 | + array('fields' => |
|
| 118 | + array('Variacao.nome_variacao') |
|
| 119 | + ) |
|
| 120 | + ); |
|
| 121 | 121 | |
| 122 | - $produto[0]['Produto']['variacao'] = $variacao[0]['Variacao']['nome_variacao']; |
|
| 122 | + $produto[0]['Produto']['variacao'] = $variacao[0]['Variacao']['nome_variacao']; |
|
| 123 | 123 | |
| 124 | - $produtos[] = $produto[0]; |
|
| 125 | - } |
|
| 124 | + $produtos[] = $produto[0]; |
|
| 125 | + } |
|
| 126 | 126 | |
| 127 | - return array('products_cart' => $produtos, 'total' => $total); |
|
| 127 | + return array('products_cart' => $produtos, 'total' => $total); |
|
| 128 | 128 | } |
| 129 | 129 | |
| 130 | 130 | public function loadCategoriesProducts($id_categoria = null) { |
| 131 | - $this->loadModel('Categoria'); |
|
| 131 | + $this->loadModel('Categoria'); |
|
| 132 | 132 | |
| 133 | - $params = array('conditions' => |
|
| 134 | - array('ativo' => 1, |
|
| 135 | - 'usuario_id' => $this->Session->read('Usuario.id') |
|
| 136 | - ) |
|
| 137 | - ); |
|
| 133 | + $params = array('conditions' => |
|
| 134 | + array('ativo' => 1, |
|
| 135 | + 'usuario_id' => $this->Session->read('Usuario.id') |
|
| 136 | + ) |
|
| 137 | + ); |
|
| 138 | 138 | |
| 139 | - $categorias = $this->Categoria->find('all', $params); |
|
| 139 | + $categorias = $this->Categoria->find('all', $params); |
|
| 140 | 140 | |
| 141 | - return $categorias; |
|
| 141 | + return $categorias; |
|
| 142 | 142 | } |
| 143 | 143 | |
| 144 | 144 | public function payment() { |
| 145 | - $andress = $this->request->data('endereco'); |
|
| 146 | - $client = $this->request->data('cliente'); |
|
| 145 | + $andress = $this->request->data('endereco'); |
|
| 146 | + $client = $this->request->data('cliente'); |
|
| 147 | 147 | |
| 148 | - $products = $this->loadProductsAndValuesCart(); |
|
| 148 | + $products = $this->loadProductsAndValuesCart(); |
|
| 149 | 149 | |
| 150 | - (float) $valor_frete = number_format($this->Session->read('Frete.valor'), 2, '.', ','); |
|
| 150 | + (float) $valor_frete = number_format($this->Session->read('Frete.valor'), 2, '.', ','); |
|
| 151 | 151 | |
| 152 | - $objVenda = new VendaController(); |
|
| 153 | - $productsSale = $this->prepareProductsSale($products['products_cart']); |
|
| 154 | - $usuario_id = $this->Session->read('Usuario.id'); |
|
| 152 | + $objVenda = new VendaController(); |
|
| 153 | + $productsSale = $this->prepareProductsSale($products['products_cart']); |
|
| 154 | + $usuario_id = $this->Session->read('Usuario.id'); |
|
| 155 | 155 | |
| 156 | - $retorno_venda = $objVenda->salvar_venda($productsSale, array(), array('valor' => $valor_frete + $products['total']), $usuario_id); |
|
| 156 | + $retorno_venda = $objVenda->salvar_venda($productsSale, array(), array('valor' => $valor_frete + $products['total']), $usuario_id); |
|
| 157 | 157 | |
| 158 | - $this->paymentPagSeguro($products['products_cart'], $andress, $client, $products['total'], $valor_frete, $retorno_venda['id']); |
|
| 158 | + $this->paymentPagSeguro($products['products_cart'], $andress, $client, $products['total'], $valor_frete, $retorno_venda['id']); |
|
| 159 | 159 | } |
| 160 | 160 | |
| 161 | 161 | public function prepareProductsSale($products) { |
| 162 | - $retorno = array(); |
|
| 163 | - foreach ($products as $i => $product) { |
|
| 164 | - $retorno[$i]['id_produto'] = $product['Produto']['id']; |
|
| 165 | - $retorno[$i]['quantidade'] = $product['Produto']['quantidade']; |
|
| 166 | - $retorno[$i]['variacao'] = $product['Produto']['variacao']; |
|
| 167 | - } |
|
| 168 | - |
|
| 169 | - return $retorno; |
|
| 162 | + $retorno = array(); |
|
| 163 | + foreach ($products as $i => $product) { |
|
| 164 | + $retorno[$i]['id_produto'] = $product['Produto']['id']; |
|
| 165 | + $retorno[$i]['quantidade'] = $product['Produto']['quantidade']; |
|
| 166 | + $retorno[$i]['variacao'] = $product['Produto']['variacao']; |
|
| 167 | + } |
|
| 168 | + |
|
| 169 | + return $retorno; |
|
| 170 | 170 | } |
| 171 | 171 | |
| 172 | 172 | public function searchAndressByCep($cep) { |
| 173 | - $this->layout = 'ajax'; |
|
| 173 | + $this->layout = 'ajax'; |
|
| 174 | 174 | |
| 175 | - $curl = curl_init('http://cep.correiocontrol.com.br/'.$cep.'.js'); |
|
| 175 | + $curl = curl_init('http://cep.correiocontrol.com.br/'.$cep.'.js'); |
|
| 176 | 176 | |
| 177 | - curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); |
|
| 178 | - $resultado = curl_exec($curl); |
|
| 177 | + curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); |
|
| 178 | + $resultado = curl_exec($curl); |
|
| 179 | 179 | |
| 180 | - echo $resultado; |
|
| 181 | - exit(); |
|
| 180 | + echo $resultado; |
|
| 181 | + exit(); |
|
| 182 | 182 | } |
| 183 | 183 | |
| 184 | 184 | public function calcTransportAjax() { |
| 185 | - $this->layout = 'ajax'; |
|
| 185 | + $this->layout = 'ajax'; |
|
| 186 | 186 | |
| 187 | - $cep_destino = $this->request->data('cep_destino'); |
|
| 188 | - $cep_origem = $this->request->data('cep_origem'); |
|
| 187 | + $cep_destino = $this->request->data('cep_destino'); |
|
| 188 | + $cep_origem = $this->request->data('cep_origem'); |
|
| 189 | 189 | |
| 190 | - $dataProducts = $this->loadProductsAndValuesCart(); |
|
| 191 | - $fretes = $this->transport($cep_destino, $cep_origem, $dataProducts['products_cart']); |
|
| 190 | + $dataProducts = $this->loadProductsAndValuesCart(); |
|
| 191 | + $fretes = $this->transport($cep_destino, $cep_origem, $dataProducts['products_cart']); |
|
| 192 | 192 | |
| 193 | - $disponiveis = array(); |
|
| 194 | - $cont = 0; |
|
| 195 | - foreach ($fretes as $i => $frete) { |
|
| 196 | - $disponiveis[$cont]['valor'] = $frete->price; |
|
| 197 | - $disponiveis[$cont]['prazo'] = $frete->estimate; |
|
| 198 | - $disponiveis[$cont]['codigo'] = $frete->method; |
|
| 199 | - $cont++; |
|
| 200 | - } |
|
| 193 | + $disponiveis = array(); |
|
| 194 | + $cont = 0; |
|
| 195 | + foreach ($fretes as $i => $frete) { |
|
| 196 | + $disponiveis[$cont]['valor'] = $frete->price; |
|
| 197 | + $disponiveis[$cont]['prazo'] = $frete->estimate; |
|
| 198 | + $disponiveis[$cont]['codigo'] = $frete->method; |
|
| 199 | + $cont++; |
|
| 200 | + } |
|
| 201 | 201 | |
| 202 | - $this->Session->write('Frete.valor', $disponiveis[$cont - 1]['valor']); |
|
| 202 | + $this->Session->write('Frete.valor', $disponiveis[$cont - 1]['valor']); |
|
| 203 | 203 | |
| 204 | - (float) $total = $disponiveis[$cont - 1]['valor'] + $dataProducts['total']; |
|
| 205 | - $total = number_format($total, 2, ',', '.'); |
|
| 204 | + (float) $total = $disponiveis[$cont - 1]['valor'] + $dataProducts['total']; |
|
| 205 | + $total = number_format($total, 2, ',', '.'); |
|
| 206 | 206 | |
| 207 | - $retorno = array('frete' => $disponiveis[$cont - 1]['valor'], 'total' => $total); |
|
| 207 | + $retorno = array('frete' => $disponiveis[$cont - 1]['valor'], 'total' => $total); |
|
| 208 | 208 | |
| 209 | - echo json_encode($retorno); |
|
| 210 | - exit(); |
|
| 209 | + echo json_encode($retorno); |
|
| 210 | + exit(); |
|
| 211 | 211 | } |
| 212 | 212 | |
| 213 | 213 | public function transport($cep_destino, $cep_origem, $data) { |
| 214 | - $products = []; |
|
| 215 | - foreach ($data as $key => $item) { |
|
| 216 | - $products[] = [ |
|
| 217 | - "weight" => (float) $item['Produto']['peso_bruto'], |
|
| 218 | - "height" => (float) '', |
|
| 219 | - "length" =>(float) '', |
|
| 220 | - "width" => (float) '', |
|
| 221 | - "unit_price" => (float) $item['Produto']['preco'], |
|
| 222 | - "quantity" => (integer) $item['Produto']['quantidade'], |
|
| 223 | - "sku" => $item['Produto']['id_alias'], |
|
| 224 | - "id" => $item['Produto']['id'] |
|
| 225 | - ]; |
|
| 226 | - } |
|
| 227 | - |
|
| 228 | - $shipping = new Shipping( |
|
| 229 | - (string) $cep_destino, |
|
| 230 | - 'BR', |
|
| 231 | - 'GUARULHOS', |
|
| 232 | - (string) $cep_origem, |
|
| 233 | - '', |
|
| 234 | - '', |
|
| 235 | - '', |
|
| 236 | - $products |
|
| 237 | - ); |
|
| 238 | - |
|
| 239 | - $response = $shipping->getPricesShipping(); |
|
| 240 | - |
|
| 241 | - return $response; |
|
| 214 | + $products = []; |
|
| 215 | + foreach ($data as $key => $item) { |
|
| 216 | + $products[] = [ |
|
| 217 | + "weight" => (float) $item['Produto']['peso_bruto'], |
|
| 218 | + "height" => (float) '', |
|
| 219 | + "length" =>(float) '', |
|
| 220 | + "width" => (float) '', |
|
| 221 | + "unit_price" => (float) $item['Produto']['preco'], |
|
| 222 | + "quantity" => (integer) $item['Produto']['quantidade'], |
|
| 223 | + "sku" => $item['Produto']['id_alias'], |
|
| 224 | + "id" => $item['Produto']['id'] |
|
| 225 | + ]; |
|
| 226 | + } |
|
| 227 | + |
|
| 228 | + $shipping = new Shipping( |
|
| 229 | + (string) $cep_destino, |
|
| 230 | + 'BR', |
|
| 231 | + 'GUARULHOS', |
|
| 232 | + (string) $cep_origem, |
|
| 233 | + '', |
|
| 234 | + '', |
|
| 235 | + '', |
|
| 236 | + $products |
|
| 237 | + ); |
|
| 238 | + |
|
| 239 | + $response = $shipping->getPricesShipping(); |
|
| 240 | + |
|
| 241 | + return $response; |
|
| 242 | 242 | } |
| 243 | 243 | |
| 244 | 244 | public function saveEmailNewsletter() { |
| 245 | - $nome = $this->request->data('nome'); |
|
| 246 | - $email = $this->request->data('email'); |
|
| 245 | + $nome = $this->request->data('nome'); |
|
| 246 | + $email = $this->request->data('email'); |
|
| 247 | 247 | |
| 248 | - $objNewsletter = new NewsletterController(); |
|
| 248 | + $objNewsletter = new NewsletterController(); |
|
| 249 | 249 | |
| 250 | - if ($objNewsletter->newsletter_cadastro($nome, $email, $this->Session->read('Usuario.id'))) |
|
| 251 | - { |
|
| 252 | - echo json_encode(true); |
|
| 253 | - exit(); |
|
| 254 | - } |
|
| 250 | + if ($objNewsletter->newsletter_cadastro($nome, $email, $this->Session->read('Usuario.id'))) |
|
| 251 | + { |
|
| 252 | + echo json_encode(true); |
|
| 253 | + exit(); |
|
| 254 | + } |
|
| 255 | 255 | |
| 256 | - echo json_encode(false); |
|
| 257 | - exit(); |
|
| 256 | + echo json_encode(false); |
|
| 257 | + exit(); |
|
| 258 | 258 | } |
| 259 | 259 | |
| 260 | 260 | public function useCoupon() { |
| 261 | - $this->layout = 'ajax'; |
|
| 261 | + $this->layout = 'ajax'; |
|
| 262 | 262 | |
| 263 | - $cupom = $this->request->data('cupom'); |
|
| 264 | - $valor = $this->request->data('valor'); |
|
| 263 | + $cupom = $this->request->data('cupom'); |
|
| 264 | + $valor = $this->request->data('valor'); |
|
| 265 | 265 | |
| 266 | - $objCupom = new CupomController(); |
|
| 267 | - $novo_valor = $objCupom->utilizar_cupom($cupom, $valor, $this->Session->read('Usuario.id')); |
|
| 266 | + $objCupom = new CupomController(); |
|
| 267 | + $novo_valor = $objCupom->utilizar_cupom($cupom, $valor, $this->Session->read('Usuario.id')); |
|
| 268 | 268 | |
| 269 | - if (!$novo_valor) |
|
| 270 | - { |
|
| 271 | - echo json_encode(false); |
|
| 272 | - exit(); |
|
| 273 | - } |
|
| 269 | + if (!$novo_valor) |
|
| 270 | + { |
|
| 271 | + echo json_encode(false); |
|
| 272 | + exit(); |
|
| 273 | + } |
|
| 274 | 274 | |
| 275 | - echo json_encode($novo_valor); |
|
| 276 | - exit(); |
|
| 275 | + echo json_encode($novo_valor); |
|
| 276 | + exit(); |
|
| 277 | 277 | } |
| 278 | 278 | |
| 279 | 279 | public function validateProduct($data) { |
| 280 | - $this->loadModel('Variacao'); |
|
| 280 | + $this->loadModel('Variacao'); |
|
| 281 | 281 | |
| 282 | - $params = array('conditions' => |
|
| 283 | - array( |
|
| 284 | - 'Variacao.id' => $data['variacao'] |
|
| 285 | - ) |
|
| 286 | - ); |
|
| 282 | + $params = array('conditions' => |
|
| 283 | + array( |
|
| 284 | + 'Variacao.id' => $data['variacao'] |
|
| 285 | + ) |
|
| 286 | + ); |
|
| 287 | 287 | |
| 288 | - $variacao = $this->Variacao->find('all', $params); |
|
| 288 | + $variacao = $this->Variacao->find('all', $params); |
|
| 289 | 289 | |
| 290 | - if ($variacao[0]['Variacao']['estoque'] <= 0 || $data['quantidade'] > $variacao[0]['Variacao']['estoque']) |
|
| 291 | - { |
|
| 292 | - return false; |
|
| 293 | - } |
|
| 290 | + if ($variacao[0]['Variacao']['estoque'] <= 0 || $data['quantidade'] > $variacao[0]['Variacao']['estoque']) |
|
| 291 | + { |
|
| 292 | + return false; |
|
| 293 | + } |
|
| 294 | 294 | |
| 295 | - return true; |
|
| 295 | + return true; |
|
| 296 | 296 | } |
| 297 | 297 | |
| 298 | 298 | public function saveClientFromEcommerce($data) { |
| 299 | - $this->loadModel('Cliente'); |
|
| 299 | + $this->loadModel('Cliente'); |
|
| 300 | 300 | |
| 301 | - $data['senha'] = sha1($data['senha']); |
|
| 301 | + $data['senha'] = sha1($data['senha']); |
|
| 302 | 302 | |
| 303 | - $this->Cliente->set($data); |
|
| 303 | + $this->Cliente->set($data); |
|
| 304 | 304 | |
| 305 | - if (!$this->Cliente->validates()) |
|
| 306 | - { |
|
| 307 | - return false; |
|
| 308 | - } |
|
| 305 | + if (!$this->Cliente->validates()) |
|
| 306 | + { |
|
| 307 | + return false; |
|
| 308 | + } |
|
| 309 | 309 | |
| 310 | - if (!$this->Cliente->save()) |
|
| 311 | - { |
|
| 312 | - return false; |
|
| 313 | - } |
|
| 310 | + if (!$this->Cliente->save()) |
|
| 311 | + { |
|
| 312 | + return false; |
|
| 313 | + } |
|
| 314 | 314 | |
| 315 | - return $this->Cliente->getLastInsertId(); |
|
| 315 | + return $this->Cliente->getLastInsertId(); |
|
| 316 | 316 | } |
| 317 | 317 | |
| 318 | 318 | public function saveAndressClientFromEcommerce($data) { |
| 319 | - $this->loadModel('EnderecoClienteCadastro'); |
|
| 319 | + $this->loadModel('EnderecoClienteCadastro'); |
|
| 320 | 320 | |
| 321 | - $this->EnderecoClienteCadastro->set($data); |
|
| 321 | + $this->EnderecoClienteCadastro->set($data); |
|
| 322 | 322 | |
| 323 | - if (!$this->EnderecoClienteCadastro->validates()) |
|
| 324 | - { |
|
| 325 | - return false; |
|
| 326 | - } |
|
| 323 | + if (!$this->EnderecoClienteCadastro->validates()) |
|
| 324 | + { |
|
| 325 | + return false; |
|
| 326 | + } |
|
| 327 | 327 | |
| 328 | - return $this->EnderecoClienteCadastro->save(); |
|
| 328 | + return $this->EnderecoClienteCadastro->save(); |
|
| 329 | 329 | } |
| 330 | 330 | |
| 331 | 331 | /** |
| 332 | - * Views |
|
| 333 | - */ |
|
| 332 | + * Views |
|
| 333 | + */ |
|
| 334 | 334 | public function index() { |
| 335 | - $this->set('banners', $this->loadBanners()); |
|
| 336 | - $this->set('categorias', $this->loadCategoriesProducts()); |
|
| 335 | + $this->set('banners', $this->loadBanners()); |
|
| 336 | + $this->set('categorias', $this->loadCategoriesProducts()); |
|
| 337 | 337 | $this->set('produtos', $this->loadProducts()); |
| 338 | 338 | } |
| 339 | 339 | |
| 340 | 340 | public function cart() { |
| 341 | - $this->set('categorias', $this->loadCategoriesProducts()); |
|
| 342 | - $products = $this->loadProductsAndValuesCart(); |
|
| 341 | + $this->set('categorias', $this->loadCategoriesProducts()); |
|
| 342 | + $products = $this->loadProductsAndValuesCart(); |
|
| 343 | 343 | |
| 344 | - $this->set('products', $products['products_cart']); |
|
| 345 | - $this->set('total', $products['total']); |
|
| 344 | + $this->set('products', $products['products_cart']); |
|
| 345 | + $this->set('total', $products['total']); |
|
| 346 | 346 | } |
| 347 | 347 | |
| 348 | 348 | public function checkout() { |
| 349 | - $this->set('categorias', $this->loadCategoriesProducts()); |
|
| 350 | - $products = $this->loadProductsAndValuesCart(); |
|
| 349 | + $this->set('categorias', $this->loadCategoriesProducts()); |
|
| 350 | + $products = $this->loadProductsAndValuesCart(); |
|
| 351 | 351 | |
| 352 | - $this->set('products', $products['products_cart']); |
|
| 353 | - $this->set('total', $products['total']); |
|
| 352 | + $this->set('products', $products['products_cart']); |
|
| 353 | + $this->set('total', $products['total']); |
|
| 354 | 354 | } |
| 355 | 355 | |
| 356 | 356 | public function category() { |
| 357 | - $id = $this->params['id']; |
|
| 358 | - $nome = $this->params['nome']; |
|
| 357 | + $id = $this->params['id']; |
|
| 358 | + $nome = $this->params['nome']; |
|
| 359 | 359 | |
| 360 | - $products = $this->loadProducts($id); |
|
| 360 | + $products = $this->loadProducts($id); |
|
| 361 | 361 | |
| 362 | - $this->set('categorias', $this->loadCategoriesProducts()); |
|
| 363 | - $this->set('produtos', $products); |
|
| 364 | - $this->set('nameCategory', $nome); |
|
| 362 | + $this->set('categorias', $this->loadCategoriesProducts()); |
|
| 363 | + $this->set('produtos', $products); |
|
| 364 | + $this->set('nameCategory', $nome); |
|
| 365 | 365 | } |
| 366 | 366 | |
| 367 | 367 | public function product() { |
| 368 | - $this->loadModel('Produto'); |
|
| 368 | + $this->loadModel('Produto'); |
|
| 369 | 369 | |
| 370 | - $id = $this->params['id']; |
|
| 370 | + $id = $this->params['id']; |
|
| 371 | 371 | |
| 372 | - $this->set('categorias', $this->loadCategoriesProducts()); |
|
| 372 | + $this->set('categorias', $this->loadCategoriesProducts()); |
|
| 373 | 373 | |
| 374 | - $produto = $this->loadProducts(null, $id)[0]; |
|
| 375 | - |
|
| 376 | - $this->loadModel('Variacao'); |
|
| 377 | - |
|
| 378 | - $query = array ( |
|
| 379 | - 'joins' => array( |
|
| 380 | - array( |
|
| 381 | - 'table' => 'produtos', |
|
| 382 | - 'alias' => 'Produto', |
|
| 383 | - 'type' => 'LEFT', |
|
| 384 | - 'conditions' => array( |
|
| 385 | - 'Variacao.produto_id = Produto.id', |
|
| 386 | - ), |
|
| 387 | - ) |
|
| 388 | - ), |
|
| 389 | - 'conditions' => array('Variacao.produto_id' => $id, 'Variacao.ativo' => 1), |
|
| 390 | - 'fields' => array('Produto.id, Variacao.*'), |
|
| 391 | - ); |
|
| 392 | - |
|
| 393 | - $variacoes = $this->Variacao->find('all', $query); |
|
| 394 | - $this->set('variacoes', $variacoes); |
|
| 395 | - |
|
| 396 | - $this->set('produto', $produto); |
|
| 374 | + $produto = $this->loadProducts(null, $id)[0]; |
|
| 375 | + |
|
| 376 | + $this->loadModel('Variacao'); |
|
| 377 | + |
|
| 378 | + $query = array ( |
|
| 379 | + 'joins' => array( |
|
| 380 | + array( |
|
| 381 | + 'table' => 'produtos', |
|
| 382 | + 'alias' => 'Produto', |
|
| 383 | + 'type' => 'LEFT', |
|
| 384 | + 'conditions' => array( |
|
| 385 | + 'Variacao.produto_id = Produto.id', |
|
| 386 | + ), |
|
| 387 | + ) |
|
| 388 | + ), |
|
| 389 | + 'conditions' => array('Variacao.produto_id' => $id, 'Variacao.ativo' => 1), |
|
| 390 | + 'fields' => array('Produto.id, Variacao.*'), |
|
| 391 | + ); |
|
| 392 | + |
|
| 393 | + $variacoes = $this->Variacao->find('all', $query); |
|
| 394 | + $this->set('variacoes', $variacoes); |
|
| 395 | + |
|
| 396 | + $this->set('produto', $produto); |
|
| 397 | 397 | } |
| 398 | 398 | |
| 399 | 399 | } |
| 400 | 400 | \ No newline at end of file |
@@ -7,7 +7,7 @@ discard block |
||
| 7 | 7 | require 'NewsletterController.php'; |
| 8 | 8 | require 'VendaController.php'; |
| 9 | 9 | |
| 10 | -require_once(ROOT . DS . 'vendor' . DS . 'autoload.php'); |
|
| 10 | +require_once(ROOT.DS.'vendor'.DS.'autoload.php'); |
|
| 11 | 11 | |
| 12 | 12 | use FastShipping\Lib\Tracking; |
| 13 | 13 | use FastShipping\Lib\Shipping; |
@@ -15,7 +15,7 @@ discard block |
||
| 15 | 15 | class LojaController extends AppController { |
| 16 | 16 | public $layout = 'lojaexemplo'; |
| 17 | 17 | |
| 18 | - public function beforeFilter(){ |
|
| 18 | + public function beforeFilter() { |
|
| 19 | 19 | return true; |
| 20 | 20 | } |
| 21 | 21 | |
@@ -63,23 +63,23 @@ discard block |
||
| 63 | 63 | $this->redirect('/'); |
| 64 | 64 | } |
| 65 | 65 | |
| 66 | - if (!$this->validateProduct($produto)) { |
|
| 66 | + if ( ! $this->validateProduct($produto)) { |
|
| 67 | 67 | $this->Session->setFlash('Quantidade de produtos escolhidas é maior do que a disponivel!'); |
| 68 | 68 | $this->redirect('/'); |
| 69 | 69 | } |
| 70 | 70 | |
| 71 | 71 | $cont = count($this->Session->read('Produto')); |
| 72 | 72 | |
| 73 | - $this->Session->write('Produto.'.$produto['id'].'.id' , $produto['id']); |
|
| 74 | - $this->Session->write('Produto.'.$produto['id'].'.quantidade' , $produto['quantidade']); |
|
| 73 | + $this->Session->write('Produto.'.$produto['id'].'.id', $produto['id']); |
|
| 74 | + $this->Session->write('Produto.'.$produto['id'].'.quantidade', $produto['quantidade']); |
|
| 75 | 75 | $this->Session->write('Produto.'.$produto['id'].'.variacao', $produto['variacao']); |
| 76 | 76 | |
| 77 | 77 | $this->redirect('/cart'); |
| 78 | 78 | } |
| 79 | 79 | |
| 80 | 80 | public function removeProductCart() { |
| 81 | - if ( ($this->Session->read('Produto.' . $this->params['id'])) !== null ) { |
|
| 82 | - $this->Session->delete( 'Produto.' . $this->params['id'] ); |
|
| 81 | + if (($this->Session->read('Produto.'.$this->params['id'])) !== null) { |
|
| 82 | + $this->Session->delete('Produto.'.$this->params['id']); |
|
| 83 | 83 | } |
| 84 | 84 | |
| 85 | 85 | $this->redirect('/cart'); |
@@ -98,7 +98,7 @@ discard block |
||
| 98 | 98 | (float) $total = 0.00; |
| 99 | 99 | $produtos = array(); |
| 100 | 100 | foreach ($productsSession as $indice => $item) { |
| 101 | - $produto = $this->Produto->find('all', |
|
| 101 | + $produto = $this->Produto->find('all', |
|
| 102 | 102 | array('conditions' => |
| 103 | 103 | array('Produto.ativo' => 1, |
| 104 | 104 | 'Produto.id' => $item['id'] |
@@ -106,7 +106,7 @@ discard block |
||
| 106 | 106 | ) |
| 107 | 107 | ); |
| 108 | 108 | |
| 109 | - $total += $produto[0]['Produto']['preco'] * $item['quantidade']; |
|
| 109 | + $total += $produto[0]['Produto']['preco'] * $item['quantidade']; |
|
| 110 | 110 | |
| 111 | 111 | $produto[0]['Produto']['quantidade'] = $item['quantidade']; |
| 112 | 112 | |
@@ -216,7 +216,7 @@ discard block |
||
| 216 | 216 | $products[] = [ |
| 217 | 217 | "weight" => (float) $item['Produto']['peso_bruto'], |
| 218 | 218 | "height" => (float) '', |
| 219 | - "length" =>(float) '', |
|
| 219 | + "length" =>(float) '', |
|
| 220 | 220 | "width" => (float) '', |
| 221 | 221 | "unit_price" => (float) $item['Produto']['preco'], |
| 222 | 222 | "quantity" => (integer) $item['Produto']['quantidade'], |
@@ -261,12 +261,12 @@ discard block |
||
| 261 | 261 | $this->layout = 'ajax'; |
| 262 | 262 | |
| 263 | 263 | $cupom = $this->request->data('cupom'); |
| 264 | - $valor = $this->request->data('valor'); |
|
| 264 | + $valor = $this->request->data('valor'); |
|
| 265 | 265 | |
| 266 | 266 | $objCupom = new CupomController(); |
| 267 | 267 | $novo_valor = $objCupom->utilizar_cupom($cupom, $valor, $this->Session->read('Usuario.id')); |
| 268 | 268 | |
| 269 | - if (!$novo_valor) |
|
| 269 | + if ( ! $novo_valor) |
|
| 270 | 270 | { |
| 271 | 271 | echo json_encode(false); |
| 272 | 272 | exit(); |
@@ -302,12 +302,12 @@ discard block |
||
| 302 | 302 | |
| 303 | 303 | $this->Cliente->set($data); |
| 304 | 304 | |
| 305 | - if (!$this->Cliente->validates()) |
|
| 305 | + if ( ! $this->Cliente->validates()) |
|
| 306 | 306 | { |
| 307 | 307 | return false; |
| 308 | 308 | } |
| 309 | 309 | |
| 310 | - if (!$this->Cliente->save()) |
|
| 310 | + if ( ! $this->Cliente->save()) |
|
| 311 | 311 | { |
| 312 | 312 | return false; |
| 313 | 313 | } |
@@ -320,7 +320,7 @@ discard block |
||
| 320 | 320 | |
| 321 | 321 | $this->EnderecoClienteCadastro->set($data); |
| 322 | 322 | |
| 323 | - if (!$this->EnderecoClienteCadastro->validates()) |
|
| 323 | + if ( ! $this->EnderecoClienteCadastro->validates()) |
|
| 324 | 324 | { |
| 325 | 325 | return false; |
| 326 | 326 | } |
@@ -375,7 +375,7 @@ discard block |
||
| 375 | 375 | |
| 376 | 376 | $this->loadModel('Variacao'); |
| 377 | 377 | |
| 378 | - $query = array ( |
|
| 378 | + $query = array( |
|
| 379 | 379 | 'joins' => array( |
| 380 | 380 | array( |
| 381 | 381 | 'table' => 'produtos', |
@@ -1,12 +1,12 @@ discard block |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | -class HomeController extends AppController{ |
|
| 3 | +class HomeController extends AppController { |
|
| 4 | 4 | |
| 5 | - public function beforeFilter(){ |
|
| 5 | + public function beforeFilter() { |
|
| 6 | 6 | return true; |
| 7 | 7 | } |
| 8 | 8 | |
| 9 | - function index(){ |
|
| 9 | + function index() { |
|
| 10 | 10 | $this->layout = 'winners'; |
| 11 | 11 | } |
| 12 | 12 | |
@@ -19,10 +19,10 @@ discard block |
||
| 19 | 19 | $dados = $this->request->data('dados'); |
| 20 | 20 | |
| 21 | 21 | // Check for empty fields |
| 22 | - if(empty($dados['name']) || |
|
| 23 | - empty($dados['email']) || |
|
| 24 | - empty($dados['message']) || |
|
| 25 | - !filter_var($dados['email'], FILTER_VALIDATE_EMAIL)) { |
|
| 22 | + if (empty($dados['name']) || |
|
| 23 | + empty($dados['email']) || |
|
| 24 | + empty($dados['message']) || |
|
| 25 | + ! filter_var($dados['email'], FILTER_VALIDATE_EMAIL)) { |
|
| 26 | 26 | $this->Session->setFlash('Você deve preencher todos os dados!'); |
| 27 | 27 | return $this->redirect('/'); |
| 28 | 28 | } |
@@ -37,14 +37,14 @@ discard block |
||
| 37 | 37 | $email_body = "Mensagem site: ".$message; |
| 38 | 38 | $headers = "From: [email protected]\n"; // This is the email address the generated message will be from. We recommend using something like [email protected]. |
| 39 | 39 | $headers .= "Reply-To: $email_address"; |
| 40 | - mail($to,$email_subject,$email_body,$headers); |
|
| 40 | + mail($to, $email_subject, $email_body, $headers); |
|
| 41 | 41 | //resposta automatica ao cliente |
| 42 | 42 | $to = $email_address; |
| 43 | 43 | $email_subject = '[email protected]'; |
| 44 | 44 | $email_body = "A sua mensagem foi recebida, em breve responderemos"; |
| 45 | 45 | $headers = "From: [email protected]\n"; // This is the email address the generated message will be from. We recommend using something like [email protected]. |
| 46 | 46 | $headers .= "Reply-To: $email_address"; |
| 47 | - mail($to,$email_subject,$email_body,$headers); |
|
| 47 | + mail($to, $email_subject, $email_body, $headers); |
|
| 48 | 48 | |
| 49 | 49 | $this->Session->setFlash('Seu e-mail foi enviado com sucesso em breve responderemos!'); |
| 50 | 50 | return $this->redirect('/'); |
@@ -1,6 +1,6 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | -require(APP . 'Controller/IntegracaoPagseguroController.php'); |
|
| 3 | +require(APP.'Controller/IntegracaoPagseguroController.php'); |
|
| 4 | 4 | |
| 5 | 5 | /** |
| 6 | 6 | * IntegracaoPagseguroControllerTest |