Cart work for payments and Paypal work to test
This commit is contained in:
@@ -12,71 +12,56 @@
|
||||
*/
|
||||
class Controller_Cart extends Controller_TemplateDefault {
|
||||
/**
|
||||
* Default action when called
|
||||
* List the cart contents
|
||||
*/
|
||||
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');
|
||||
$output = '';
|
||||
$co = Cart::instance();
|
||||
|
||||
// If the cart is empty, we'll return here.
|
||||
if (! Cart::instance()->contents()->count_all())
|
||||
if (! count($co->contents()))
|
||||
Block::add(array(
|
||||
'title'=>_('Empty Cart'),
|
||||
'body'=>_('The cart is empty')
|
||||
));
|
||||
|
||||
else {
|
||||
Style::add(array(
|
||||
'type'=>'file',
|
||||
'data'=>'css/cart_contents.css',
|
||||
));
|
||||
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 = 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);
|
||||
$checkout = ORM::factory('Checkout')->where_active()->find_all()->as_array();
|
||||
|
||||
$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);
|
||||
foreach ($co->contents() as $cio)
|
||||
$checkout = array_intersect($checkout,$cio->checkout()->as_array());
|
||||
|
||||
$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);
|
||||
$payopt = array();
|
||||
foreach ($checkout as $cko)
|
||||
$payopt[$cko->id] = $cko->name;
|
||||
|
||||
// If we are a plugin product, we might need more information
|
||||
// @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)))) {
|
||||
$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 .= _('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 .= Form::close();
|
||||
|
||||
Block::add(array(
|
||||
'title'=>_('Your Items'),
|
||||
'title'=>_('Payment'),
|
||||
'body'=>$output,
|
||||
));
|
||||
}
|
||||
|
||||
// Suppress our right hand tab
|
||||
$this->template->right = ' ';
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -87,13 +72,10 @@ class Controller_Cart extends Controller_TemplateDefault {
|
||||
|
||||
$cart->session_id = Session::instance()->id();
|
||||
|
||||
if (Auth::instance()->logged_in())
|
||||
$cart->account_id = Auth::instance()->get_user()->id;
|
||||
|
||||
if ($cart->values($_POST)->check())
|
||||
if ($cart->values(Request::current()->post())->check())
|
||||
$cart->save();
|
||||
else
|
||||
echo Kohana::debug($cart->validate()->errors());
|
||||
throw new Kohana_Exception('Unable to add to cart');
|
||||
|
||||
if ($cart->saved())
|
||||
HTTP::redirect('cart/index');
|
||||
@@ -102,10 +84,8 @@ class Controller_Cart extends Controller_TemplateDefault {
|
||||
}
|
||||
|
||||
public function action_empty() {
|
||||
$cart = ORM::factory('Cart')
|
||||
->where('session_id','=',session_id());
|
||||
|
||||
$cart->delete_all();
|
||||
foreach (ORM::factory('Cart')->where('session_id','=',Session::instance()->id())->find_all() as $co)
|
||||
$co->delete();
|
||||
|
||||
$this->template->content = _('Cart Emptied');
|
||||
}
|
||||
|
Reference in New Issue
Block a user