Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save erikfig/0114f37ff321b734cf9d to your computer and use it in GitHub Desktop.
Save erikfig/0114f37ff321b734cf9d to your computer and use it in GitHub Desktop.
<?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