2010-11-29 22:41:08 +00:00
|
|
|
<?php defined('SYSPATH') or die('No direct access allowed.');
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This class provides a order cart
|
|
|
|
*
|
2013-03-19 22:35:19 +00:00
|
|
|
* @package Cart
|
2010-11-29 22:41:08 +00:00
|
|
|
* @category Helpers
|
|
|
|
* @author Deon George
|
2013-03-19 22:35:19 +00:00
|
|
|
* @copyright (c) 2009-2013 Open Source Billing
|
|
|
|
* @license http://dev.osbill.net/license.html
|
2010-11-29 22:41:08 +00:00
|
|
|
*/
|
|
|
|
class Cart {
|
2013-01-15 06:07:54 +00:00
|
|
|
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);
|
2010-11-29 22:41:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return a list of items in the cart
|
|
|
|
*/
|
|
|
|
public function contents() {
|
2012-11-09 23:13:57 +00:00
|
|
|
return ORM::factory('Cart')
|
2013-01-15 06:07:54 +00:00
|
|
|
->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;
|
2010-11-29 22:41:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Print an HTML cart list
|
|
|
|
*
|
|
|
|
* @param bool $detail List a detailed cart or a summary cart
|
|
|
|
*/
|
|
|
|
public function cart_block() {
|
2013-01-15 06:07:54 +00:00
|
|
|
// @todo To implement.
|
|
|
|
return '';
|
2010-11-29 22:41:08 +00:00
|
|
|
// If the cart is empty, we'll return here.
|
2013-01-15 06:07:54 +00:00
|
|
|
if (! count($this->contents()))
|
2010-11-29 22:41:08 +00:00
|
|
|
return 'The cart is empty.';
|
|
|
|
|
|
|
|
Style::add(array(
|
|
|
|
'type'=>'file',
|
|
|
|
'data'=>'css/cart_blocklist.css',
|
|
|
|
));
|
|
|
|
|
|
|
|
$output = '<table class="cart_blocklist" border="0">';
|
2013-01-15 06:07:54 +00:00
|
|
|
foreach ($this->contents() as $item) {
|
2010-11-29 22:41:08 +00:00
|
|
|
$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 %s</td>',
|
|
|
|
Form::button('checkout','Checkout',array('type' => 'submit')),
|
|
|
|
Form::button('empty','Empty',array('type' => 'submit')));
|
|
|
|
$output .= '</tr>';
|
|
|
|
$output .= '</table>';
|
|
|
|
|
|
|
|
return $output;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
?>
|