This repository has been archived on 2024-04-08. You can view files and clone it, but cannot push or open issues or pull requests.
khosb/modules/cart/classes/Controller/Cart.php

59 lines
1.3 KiB
PHP
Raw Normal View History

2013-10-10 02:44:53 +00:00
<?php defined('SYSPATH') or die('No direct access allowed.');
/**
* This class provides a order cart
*
* @package Cart
* @category Controllers
* @author Deon George
* @copyright (c) 2009-2013 Open Source Billing
* @license http://dev.osbill.net/license.html
*/
class Controller_Cart extends Controller_TemplateDefault {
protected $auth_required = FALSE;
/**
* List the cart contents
*/
public function action_index() {
$co = Cart::instance();
// If the cart is empty, we'll return here.
if (! $co->contents()->count())
$this->template->content = _('Cart is Empty');
2013-10-10 02:44:53 +00:00
else {
$output = View::factory('cart/view')->set('o',$co);
2013-10-10 02:44:53 +00:00
$output .= Form::open('checkout/before');
$output .= View::factory('cart/payment')->set('o',$co);
2013-10-10 02:44:53 +00:00
$output .= Form::close();
Block::factory()
->body($output);
2013-10-10 02:44:53 +00:00
}
}
/**
* Add an item to the cart
*/
public function action_add() {
$co = ORM::factory('Cart');
2013-10-10 02:44:53 +00:00
$co->values(Request::current()->post());
$co->session_id = Session::instance()->id();
2013-10-10 02:44:53 +00:00
if (! $this->save($co))
throw HTTP_Exception::factory(501,_('There was a problem adding the item to the cart.'));
2013-10-10 02:44:53 +00:00
HTTP::redirect('cart/index');
2013-10-10 02:44:53 +00:00
}
public function action_empty() {
Cart::instance()->delete();
2013-10-10 02:44:53 +00:00
$this->template->content = _('Cart Emptied');
}
}
?>