Created
March 31, 2010 15:01
-
-
Save sauloarruda/350436 to your computer and use it in GitHub Desktop.
This file contains 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 | |
$carrinhoCompras = new CarrinhoCompras(); | |
$venda = new Venda($carrinhoCompras); | |
$voucher.save(); | |
class CarrinhoCompra { | |
/** | |
* { "produto_id" => int, "quantidade" => int, "presente" => boolean } | |
*/ | |
var $produtos; | |
public function adicionar($produto_id) { | |
$this->produtos[] = array("produto_id" => $produto_id, "quantidade" => 1); | |
} | |
public function atualizar($data) { | |
foreach (...) | |
} | |
} | |
class CarrinhoController extends AppController { | |
function index() { | |
} | |
function atualizar() { | |
$this->session["carrinho"].atualizar($this->data); | |
} | |
function adicionar() { | |
$this->session["carrinho"].adicionar($this->data["produto_id"]); | |
} | |
function remover() { | |
$this->session["carrinho"].remover($this->data["produto_id"]); | |
} | |
} | |
class CompraController extends AppController { | |
function finalizar() { | |
$this->session["carrinho"].atualizar($this->data); | |
$venda = new Venda($this->session["carrinho"]); | |
$venda.save(); | |
} | |
} | |
class Venda extends AppModel { | |
var $vouchers; | |
private function Venda() {} | |
public function Venda($carrinho) { | |
foreach ($carrinho->produtos as $produto) { | |
for ($i=0; $i<$produto["quantidade"]; $i++) { | |
$this->vouchers[] = new Voucher($produto["produto_id"], $this); | |
} | |
} | |
} | |
} | |
class Voucher { | |
var $codigo; | |
var $produto; | |
var $venda; | |
private function Voucher() {} | |
public function Voucher($produto, $venda) { | |
$this->tipo = $produto->tipo; | |
$this->produto = $produto; | |
$this->venda = $venda; | |
$this->codigo = $this->gerarCodigo(); | |
} | |
} | |
abstract class Produto { | |
var $id; | |
protected functon Produto() {} | |
} | |
class Experiencia { | |
var $id; // mesmo do produto | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment