2010-11-29 22:41:08 +00:00
|
|
|
<?php defined('SYSPATH') or die('No direct access allowed.');
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This class provides a order cart
|
|
|
|
*
|
|
|
|
* @package OSB
|
|
|
|
* @subpackage Cart
|
|
|
|
* @category Controllers
|
|
|
|
* @author Deon George
|
|
|
|
* @copyright (c) 2010 Deon George
|
|
|
|
* @license http://dev.leenooks.net/license.html
|
|
|
|
*/
|
|
|
|
class Controller_Cart extends Controller_TemplateDefault {
|
|
|
|
/**
|
|
|
|
* Default action when called
|
|
|
|
*/
|
|
|
|
public function action_index() {
|
|
|
|
return $this->action_list();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* List items in the cart
|
|
|
|
*/
|
|
|
|
public function action_list() {
|
|
|
|
// @todo - this should be a global config item
|
|
|
|
$mediapath = Route::get('default/media');
|
|
|
|
|
|
|
|
// If the cart is empty, we'll return here.
|
|
|
|
if (! Cart::instance()->contents()->count_all())
|
2011-05-14 07:35:33 +00:00
|
|
|
Block::add(array(
|
2010-11-29 22:41:08 +00:00
|
|
|
'title'=>_('Empty Cart'),
|
|
|
|
'body'=>_('The cart is empty')
|
|
|
|
));
|
|
|
|
|
|
|
|
else {
|
|
|
|
Style::add(array(
|
|
|
|
'type'=>'file',
|
|
|
|
'data'=>'css/cart_contents.css',
|
|
|
|
));
|
|
|
|
|
|
|
|
$output = Form::open('checkout/noready');
|
|
|
|
foreach (Cart::instance()->contents()->find_all() as $item) {
|
|
|
|
$ppa = $item->product->get_price_array();
|
|
|
|
$pdata = Period::details($item->recurr_schedule,$item->product->price_recurr_weekday,time(),TRUE);
|
|
|
|
|
|
|
|
$price_box = View::factory('cart/list_pricebox')
|
|
|
|
->set('price_recurring',Currency::display($item->quantity*$ppa[$item->recurr_schedule]['price_base']))
|
|
|
|
->set('price_firstinvoice',Currency::display($item->quantity*$ppa[$item->recurr_schedule]['price_base']*$pdata['prorata']))
|
|
|
|
->set('price_setup',Currency::display($item->quantity*$ppa[$item->recurr_schedule]['price_setup']))
|
|
|
|
->set('item',$item)
|
|
|
|
->set('mediapath',$mediapath);
|
|
|
|
|
|
|
|
$output .= View::factory('cart/list_item')
|
|
|
|
->set('price_box',$price_box)
|
|
|
|
->set('service_start',$pdata['date'])
|
|
|
|
->set('service_end',$pdata['end'])
|
|
|
|
->set('price_recurring',Currency::display($item->quantity*$ppa[$item->recurr_schedule]['price_base']))
|
|
|
|
->set('item',$item)
|
|
|
|
->set('mediapath',$mediapath);
|
|
|
|
|
|
|
|
// If we are a plugin product, we might need more information
|
2011-05-14 07:35:33 +00:00
|
|
|
// @todo If an admin, show a system message if cart_info doesnt exist.
|
|
|
|
if ($item->product->prod_plugin AND method_exists($item->product->prod_plugin_file,'product_cart') AND Kohana::find_file('views',sprintf('%s/cart_info',strtolower($item->product->prod_plugin_file)))) {
|
2010-11-29 22:41:08 +00:00
|
|
|
$output .= View::factory(sprintf('%s/cart_info',strtolower($item->product->prod_plugin_file)));
|
|
|
|
|
|
|
|
// @todo JS validation will need to verify data before submission
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$output .= '<div>'.Form::submit('submit',_('Checkout')).'</div>';
|
|
|
|
$output .= Form::close();
|
|
|
|
|
2011-05-14 07:35:33 +00:00
|
|
|
Block::add(array(
|
2010-11-29 22:41:08 +00:00
|
|
|
'title'=>_('Your Items'),
|
|
|
|
'body'=>$output,
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
|
|
|
// Suppress our right hand tab
|
|
|
|
$this->template->right = ' ';
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add an item to the cart
|
|
|
|
*/
|
|
|
|
public function action_add() {
|
2012-11-09 23:13:57 +00:00
|
|
|
$cart = ORM::factory('Cart');
|
2010-11-29 22:41:08 +00:00
|
|
|
|
|
|
|
$cart->session_id = Session::instance()->id();
|
|
|
|
|
|
|
|
if (Auth::instance()->logged_in())
|
|
|
|
$cart->account_id = Auth::instance()->get_user()->id;
|
|
|
|
|
|
|
|
if ($cart->values($_POST)->check())
|
|
|
|
$cart->save();
|
|
|
|
else
|
|
|
|
echo Kohana::debug($cart->validate()->errors());
|
|
|
|
|
|
|
|
if ($cart->saved())
|
2012-11-09 23:13:57 +00:00
|
|
|
HTTP::redirect('cart/index');
|
2010-11-29 22:41:08 +00:00
|
|
|
else
|
|
|
|
throw new Kohana_Exception(_('There was a problem adding the item to the cart.'));
|
|
|
|
}
|
|
|
|
|
|
|
|
public function action_empty() {
|
2012-11-09 23:13:57 +00:00
|
|
|
$cart = ORM::factory('Cart')
|
2010-11-29 22:41:08 +00:00
|
|
|
->where('session_id','=',session_id());
|
|
|
|
|
|
|
|
$cart->delete_all();
|
|
|
|
|
|
|
|
$this->template->content = _('Cart Emptied');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
?>
|