Last active
July 27, 2016 17:01
-
-
Save gersonfs/107962f756df1801c18ceaa6f5c0b3cc to your computer and use it in GitHub Desktop.
Mau cheiro 1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
public function remover_produto($id, $condicional_id){ | |
$this->Condicional->CondicionalProduto->id = $id; | |
if (!$this->Condicional->CondicionalProduto->exists()) { | |
throw new NotFoundException(__('Invalid condicional')); | |
} | |
if (Parametro::v('ATUALIZAR_ESTOQUE_POR_CONDICIONAL', false)) { | |
$atualizou = $this->Condicional->CondicionalProduto->field('atualizou_estoque'); | |
$this->Condicional->id = $condicional_id; | |
if ($atualizou == 1) { | |
$PT = ClassRegistry::init('ProdutosTamanho'); | |
$PT->adicionarAoEstoque( | |
$this->Condicional->field('loja_id'), $this->Condicional->CondicionalProduto->field('produto_id'), $this->Condicional->CondicionalProduto->field('tamanho_id'), $this->Condicional->CondicionalProduto->field('tamanho1_id'), $this->Condicional->CondicionalProduto->field('quantidade')); | |
} | |
} | |
if ($this->Condicional->CondicionalProduto->delete($id)) { | |
$this->Flash->success('Produto Removido'); | |
$this->redirect($this->referer(array('action' => 'view', $condicional_id))); | |
} | |
$this->Flash->error('O produto não foi removido'); | |
$this->redirect($this->referer(array('action' => 'view', $condicional_id))); | |
} | |
public function editar_produto($id, $condicional_id){ | |
if (!empty($this->request->data)) { | |
if (Parametro::v('ATUALIZAR_ESTOQUE_POR_CONDICIONAL', false)) { | |
$this->CondicionalProduto->id = $id; | |
$atualizou = $this->CondicionalProduto->field('atualizou_estoque'); | |
if ($atualizou == 1) { | |
$qntAtual = $this->CondicionalProduto->field('quantidade'); | |
$qntNova = $this->request->data['CondicionalProduto']['quantidade']; | |
$PT = ClassRegistry::init('ProdutosTamanho'); | |
$this->Condicional->id = $condicional_id; | |
if ($qntAtual < $qntNova) { | |
$PT->removerDoEstoque( | |
$this->Condicional->field('loja_id'), $this->CondicionalProduto->field('produto_id'), $this->CondicionalProduto->field('tamanho_id'), $this->CondicionalProduto->field('tamanho1_id'), $qntNova - $qntAtual); | |
} else { | |
$PT->adicionarAoEstoque( | |
$this->Condicional->field('loja_id'), $this->CondicionalProduto->field('produto_id'), $this->CondicionalProduto->field('tamanho_id'), $this->CondicionalProduto->field('tamanho1_id'), $qntAtual - $qntNova); | |
} | |
} | |
} | |
if($this->CondicionalProduto->save($this->request->data)){ | |
$this->Flash->success('Produto salvo com sucesso!'); | |
$this->Condicional->id = $condicional_id; | |
$this->Condicional->saveField('updated', date('Y-m-d H:i:s')); | |
$this->redirect(array('action' => 'view', $condicional_id)); | |
}else{ | |
$this->Flash->error('Não foi possível salvar o produto!'); | |
} | |
}else{ | |
$this->request->data = $this->CondicionalProduto->read(null, $id); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment