Componette

Componette

download-cloud-line composer require kollarovic/shopping-cart

Shopping Cart

Alt text

Live Demo

Live Demo

Demo – source code

Installation

composer.json

{
    "require":{
        "kollarovic/shopping-cart": "dev-master"
    }
}

config.neon

extensions:
	cart: Kollarovic\ShoppingCart\DI\Extension
	thumbnail: Kollarovic\Thumbnail\DI\Extension

presenter

namespace App\FrontendModule\Presenters;

use Kollarovic\ShoppingCart\Cart;
use Kollarovic\ShoppingCart\ICartControlFactory;
use Nette\Database\Context;


class CartPresenter extends BasePresenter
{

	/** @var Cart @inject */
	public $cart;

	/** @var ICartControlFactory @inject */
	public $cartControlFactory;

	/** @var Context @inject */
	public $database;


	public function actionAdd($id)
	{
		$product = $this->database->table('product')->get($id);

		if (!$product) $this->error();

		$this->cart->addItem($product->id, $product->price)
			->setName($product->name)
			->setImage($product->image)
			->setUnit($product->unit)
			->setVatRate($product->vat)
			->setLink('Product:default')
			->setLinkArgs($product->id);

		$this->redirect('default');
	}


	protected function createComponentCartControl()
	{
		$cartControl = $this->cartControlFactory->create();

		$cartControl->onClickContinue[] = function() {
			$this->redirect('Homepage:default');
		};

		$cartControl->onClickNext[] = function() {
			$this->redirect('Order:default');
		};
		return $cartControl;
	}

}

default.latte

{control cartControl}

Optional settings

config.neon

cart:
	columns:
		image: yes
		name: yes
		price: no
		quantity: yes
		totalWithoutVat: yes
		total: yes
		delete: yes
	price:
		currency: €
		decimals: 2
		decimalPoint: ','
		thousandsSep: ' '
		priceFormat: '{price} {currency}'
	buttons:
		next: Checkout
		continue: Continue shopping
		update: Update
	image:
		width: 80
		height: 80
	
Componette Componette felix@nette.org