Forked from humbertoromanojr/gist:f11076ef33ea08b8902d
Created
February 18, 2016 11:18
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 | |
namespace App\Controller; | |
use Cart\Model\Table\Cart; | |
use Cake\Network\Exception\NotFoundException; | |
class CartController extends AppController { | |
public function index() | |
{ | |
$cart = Cart::factory(); | |
$products = $cart->all(); | |
$this->set(['cart'=>$products]); | |
} | |
public function add($id=null) | |
{ | |
$this->loadModel('Products'); | |
$product = $this->Products->find('all',[ | |
'conditions'=>[ | |
'Products.id'=>$id | |
] | |
])->first(); | |
if (empty($product)) { | |
throw new NotFoundException("Artefact not found - Artefato não encontrado"); | |
} | |
$product->qtd = 1; | |
$cart = Cart::factory(); | |
$cart->add($product->toArray()); | |
return $this->redirect(['action'=>'index']); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment