Completed
Push — master ( f57dd5...55db64 )
by Reginaldo
40:24
created
app/Controller/LojaController.php 3 patches
Doc Comments   +3 added lines patch added patch discarded remove patch
@@ -160,6 +160,9 @@
 block discarded – undo
160 160
       $this->paymentPagSeguro($products['products_cart'], $andress, $client, $products['total'], $valor_frete, $retorno_venda['id']);
161 161
    }
162 162
 
163
+   /**
164
+    * @param double $total
165
+    */
163 166
    public function paymentPagSeguro($products, $andress, $client, $total, $shipping, $id) {
164 167
       $pagamento = new PagamentoController('PagseguroController');   
165 168
 
Please login to merge, or discard this patch.
Indentation   +240 added lines, -240 removed lines patch added patch discarded remove patch
@@ -21,20 +21,20 @@  discard block
 block discarded – undo
21 21
 	public function loadProducts($id_categoria = null, $id_produto = null) {
22 22
 		$this->loadModel('Produto');
23 23
 
24
-      $params = array('conditions' => 
25
-         array(
26
-            'Produto.ativo' => 1,
27
-            'Produto.id_usuario' => $this->Session->read('Usuario.id')
28
-         )
29
-      );
24
+	  $params = array('conditions' => 
25
+		 array(
26
+			'Produto.ativo' => 1,
27
+			'Produto.id_usuario' => $this->Session->read('Usuario.id')
28
+		 )
29
+	  );
30 30
 
31
-      if ($id_categoria != null) {
32
-         $params['conditions']['Produto.categoria_id'] = $id_categoria;
33
-      }
31
+	  if ($id_categoria != null) {
32
+		 $params['conditions']['Produto.categoria_id'] = $id_categoria;
33
+	  }
34 34
 
35
-      if ($id_produto != null) {
36
-         $params['conditions']['Produto.id'] = $id_produto;
37
-      }
35
+	  if ($id_produto != null) {
36
+		 $params['conditions']['Produto.id'] = $id_produto;
37
+	  }
38 38
 
39 39
 		$produtos = $this->Produto->find('all', $params);
40 40
 
@@ -42,17 +42,17 @@  discard block
 block discarded – undo
42 42
 	}
43 43
 
44 44
    public function loadBanners($id_banner = null) {
45
-      $this->loadModel('Banner');
45
+	  $this->loadModel('Banner');
46 46
 
47
-      $params = array('conditions' => 
48
-         array('ativo' => 1,
49
-              'usuario_id' => $this->Session->read('Usuario.id')
50
-         )
51
-      );
47
+	  $params = array('conditions' => 
48
+		 array('ativo' => 1,
49
+			  'usuario_id' => $this->Session->read('Usuario.id')
50
+		 )
51
+	  );
52 52
 
53
-      $banners = $this->Banner->find('all', $params);
53
+	  $banners = $this->Banner->find('all', $params);
54 54
 
55
-      return $banners;
55
+	  return $banners;
56 56
    } 
57 57
 
58 58
 	public function addCart() {
@@ -62,26 +62,26 @@  discard block
 block discarded – undo
62 62
 			$this->redirect('/');
63 63
 		}
64 64
 
65
-      if (!$this->validateProduct($produto)) {
66
-         $this->Session->setFlash('Quantidade de produtos escolhidas é maior do que a disponivel!');
67
-         $this->redirect('/');
68
-      }
65
+	  if (!$this->validateProduct($produto)) {
66
+		 $this->Session->setFlash('Quantidade de produtos escolhidas é maior do que a disponivel!');
67
+		 $this->redirect('/');
68
+	  }
69 69
 
70 70
 		$cont = count($this->Session->read('Produto'));
71 71
 
72 72
 		$this->Session->write('Produto.'.$produto['id'].'.id' , $produto['id']);
73
-      $this->Session->write('Produto.'.$produto['id'].'.quantidade' , $produto['quantidade']);
74
-      $this->Session->write('Produto.'.$produto['id'].'.variacao', $produto['variacao']);
73
+	  $this->Session->write('Produto.'.$produto['id'].'.quantidade' , $produto['quantidade']);
74
+	  $this->Session->write('Produto.'.$produto['id'].'.variacao', $produto['variacao']);
75 75
 
76 76
 		$this->redirect('/cart');
77 77
 	}
78 78
 
79 79
    public function removeProductCart() {
80
-      if ( ($this->Session->read('Produto.' . $this->params['id'])) !== null ) {
81
-         $this->Session->delete( 'Produto.' . $this->params['id'] );
82
-      }
80
+	  if ( ($this->Session->read('Produto.' . $this->params['id'])) !== null ) {
81
+		 $this->Session->delete( 'Produto.' . $this->params['id'] );
82
+	  }
83 83
 
84
-      $this->redirect('/cart');
84
+	  $this->redirect('/cart');
85 85
    }
86 86
 
87 87
 	public function clearCart() {
@@ -89,334 +89,334 @@  discard block
 block discarded – undo
89 89
 	}
90 90
 
91 91
    public function loadProductsAndValuesCart() {
92
-      $this->loadModel('Produto');
93
-      $this->loadModel('Variacao');
92
+	  $this->loadModel('Produto');
93
+	  $this->loadModel('Variacao');
94 94
 
95
-      $productsSession = $this->Session->read('Produto');
95
+	  $productsSession = $this->Session->read('Produto');
96 96
 
97
-      (float) $total = 0.00;
98
-      $produtos      = array();
99
-      foreach ($productsSession as $indice => $item) {
100
-         $produto =  $this->Produto->find('all', 
101
-            array('conditions' => 
102
-               array('Produto.ativo' => 1,
103
-                    'Produto.id' => $item['id']
104
-               )
105
-            )
106
-         );
97
+	  (float) $total = 0.00;
98
+	  $produtos      = array();
99
+	  foreach ($productsSession as $indice => $item) {
100
+		 $produto =  $this->Produto->find('all', 
101
+			array('conditions' => 
102
+			   array('Produto.ativo' => 1,
103
+					'Produto.id' => $item['id']
104
+			   )
105
+			)
106
+		 );
107 107
 
108
-         $total     += $produto[0]['Produto']['preco'] * $item['quantidade'];
108
+		 $total     += $produto[0]['Produto']['preco'] * $item['quantidade'];
109 109
 
110
-         $produto[0]['Produto']['quantidade'] = $item['quantidade'];
110
+		 $produto[0]['Produto']['quantidade'] = $item['quantidade'];
111 111
 
112
-         $variacao = $this->Variacao->find('all', 
113
-            array('conditions' =>
114
-               array('Variacao.id' => $item['variacao'])
115
-            ),
116
-            array('fields' => 
117
-               array('Variacao.nome_variacao')
118
-            )
119
-         );
112
+		 $variacao = $this->Variacao->find('all', 
113
+			array('conditions' =>
114
+			   array('Variacao.id' => $item['variacao'])
115
+			),
116
+			array('fields' => 
117
+			   array('Variacao.nome_variacao')
118
+			)
119
+		 );
120 120
 
121
-         $produto[0]['Produto']['variacao'] = $variacao[0]['Variacao']['nome_variacao'];
121
+		 $produto[0]['Produto']['variacao'] = $variacao[0]['Variacao']['nome_variacao'];
122 122
 
123
-         $produtos[] = $produto[0];
124
-      }
123
+		 $produtos[] = $produto[0];
124
+	  }
125 125
 
126
-      return array('products_cart' => $produtos, 'total' => $total);
126
+	  return array('products_cart' => $produtos, 'total' => $total);
127 127
    }
128 128
 
129 129
    public function loadCategoriesProducts($id_categoria = null) {
130
-      $this->loadModel('Categoria');
130
+	  $this->loadModel('Categoria');
131 131
 
132
-      $params = array('conditions' => 
133
-         array('ativo' => 1,
134
-              'usuario_id' => $this->Session->read('Usuario.id')
135
-         )
136
-      );
132
+	  $params = array('conditions' => 
133
+		 array('ativo' => 1,
134
+			  'usuario_id' => $this->Session->read('Usuario.id')
135
+		 )
136
+	  );
137 137
 
138
-      $categorias = $this->Categoria->find('all', $params);
138
+	  $categorias = $this->Categoria->find('all', $params);
139 139
 
140
-      return $categorias;
140
+	  return $categorias;
141 141
    }
142 142
 
143 143
    public function payment() {
144
-      $andress = $this->request->data('endereco');
144
+	  $andress = $this->request->data('endereco');
145 145
      
146
-      $client  = $this->request->data('cliente');
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();
152
+	  $objVenda = new VendaController();
153 153
      
154
-      $productsSale = $this->prepareProductsSale($products['products_cart']);
154
+	  $productsSale = $this->prepareProductsSale($products['products_cart']);
155 155
      
156
-      $usuario_id = $this->Session->read('Usuario.id');
156
+	  $usuario_id = $this->Session->read('Usuario.id');
157 157
 
158
-      $retorno_venda = $objVenda->salvar_venda($productsSale, array('forma_pagamento' => 'pagseguro'), array('valor' => $valor_frete + $products['total']), $usuario_id);
158
+	  $retorno_venda = $objVenda->salvar_venda($productsSale, array('forma_pagamento' => 'pagseguro'), array('valor' => $valor_frete + $products['total']), $usuario_id);
159 159
       
160
-      $this->paymentPagSeguro($products['products_cart'], $andress, $client, $products['total'], $valor_frete, $retorno_venda['id']);
160
+	  $this->paymentPagSeguro($products['products_cart'], $andress, $client, $products['total'], $valor_frete, $retorno_venda['id']);
161 161
    }
162 162
 
163 163
    public function paymentPagSeguro($products, $andress, $client, $total, $shipping, $id) {
164
-      $pagamento = new PagamentoController('PagseguroController');   
164
+	  $pagamento = new PagamentoController('PagseguroController');   
165 165
 
166
-      $pagamento->setToken('0C063416737542A28219A50736AD363E');
166
+	  $pagamento->setToken('0C063416737542A28219A50736AD363E');
167 167
       
168
-      $pagamento->setEmail('[email protected]');
168
+	  $pagamento->setEmail('[email protected]');
169 169
 
170
-      $pagamento->setProdutos($products);
170
+	  $pagamento->setProdutos($products);
171 171
       
172
-      $pagamento->adicionarProdutosGateway();
172
+	  $pagamento->adicionarProdutosGateway();
173 173
 
174
-      $pagamento->setEndereco($andress);
174
+	  $pagamento->setEndereco($andress);
175 175
 
176
-      $pagamento->setReference('#' . $id);
176
+	  $pagamento->setReference('#' . $id);
177 177
       
178
-      $pagamento->setValorFrete($shipping);
178
+	  $pagamento->setValorFrete($shipping);
179 179
 
180
-      return $this->redirect($pagamento->finalizarPedido());
180
+	  return $this->redirect($pagamento->finalizarPedido());
181 181
    }
182 182
 
183 183
    public function prepareProductsSale($products) {
184
-      $retorno = array();
184
+	  $retorno = array();
185 185
      
186
-      foreach ($products as $i => $product) {
187
-         $retorno[$i]['id_produto'] = $product['Produto']['id'];
188
-         $retorno[$i]['quantidade'] = $product['Produto']['quantidade'];
189
-         $retorno[$i]['variacao']   = $product['Produto']['variacao'];
190
-      }
186
+	  foreach ($products as $i => $product) {
187
+		 $retorno[$i]['id_produto'] = $product['Produto']['id'];
188
+		 $retorno[$i]['quantidade'] = $product['Produto']['quantidade'];
189
+		 $retorno[$i]['variacao']   = $product['Produto']['variacao'];
190
+	  }
191 191
 
192
-      return $retorno;
192
+	  return $retorno;
193 193
    }
194 194
 
195 195
    public function searchAndressByCep($cep) {
196
-      $this->layout = 'ajax';
196
+	  $this->layout = 'ajax';
197 197
 
198
-      $curl = curl_init('http://cep.correiocontrol.com.br/'.$cep.'.js');
198
+	  $curl = curl_init('http://cep.correiocontrol.com.br/'.$cep.'.js');
199 199
 
200
-      curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
201
-      $resultado = curl_exec($curl);
200
+	  curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
201
+	  $resultado = curl_exec($curl);
202 202
 
203
-      echo $resultado;
204
-      exit();
203
+	  echo $resultado;
204
+	  exit();
205 205
    }
206 206
 
207 207
    public function calcTransportAjax() {
208
-      $this->layout = 'ajax';
208
+	  $this->layout = 'ajax';
209 209
 
210
-      $cep_destino = $this->request->data('cep_destino');
211
-      $cep_origem  = $this->request->data('cep_origem');
210
+	  $cep_destino = $this->request->data('cep_destino');
211
+	  $cep_origem  = $this->request->data('cep_origem');
212 212
 
213
-      $dataProducts = $this->loadProductsAndValuesCart();
214
-      $fretes = $this->transport($cep_destino, $cep_origem, $dataProducts['products_cart']);
213
+	  $dataProducts = $this->loadProductsAndValuesCart();
214
+	  $fretes = $this->transport($cep_destino, $cep_origem, $dataProducts['products_cart']);
215 215
 
216
-      $disponiveis = array();
217
-      $cont = 0;
218
-      foreach ($fretes as $i => $frete) {
219
-         $disponiveis[$cont]['valor']  = $frete->price;
220
-         $disponiveis[$cont]['prazo']  = $frete->estimate;
221
-         $disponiveis[$cont]['codigo'] = $frete->method;
222
-         $cont++;
223
-      }
216
+	  $disponiveis = array();
217
+	  $cont = 0;
218
+	  foreach ($fretes as $i => $frete) {
219
+		 $disponiveis[$cont]['valor']  = $frete->price;
220
+		 $disponiveis[$cont]['prazo']  = $frete->estimate;
221
+		 $disponiveis[$cont]['codigo'] = $frete->method;
222
+		 $cont++;
223
+	  }
224 224
 
225
-      $this->Session->write('Frete.valor', $disponiveis[$cont - 1]['valor']);
225
+	  $this->Session->write('Frete.valor', $disponiveis[$cont - 1]['valor']);
226 226
 
227
-      (float) $total = $disponiveis[$cont - 1]['valor'] + $dataProducts['total'];
228
-      $total = number_format($total, 2, ',', '.');
227
+	  (float) $total = $disponiveis[$cont - 1]['valor'] + $dataProducts['total'];
228
+	  $total = number_format($total, 2, ',', '.');
229 229
 
230
-      $retorno = array('frete' => $disponiveis[$cont - 1]['valor'], 'total' => $total);
230
+	  $retorno = array('frete' => $disponiveis[$cont - 1]['valor'], 'total' => $total);
231 231
 
232
-      echo json_encode($retorno);   
233
-      exit();
232
+	  echo json_encode($retorno);   
233
+	  exit();
234 234
    }
235 235
    
236 236
    public function transport($cep_destino, $cep_origem, $data) {
237
-      $products = [];
238
-      foreach ($data as $key => $item) {
239
-         $products[] = [
240
-           "weight" => (float) $item['Produto']['peso_bruto'],
241
-           "height" => (float) '',
242
-           "length" =>(float)  '',
243
-           "width" => (float) '',
244
-           "unit_price" => (float) $item['Produto']['preco'],
245
-           "quantity" => (integer) $item['Produto']['quantidade'],
246
-           "sku" => $item['Produto']['id_alias'],
247
-           "id" => $item['Produto']['id']
248
-         ];
249
-      }
250
-
251
-      $shipping = new Shipping(
252
-          (string) $cep_destino,
253
-          'BR',
254
-          'GUARULHOS',
255
-          (string) $cep_origem,
256
-          '',
257
-          '',
258
-          '',
259
-          $products
260
-      );
261
-
262
-      $response = $shipping->getPricesShipping();
263
-
264
-      return $response;
237
+	  $products = [];
238
+	  foreach ($data as $key => $item) {
239
+		 $products[] = [
240
+		   "weight" => (float) $item['Produto']['peso_bruto'],
241
+		   "height" => (float) '',
242
+		   "length" =>(float)  '',
243
+		   "width" => (float) '',
244
+		   "unit_price" => (float) $item['Produto']['preco'],
245
+		   "quantity" => (integer) $item['Produto']['quantidade'],
246
+		   "sku" => $item['Produto']['id_alias'],
247
+		   "id" => $item['Produto']['id']
248
+		 ];
249
+	  }
250
+
251
+	  $shipping = new Shipping(
252
+		  (string) $cep_destino,
253
+		  'BR',
254
+		  'GUARULHOS',
255
+		  (string) $cep_origem,
256
+		  '',
257
+		  '',
258
+		  '',
259
+		  $products
260
+	  );
261
+
262
+	  $response = $shipping->getPricesShipping();
263
+
264
+	  return $response;
265 265
    }
266 266
 
267 267
    public function saveEmailNewsletter() {
268
-      $nome  = $this->request->data('nome');
269
-      $email = $this->request->data('email');
268
+	  $nome  = $this->request->data('nome');
269
+	  $email = $this->request->data('email');
270 270
 
271
-      $objNewsletter = new NewsletterController();
271
+	  $objNewsletter = new NewsletterController();
272 272
 
273
-      if ($objNewsletter->newsletter_cadastro($nome, $email, $this->Session->read('Usuario.id')))
274
-      {
275
-         echo json_encode(true);
276
-         exit();
277
-      } 
273
+	  if ($objNewsletter->newsletter_cadastro($nome, $email, $this->Session->read('Usuario.id')))
274
+	  {
275
+		 echo json_encode(true);
276
+		 exit();
277
+	  } 
278 278
 
279
-      echo json_encode(false);
280
-      exit();
279
+	  echo json_encode(false);
280
+	  exit();
281 281
    }
282 282
 
283 283
    public function useCoupon() {
284
-      $this->layout = 'ajax';
284
+	  $this->layout = 'ajax';
285 285
 
286
-      $cupom = $this->request->data('cupom');
287
-      $valor  = $this->request->data('valor');
286
+	  $cupom = $this->request->data('cupom');
287
+	  $valor  = $this->request->data('valor');
288 288
          
289
-      $objCupom = new CupomController();
290
-      $novo_valor = $objCupom->utilizar_cupom($cupom, $valor, $this->Session->read('Usuario.id'));
289
+	  $objCupom = new CupomController();
290
+	  $novo_valor = $objCupom->utilizar_cupom($cupom, $valor, $this->Session->read('Usuario.id'));
291 291
 
292
-      if (!$novo_valor)
293
-      {
294
-         echo json_encode(false);
295
-         exit();
296
-      }
292
+	  if (!$novo_valor)
293
+	  {
294
+		 echo json_encode(false);
295
+		 exit();
296
+	  }
297 297
 
298
-      echo json_encode($novo_valor);
299
-      exit();
298
+	  echo json_encode($novo_valor);
299
+	  exit();
300 300
    }
301 301
 
302 302
    public function validateProduct($data) {
303
-      $this->loadModel('Variacao');
303
+	  $this->loadModel('Variacao');
304 304
 
305
-      $params = array('conditions' => 
306
-         array(
307
-            'Variacao.id' => $data['variacao']
308
-         )
309
-      );
305
+	  $params = array('conditions' => 
306
+		 array(
307
+			'Variacao.id' => $data['variacao']
308
+		 )
309
+	  );
310 310
 
311
-      $variacao = $this->Variacao->find('all', $params);
311
+	  $variacao = $this->Variacao->find('all', $params);
312 312
 
313
-      if ($variacao[0]['Variacao']['estoque'] <= 0 || $data['quantidade'] > $variacao[0]['Variacao']['estoque'])
314
-      {
315
-         return false;
316
-      }
313
+	  if ($variacao[0]['Variacao']['estoque'] <= 0 || $data['quantidade'] > $variacao[0]['Variacao']['estoque'])
314
+	  {
315
+		 return false;
316
+	  }
317 317
 
318
-      return true;   
318
+	  return true;   
319 319
    }
320 320
 
321 321
    public function saveClientFromEcommerce($data) {
322
-      $this->loadModel('Cliente');
322
+	  $this->loadModel('Cliente');
323 323
 
324
-      $data['senha'] = sha1($data['senha']);
324
+	  $data['senha'] = sha1($data['senha']);
325 325
 
326
-      $this->Cliente->set($data);
326
+	  $this->Cliente->set($data);
327 327
 
328
-      if (!$this->Cliente->validates())
329
-      {
330
-         return false;
331
-      }
328
+	  if (!$this->Cliente->validates())
329
+	  {
330
+		 return false;
331
+	  }
332 332
 
333
-      if (!$this->Cliente->save())
334
-      {
335
-         return false;
336
-      }
333
+	  if (!$this->Cliente->save())
334
+	  {
335
+		 return false;
336
+	  }
337 337
 
338
-      return $this->Cliente->getLastInsertId();
338
+	  return $this->Cliente->getLastInsertId();
339 339
    }
340 340
 
341 341
    public function saveAndressClientFromEcommerce($data) {
342
-      $this->loadModel('EnderecoClienteCadastro');
342
+	  $this->loadModel('EnderecoClienteCadastro');
343 343
 
344
-      $this->EnderecoClienteCadastro->set($data);
344
+	  $this->EnderecoClienteCadastro->set($data);
345 345
 
346
-      if (!$this->EnderecoClienteCadastro->validates())
347
-      {
348
-         return false;
349
-      }
346
+	  if (!$this->EnderecoClienteCadastro->validates())
347
+	  {
348
+		 return false;
349
+	  }
350 350
 
351
-      return $this->EnderecoClienteCadastro->save();
351
+	  return $this->EnderecoClienteCadastro->save();
352 352
    }
353 353
 
354 354
 	/**
355
-	* Views
356
-	*/
355
+	 * Views
356
+	 */
357 357
 	public function index() {
358
-      $this->set('banners', $this->loadBanners());
359
-      $this->set('categorias', $this->loadCategoriesProducts());
358
+	  $this->set('banners', $this->loadBanners());
359
+	  $this->set('categorias', $this->loadCategoriesProducts());
360 360
 		$this->set('produtos', $this->loadProducts());
361 361
 	}
362 362
 
363 363
    public function cart() {
364
-      $this->set('categorias', $this->loadCategoriesProducts());
365
-      $products = $this->loadProductsAndValuesCart();
364
+	  $this->set('categorias', $this->loadCategoriesProducts());
365
+	  $products = $this->loadProductsAndValuesCart();
366 366
 
367
-      $this->set('products', $products['products_cart']);
368
-      $this->set('total', $products['total']);
367
+	  $this->set('products', $products['products_cart']);
368
+	  $this->set('total', $products['total']);
369 369
    }
370 370
 
371 371
    public function checkout() {
372
-      $this->set('categorias', $this->loadCategoriesProducts());  
373
-      $products = $this->loadProductsAndValuesCart();
372
+	  $this->set('categorias', $this->loadCategoriesProducts());  
373
+	  $products = $this->loadProductsAndValuesCart();
374 374
 
375
-      $this->set('products', $products['products_cart']);
376
-      $this->set('total', $products['total']);
375
+	  $this->set('products', $products['products_cart']);
376
+	  $this->set('total', $products['total']);
377 377
    }
378 378
 
379 379
    public function category() {
380
-      $id   = $this->params['id'];
381
-      $nome = $this->params['nome'];
380
+	  $id   = $this->params['id'];
381
+	  $nome = $this->params['nome'];
382 382
 
383
-      $products = $this->loadProducts($id);
383
+	  $products = $this->loadProducts($id);
384 384
 
385
-      $this->set('categorias', $this->loadCategoriesProducts());
386
-      $this->set('produtos', $products);
387
-      $this->set('nameCategory', $nome);
385
+	  $this->set('categorias', $this->loadCategoriesProducts());
386
+	  $this->set('produtos', $products);
387
+	  $this->set('nameCategory', $nome);
388 388
    }
389 389
 
390 390
    public function product() {
391
-      $this->loadModel('Produto');
391
+	  $this->loadModel('Produto');
392 392
 
393
-      $id = $this->params['id'];
393
+	  $id = $this->params['id'];
394 394
 
395
-      $this->set('categorias', $this->loadCategoriesProducts());
395
+	  $this->set('categorias', $this->loadCategoriesProducts());
396 396
       
397
-      $produto = $this->loadProducts(null, $id)[0];
398
-
399
-      $this->loadModel('Variacao');
400
-
401
-      $query = array (
402
-         'joins' => array(
403
-                array(
404
-                    'table' => 'produtos',
405
-                    'alias' => 'Produto',
406
-                    'type' => 'LEFT',
407
-                    'conditions' => array(
408
-                        'Variacao.produto_id = Produto.id',
409
-                    ),
410
-                )
411
-            ),
412
-           'conditions' => array('Variacao.produto_id' => $id, 'Variacao.ativo' => 1),
413
-           'fields' => array('Produto.id, Variacao.*'),
414
-      );
415
-
416
-      $variacoes = $this->Variacao->find('all', $query);
417
-      $this->set('variacoes', $variacoes);
418
-
419
-      $this->set('produto', $produto);
397
+	  $produto = $this->loadProducts(null, $id)[0];
398
+
399
+	  $this->loadModel('Variacao');
400
+
401
+	  $query = array (
402
+		 'joins' => array(
403
+				array(
404
+					'table' => 'produtos',
405
+					'alias' => 'Produto',
406
+					'type' => 'LEFT',
407
+					'conditions' => array(
408
+						'Variacao.produto_id = Produto.id',
409
+					),
410
+				)
411
+			),
412
+		   'conditions' => array('Variacao.produto_id' => $id, 'Variacao.ativo' => 1),
413
+		   'fields' => array('Produto.id, Variacao.*'),
414
+	  );
415
+
416
+	  $variacoes = $this->Variacao->find('all', $query);
417
+	  $this->set('variacoes', $variacoes);
418
+
419
+	  $this->set('produto', $produto);
420 420
    }
421 421
 
422 422
 }
423 423
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +17 added lines, -17 removed lines patch added patch discarded remove patch
@@ -7,14 +7,14 @@  discard block
 block discarded – undo
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
 use FastShipping\Lib\Tracking;
12 12
 use FastShipping\Lib\Shipping;
13 13
 
