Internal overhaul of Cart/Checkout and other minor fixes
This commit is contained in:
@@ -16,52 +16,21 @@ class Controller_Cart extends Controller_TemplateDefault {
|
||||
* List the cart contents
|
||||
*/
|
||||
public function action_index() {
|
||||
$output = '';
|
||||
$co = Cart::instance();
|
||||
|
||||
// If the cart is empty, we'll return here.
|
||||
if (! count($co->contents()))
|
||||
Block::add(array(
|
||||
'title'=>_('Empty Cart'),
|
||||
'body'=>_('The cart is empty')
|
||||
));
|
||||
if (! $co->contents()->count())
|
||||
$this->template->content = _('Cart is Empty');
|
||||
|
||||
else {
|
||||
Block::add(array(
|
||||
'title'=>_('Cart Items'),
|
||||
'body'=>Table::display(
|
||||
$co->contents(),
|
||||
NULL,
|
||||
array(
|
||||
'item()->q'=>array('label'=>'Quantity'),
|
||||
'item()->i'=>array('label'=>'Item'),
|
||||
'item()->t'=>array('label'=>'Total','class'=>'right'),
|
||||
),
|
||||
array(
|
||||
'type'=>'list',
|
||||
)
|
||||
),
|
||||
));
|
||||
$output = View::factory('cart/view')->set('o',$co);
|
||||
|
||||
$checkout = ORM::factory('Checkout')->where_active()->find_all()->as_array();
|
||||
|
||||
foreach ($co->contents() as $cio)
|
||||
$checkout = array_intersect($checkout,$cio->checkout()->as_array());
|
||||
|
||||
$payopt = array();
|
||||
foreach ($checkout as $cko)
|
||||
$payopt[$cko->id] = $cko->name;
|
||||
|
||||
$output .= _('Total amount due for payment').' '.$co->total(TRUE);
|
||||
$output .= Form::open('checkout/before');
|
||||
$output .= Form::select('checkout_id',$payopt);
|
||||
$output .= Form::submit('submit',_('Checkout'));
|
||||
$output .= View::factory('cart/payment')->set('o',$co);
|
||||
$output .= Form::close();
|
||||
|
||||
Block::add(array(
|
||||
'title'=>_('Payment'),
|
||||
'body'=>$output,
|
||||
));
|
||||
Block::factory()
|
||||
->body($output);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -69,24 +38,19 @@ class Controller_Cart extends Controller_TemplateDefault {
|
||||
* Add an item to the cart
|
||||
*/
|
||||
public function action_add() {
|
||||
$cart = ORM::factory('Cart');
|
||||
$co = ORM::factory('Cart');
|
||||
|
||||
$cart->session_id = Session::instance()->id();
|
||||
$co->values(Request::current()->post());
|
||||
$co->session_id = Session::instance()->id();
|
||||
|
||||
if ($cart->values(Request::current()->post())->check())
|
||||
$cart->save();
|
||||
else
|
||||
throw new Kohana_Exception('Unable to add to cart');
|
||||
if (! $this->save($co))
|
||||
throw HTTP_Exception::factory(501,_('There was a problem adding the item to the cart.'));
|
||||
|
||||
if ($cart->saved())
|
||||
HTTP::redirect('cart/index');
|
||||
else
|
||||
throw new Kohana_Exception(_('There was a problem adding the item to the cart.'));
|
||||
HTTP::redirect('cart/index');
|
||||
}
|
||||
|
||||
public function action_empty() {
|
||||
foreach (ORM::factory('Cart')->where('session_id','=',Session::instance()->id())->find_all() as $co)
|
||||
$co->delete();
|
||||
Cart::instance()->delete();
|
||||
|
||||
$this->template->content = _('Cart Emptied');
|
||||
}
|
||||
|
Reference in New Issue
Block a user