Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
<?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)
{
$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