14 14
 class LojaController extends AppController {
15 15
 	public $layout = 'lojaexemplo';	
16 16
 
17
-	public function beforeFilter(){
17
+	public function beforeFilter() {
18 18
 	   return true;
19 19
 	}
20 20
 
@@ -62,23 +62,23 @@  discard block
 block discarded – undo
62 62
 			$this->redirect('/');
63 63
 		}
64 64
 
65
-      if (!$this->validateProduct($produto)) {
65
+      if ( ! $this->validateProduct($produto)) {
66 66
          $this->Session->setFlash('Quantidade de produtos escolhidas é maior do que a disponivel!');
67 67
          $this->redirect('/');
68 68
       }
69 69
 
70 70
 		$cont = count($this->Session->read('Produto'));
71 71
 
72
-		$this->Session->write('Produto.'.$produto['id'].'.id' , $produto['id']);
73
-      $this->Session->write('Produto.'.$produto['id'].'.quantidade' , $produto['quantidade']);
72
+		$this->Session->write('Produto.'.$produto['id'].'.id', $produto['id']);
73
+      $this->Session->write('Produto.'.$produto['id'].'.quantidade', $produto['quantidade']);
74 74
       $this->Session->write('Produto.'.$produto['id'].'.variacao', $produto['variacao']);
75 75
 
76 76
 		$this->redirect('/cart');
77 77
 	}
78 78
 
79 79
    public function removeProductCart() {
80
-      if ( ($this->Session->read('Produto.' . $this->params['id'])) !== null ) {
81
-         $this->Session->delete( 'Produto.' . $this->params['id'] );
80
+      if (($this->Session->read('Produto.'.$this->params['id'])) !== null) {
81
+         $this->Session->delete('Produto.'.$this->params['id']);
82 82
       }
83 83
 
84 84
       $this->redirect('/cart');
@@ -97,7 +97,7 @@  discard block
 block discarded – undo
97 97
       (float) $total = 0.00;
98 98
       $produtos      = array();
99 99
       foreach ($productsSession as $indice => $item) {
100
-         $produto =  $this->Produto->find('all', 
100
+         $produto = $this->Produto->find('all', 
101 101
             array('conditions' => 
102 102
                array('Produto.ativo' => 1,
103 103
                     'Produto.id' => $item['id']
@@ -105,7 +105,7 @@  discard block
 block discarded – undo
105 105
             )
106 106
          );
107 107
 
108
-         $total     += $produto[0]['Produto']['preco'] * $item['quantidade'];
108
+         $total += $produto[0]['Produto']['preco'] * $item['quantidade'];
109 109
 
110 110
          $produto[0]['Produto']['quantidade'] = $item['quantidade'];
111 111
 
@@ -173,7 +173,7 @@  discard block
 block discarded – undo
173 173
 
174 174
       $pagamento->setEndereco($andress);
175 175
 
176
-      $pagamento->setReference('#' . $id);
176
+      $pagamento->setReference('#'.$id);
177 177
       
178 178
       $pagamento->setValorFrete($shipping);
179 179
 
@@ -239,7 +239,7 @@  discard block
 block discarded – undo
239 239
          $products[] = [
240 240
            "weight" => (float) $item['Produto']['peso_bruto'],
241 241
            "height" => (float) '',
242
-           "length" =>(float)  '',
242
+           "length" =>(float) '',
243 243
            "width" => (float) '',
244 244
            "unit_price" => (float) $item['Produto']['preco'],
245 245
            "quantity" => (integer) $item['Produto']['quantidade'],
@@ -284,12 +284,12 @@  discard block
 block discarded – undo
284 284
       $this->layout = 'ajax';
285 285
 
286 286
       $cupom = $this->request->data('cupom');
287
-      $valor  = $this->request->data('valor');
287
+      $valor = $this->request->data('valor');
288 288
          
289 289
       $objCupom = new CupomController();
290 290
       $novo_valor = $objCupom->utilizar_cupom($cupom, $valor, $this->Session->read('Usuario.id'));
291 291
 
292
-      if (!$novo_valor)
292
+      if ( ! $novo_valor)
293 293
       {
294 294
          echo json_encode(false);
295 295
          exit();
@@ -325,12 +325,12 @@  discard block
 block discarded – undo
325 325
 
326 326
       $this->Cliente->set($data);
327 327
 
328
-      if (!$this->Cliente->validates())
328
+      if ( ! $this->Cliente->validates())
329 329
       {
330 330
          return false;
331 331
       }
332 332
 
333
-      if (!$this->Cliente->save())
333
+      if ( ! $this->Cliente->save())
334 334
       {
335 335
          return false;
336 336
       }
@@ -343,7 +343,7 @@  discard block
 block discarded – undo
343 343
 
344 344
       $this->EnderecoClienteCadastro->set($data);
345 345
 
346
-      if (!$this->EnderecoClienteCadastro->validates())
346
+      if ( ! $this->EnderecoClienteCadastro->validates())
347 347
       {
348 348
          return false;
349 349
       }
@@ -398,7 +398,7 @@  discard block
 block discarded – undo
398 398
 
399 399
       $this->loadModel('Variacao');
400 400
 
401
-      $query = array (
401
+      $query = array(
402 402
          'joins' => array(
403 403
                 array(
404 404
                     'table' => 'produtos',
Please login to merge, or discard this patch.
app/Controller/PagseguroController.php 1 patch
Indentation   +196 added lines, -196 removed lines patch added patch discarded remove patch
@@ -6,216 +6,216 @@
 block discarded – undo
6 6
 class PagseguroController extends AppController implements GatewayInterface
7 7
 {
8 8
 
9
-    private $paymentRequest;
10
-    private $email;
11
-    private $token;
12
-    private $produtos = array();
13
-    private $client = array();    
14
-    private $reference;
15
-    private $valor_frete;
16
-
17
-    public function __construct()
18
-    {
19
-        $this->paymentRequest = new PagSeguroPaymentRequest();
20
-        // Set the currency
21
-        $this->paymentRequest->setCurrency("BRL");
22
-    }
9
+	private $paymentRequest;
10
+	private $email;
11
+	private $token;
12
+	private $produtos = array();
13
+	private $client = array();    
14
+	private $reference;
15
+	private $valor_frete;
16
+
17
+	public function __construct()
18
+	{
19
+		$this->paymentRequest = new PagSeguroPaymentRequest();
20
+		// Set the currency
21
+		$this->paymentRequest->setCurrency("BRL");
22
+	}
23 23
     
24
-    // $products, $andress, $client, $total, $valor_frete, $id_venda
25
-    public function finalizarPedido()
26
-    {
27
-        $this->paymentRequest->setReference($this->reference);
28
-        $this->paymentRequest->setShippingCost($this->valor_frete);
24
+	// $products, $andress, $client, $total, $valor_frete, $id_venda
25
+	public function finalizarPedido()
26
+	{
27
+		$this->paymentRequest->setReference($this->reference);
28
+		$this->paymentRequest->setShippingCost($this->valor_frete);
29 29
 
30 30
 
31
-        // Set the url used by PagSeguro to redirect user after checkout process ends
32
-        $this->paymentRequest->setRedirectUrl("http://www.lojamodelo.com.br");
31
+		// Set the url used by PagSeguro to redirect user after checkout process ends
32
+		$this->paymentRequest->setRedirectUrl("http://www.lojamodelo.com.br");
33 33
 
34
-        try {
34
+		try {
35 35
 
36
-            /*
36
+			/*
37 37
              * #### Credentials #####
38 38
              * Replace the parameters below with your credentials
39 39
              * You can also get your credentials from a config file. See an example:
40 40
              * $credentials = PagSeguroConfig::getAccountCredentials();
41 41
             //  */
42 42
 
43
-            // seller authentication
44
-            $credentials = new PagSeguroAccountCredentials($this->email, $this->token);
43
+			// seller authentication
44
+			$credentials = new PagSeguroAccountCredentials($this->email, $this->token);
45 45
 
46
-            // application authentication
47
-            //$credentials = PagSeguroConfig::getApplicationCredentials();
46
+			// application authentication
47
+			//$credentials = PagSeguroConfig::getApplicationCredentials();
48 48
 
49
-            //$credentials->setAuthorizationCode("E231B2C9BCC8474DA2E260B6C8CF60D3");
49
+			//$credentials->setAuthorizationCode("E231B2C9BCC8474DA2E260B6C8CF60D3");
50 50
 
51
-            // Register this payment request in PagSeguro to obtain the payment URL to redirect your customer.
52
-            $url = $this->paymentRequest->register($credentials);
51
+			// Register this payment request in PagSeguro to obtain the payment URL to redirect your customer.
52
+			$url = $this->paymentRequest->register($credentials);
53 53
             
54
-            return $url;
55
-
56
-        } catch (PagSeguroServiceException $e) {
57
-
58
-            die($e->getMessage());
59
-
60
-        }
61
-    }
62
-
63
-    /**
64
-    * @return void
65
-    * @param String $token
66
-    **/
67
-    public function setToken($token)
68
-    {
69
-        $this->token = $token;
70
-    }
71
-
72
-    /**
73
-    * @return String $token
74
-    **/
75
-    public function getToken()
76
-    {
77
-        return $this->token;
78
-    }
79
-
80
-    /**
81
-    * @return void
82
-    * @param String $email
83
-    **/
84
-    public function setEmail($email)
85
-    {
86
-        $this->email = $email;
87
-    }
88
-
89
-    /**
90
-    * @return String $email
91
-    **/
92
-    public function getEmail()
93
-    {
94
-        return $this->email;
95
-    }
96
-
97
-    /**
98
-    * @return void
99
-    * @param Array $produtos
100
-    **/
101
-    public function setProdutos($produtos)
102
-    {
103
-        $this->produtos = $produtos;
104
-    }
105
-
106
-    /**
107
-    * @return Array $produtos
108
-    **/
109
-    public function getProdutos()
110
-    {
111
-        return $this->produtos;
112
-    }
113
-
114
-    /**
115
-    * @param Array Produtos
116
-    * @return Array Produtos
117
-    **/
118
-    public function adicionarProdutosGateway()
119
-    {
120
-        if (empty($this->getProdutos()))
121
-        {
122
-            throw new Exception("Você precisa usar a função setar os dados do produto!", 1);            
123
-        }
124
-
125
-        foreach ($this->getProdutos() as $i => $item) {
126
-            $this->paymentRequest->addItem(
127
-                '000' . $item['Produto']['id'], 
128
-                $item['Produto']['nome'] . '    Tamanho: '. $item['Produto']['variacao'], 
129
-                $item['Produto']['quantidade'], 
130
-                number_format($item['Produto']['preco'], 2, '.', '')
131
-            );
132
-        }
133
-
134
-        return $this->getProdutos();
135
-    }
136
-
137
-    public function setEndereco($endereco)
138
-    {
139
-        $this->endereco = $endereco;
140
-    }
141
-
142
-    public function getEndereco()
143
-    {
144
-        return $this->endereco;
145
-    }
146
-
147
-    public function setEnderecoClienteGateway()
148
-    {
149
-        if (empty($this->endereco))
150
-        {
151
-            throw new Exception("Você precisa usar a função setar os dados do cliente!", 1);            
152
-        }
153
-
154
-        $sedexCode = PagSeguroShippingType::getCodeByType('PAC');
155
-        $paymentRequest->setShippingType($sedexCode);
156
-
157
-        $paymentRequest->setShippingAddress(
158
-            $this->endereco['cep'],
159
-            $this->endereco['endereco'],
160
-            $this->endereco['numero'],
161
-            $this->endereco['complemento'],
162
-            $this->endereco['bairro'],
163
-            $this->endereco['cidade'],
164
-            $this->endereco['estado'],
165
-            'BRA'
166
-        );
167
-
168
-        return $this->getEndereco();
169
-    }
170
-
171
-    public function setReference($reference)
172
-    {
173
-        $this->reference = $reference;
174
-    }
175
-
176
-    public function getReference()
177
-    {
178
-        return $this->reference;
179
-    }
180
-
181
-    public function setValorFrete($valor_frete)
182
-    {
183
-        $this->valor_frete = $valor_frete;
184
-    }
185
-
186
-    public function getValorFrete()
187
-    {
188
-        return $this->valor_frete;
189
-    }
190
-
191
-    public function setClienteGateway()
192
-    {
193
-        if (empty($this->cliente))
194
-        {
195
-            throw new Exception("Você precisa usar a função setar os dados do cliente!", 1);            
196
-        }
197
-
198
-        // Set your customer information.
199
-        $this->paymentRequest->setSender(
200
-            $this->cliente['nome'],
201
-            $this->cliente['email'],
202
-            $this->cliente['ddd'],
203
-            $this->cliente['telefone'],
204
-            'CPF',
205
-            $this->cliente['cpf']
206
-        );
207
-
208
-        return $this->getCliente();
209
-    }
210
-
211
-    public function setCliente($cliente)
212
-    {
213
-        $this->cliente = $cliente;
214
-    }
215
-
216
-    public function getCliente()
217
-    {
218
-        return $this->cliente;
219
-    }
54
+			return $url;
55
+
56
+		} catch (PagSeguroServiceException $e) {
57
+
58
+			die($e->getMessage());
59
+
60
+		}
61
+	}
62
+
63
+	/**
64
+	 * @return void
65
+	 * @param String $token
66
+	 **/
67
+	public function setToken($token)
68
+	{
69
+		$this->token = $token;
70
+	}
71
+
72
+	/**
73
+	 * @return String $token
74
+	 **/
75
+	public function getToken()
76
+	{
77
+		return $this->token;
78
+	}
79
+
80
+	/**
81
+	 * @return void
82
+	 * @param String $email
83
+	 **/
84
+	public function setEmail($email)
85
+	{
86
+		$this->email = $email;
87
+	}
88
+
89
+	/**
90
+	 * @return String $email
91
+	 **/
92
+	public function getEmail()
93
+	{
94
+		return $this->email;
95
+	}
96
+
97
+	/**
98
+	 * @return void
99
+	 * @param Array $produtos
100
+	 **/
101
+	public function setProdutos($produtos)
102
+	{
103
+		$this->produtos = $produtos;
104
+	}
105
+
106
+	/**
107
+	 * @return Array $produtos
108
+	 **/
109
+	public function getProdutos()
110
+	{
111
+		return $this->produtos;
112
+	}
113
+
114
+	/**
115
+	 * @param Array Produtos
116
+	 * @return Array Produtos
117
+	 **/
118
+	public function adicionarProdutosGateway()
119
+	{
120
+		if (empty($this->getProdutos()))
121
+		{
122
+			throw new Exception("Você precisa usar a função setar os dados do produto!", 1);            
123
+		}
124
+
125
+		foreach ($this->getProdutos() as $i => $item) {
126
+			$this->paymentRequest->addItem(
127
+				'000' . $item['Produto']['id'], 
128
+				$item['Produto']['nome'] . '    Tamanho: '. $item['Produto']['variacao'], 
129
+				$item['Produto']['quantidade'], 
130
+				number_format($item['Produto']['preco'], 2, '.', '')
131
+			);
132
+		}
133
+
134
+		return $this->getProdutos();
135
+	}
136
+
137
+	public function setEndereco($endereco)
138
+	{
139
+		$this->endereco = $endereco;
140
+	}
141
+
142
+	public function getEndereco()
143
+	{
144
+		return $this->endereco;
145
+	}
146
+
147
+	public function setEnderecoClienteGateway()
148
+	{
149
+		if (empty($this->endereco))
150
+		{
151
+			throw new Exception("Você precisa usar a função setar os dados do cliente!", 1);            
152
+		}
153
+
154
+		$sedexCode = PagSeguroShippingType::getCodeByType('PAC');
155
+		$paymentRequest->setShippingType($sedexCode);
156
+
157
+		$paymentRequest->setShippingAddress(
158
+			$this->endereco['cep'],
159
+			$this->endereco['endereco'],
160
+			$this->endereco['numero'],
161
+			$this->endereco['complemento'],
162
+			$this->endereco['bairro'],
163
+			$this->endereco['cidade'],
164
+			$this->endereco['estado'],
165
+			'BRA'
166
+		);
167
+
168
+		return $this->getEndereco();
169
+	}
170
+
171
+	public function setReference($reference)
172
+	{
173
+		$this->reference = $reference;
174
+	}
175
+
176
+	public function getReference()
177
+	{
178
+		return $this->reference;
179
+	}
180
+
181
+	public function setValorFrete($valor_frete)
182
+	{
183
+		$this->valor_frete = $valor_frete;
184
+	}
185
+
186
+	public function getValorFrete()
187
+	{
188
+		return $this->valor_frete;
189
+	}
190
+
191
+	public function setClienteGateway()
192
+	{
193
+		if (empty($this->cliente))
194
+		{
195
+			throw new Exception("Você precisa usar a função setar os dados do cliente!", 1);            
196
+		}
197
+
198
+		// Set your customer information.
199
+		$this->paymentRequest->setSender(
200
+			$this->cliente['nome'],
201
+			$this->cliente['email'],
202
+			$this->cliente['ddd'],
203
+			$this->cliente['telefone'],
204
+			'CPF',
205
+			$this->cliente['cpf']
206
+		);
207
+
208
+		return $this->getCliente();
209
+	}
210
+
211
+	public function setCliente($cliente)
212
+	{
213
+		$this->cliente = $cliente;
214
+	}
215
+
216
+	public function getCliente()
217
+	{
218
+		return $this->cliente;
219
+	}
220 220
 
221 221
 }
222 222
\ No newline at end of file
Please login to merge, or discard this patch.