Cart work for payments and Paypal work to test

This commit is contained in:
Deon George
2013-01-15 17:07:54 +11:00
parent 133ae4d5c6
commit 69645c4eea
42 changed files with 968 additions and 801 deletions

View File

@@ -11,8 +11,14 @@
* @license http://dev.leenooks.net/license.html
*/
class Cart {
public static function instance() {
return new 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);
}
/**
@@ -20,7 +26,34 @@ class Cart {
*/
public function contents() {
return ORM::factory('Cart')
->where('session_id','=',Session::instance()->id());
->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;
}
/**
@@ -29,8 +62,10 @@ class Cart {
* @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 (! $this->contents()->count_all())
if (! count($this->contents()))
return 'The cart is empty.';
Style::add(array(
@@ -39,7 +74,7 @@ class Cart {
));
$output = '<table class="cart_blocklist" border="0">';
foreach ($this->contents()->find_all() as $item) {
foreach ($this->contents() as $item) {
$ppa = $item->product->get_price_array();
$pdata = Period::details($item->recurr_schedule,$item->product->price_recurr_weekday,time(),TRUE);
@@ -58,48 +93,5 @@ class Cart {
return $output;
}
/**
* Test to see if the cart has some trial options
*
* @return boolean
*/
public function has_trial() {
foreach ($this->contents()->find_all() as $item)
if ($item->product->is_trial())
return TRUE;
return FALSE;
}
public function subtotal() {
$total = 0;
foreach ($this->contents()->find_all() as $item) {
$ppa = $item->product->get_price_array();
$period = Period::details($item->recurr_schedule,$item->product->price_recurr_weekday,time(),TRUE);
$total += $item->quantity*$ppa[$item->recurr_schedule]['price_base']*$period['prorata'];
$total += $item->quantity*$ppa[$item->recurr_schedule]['price_setup'];
}
return $total;
}
/**
* Calculate Tax for the cart items
*
* @return unknown_type
* @uses Tax
*/
public function tax() {
// @todo Tax zone should come from somewhere else
return Tax::detail(61,NULL,$this->subtotal());
}
public function total() {
// @todo Tax zone should come from somewhere else
return $this->subtotal()+Tax::total(61,NULL,$this->subtotal());
}
}
?>