- CakePHP 3.5.0 or later
You can install this plugin into your CakePHP application using composer.
The recommended way to install composer packages is:
composer require funayaki/cakephp-cartImplement EntityBuyableAwareInterface:
class Item extends Entity implements EntityBuyableAwareInterface
{
public function getPrice()
{
return $this->price;
}
public function getBuyableLimit()
{
return INF;
}
}Load CartComponent:
<?php
class AppController extends Controller
{
public function initialize()
{
parent::initialize();
$this->loadComponent('Cart.Cart');
}
}Add item to cart:
$this->Cart->add($item);Update item quantity in cart:
$this->Cart->edit($item, 5);Get item(s) in cart:
$this->Cart->get($item);
$this->Cart->get();Calculate item total price in cart:
$this->Cart->total($item);Calculate total price in cart:
$this->Cart->total();Count quantity item(s) in cart:
$this->Cart->count($item);
$this->Cart->count();Delete item from cart:
$this->Cart->delete($item);Delete all items from cart:
$this->Cart->clear();