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/Cart.php
2013-02-03 09:04:49 +11:00

98 lines
2.4 KiB
PHP

<?php defined('SYSPATH') or die('No direct access allowed.');
/**
* This class provides a order cart
*
* @package OSB
* @subpackage Cart
* @category Helpers
* @author Deon George
* @copyright (c) 2010 Deon George
* @license http://dev.leenooks.net/license.html
*/
class Cart {
private $id = NULL;
public function __construct($id=NULL) {
$this->id = is_null($id) ? Session::instance()->id() : $id;
}
public static function instance($id=NULL) {
return new Cart($id);
}
/**
* Return a list of items in the cart
*/
public function contents() {
return ORM::factory('Cart')
->where('session_id','=',$this->id)
->find_all();
}
public function delete() {
foreach (ORM::factory('Cart')->where('session_id','=',$this->id)->find_all() as $co)
$co->delete();
}
public function get($mid,$item) {
return ORM::factory('Cart')
->where('session_id','=',$this->id)
->and_where('module_id','=',$mid)
->and_where('module_item','=',$item)
->find_all();
}
public function id() {
return $this->id;
}
public function total($format=FALSE) {
$total = 0;
foreach ($this->contents() as $cio)
$total += $cio->item()->t;
return $format ? Currency::display($total) : $total;
}
/**
* Print an HTML cart list
*
* @param bool $detail List a detailed cart or a summary cart
*/
public function cart_block() {
// @todo To implement.
return '';
// If the cart is empty, we'll return here.
if (! count($this->contents()))
return 'The cart is empty.';
Style::add(array(
'type'=>'file',
'data'=>'css/cart_blocklist.css',
));
$output = '<table class="cart_blocklist" border="0">';
foreach ($this->contents() as $item) {
$ppa = $item->product->get_price_array();
$pdata = Period::details($item->recurr_schedule,$item->product->price_recurr_weekday,time(),TRUE);
$output .= View::factory('cart/block_list')
->set('item',$item)
->set('price_setup',$item->quantity*$ppa[$item->recurr_schedule]['price_setup'])
->set('price_firstinvoice',$item->quantity*$ppa[$item->recurr_schedule]['price_base']*$pdata['prorata']);
}
$output .= '<tr class="submit">';
$output .= sprintf('<td colspan="3">%s&nbsp;%s</td>',
Form::button('checkout','Checkout',array('type' => 'submit')),
Form::button('empty','Empty',array('type' => 'submit')));
$output .= '</tr>';
$output .= '</table>';
return $output;
}
}
?>