OSB enhancements to date
This commit is contained in:
150
modules/checkout/classes/controller/checkout.php
Normal file
150
modules/checkout/classes/controller/checkout.php
Normal file
@@ -0,0 +1,150 @@
|
||||
<?php defined('SYSPATH') or die('No direct access allowed.');
|
||||
|
||||
/**
|
||||
* This class provides checkout capabilities.
|
||||
*
|
||||
* @package OSB
|
||||
* @subpackage Checkout
|
||||
* @category Controllers
|
||||
* @author Deon George
|
||||
* @copyright (c) 2010 Open Source Billing
|
||||
* @license http://dev.osbill.net/license.html
|
||||
*/
|
||||
class Controller_Checkout extends Controller_TemplateDefault {
|
||||
protected $auth_required = TRUE;
|
||||
protected $noauth_redirect = 'login/register';
|
||||
|
||||
/**
|
||||
* This is the main call to export, providing a list of items to export and
|
||||
* setting up the page to call the export plugin when submitted.
|
||||
*/
|
||||
public function action_index() {
|
||||
if ($_POST)
|
||||
return $this->checkout();
|
||||
|
||||
// @todo - this should be a global config item
|
||||
$mediapath = Route::get('default/media');
|
||||
$block = new block;
|
||||
|
||||
// @todo Items in the cart dont have account_id if they were put in the cart when the user was not logged in
|
||||
|
||||
// If the cart is empty, we'll return here.
|
||||
if (! Cart::instance()->contents()->count_all())
|
||||
$block->add(array(
|
||||
'title'=>_('Empty Cart'),
|
||||
'body'=>_('The cart is empty')
|
||||
));
|
||||
|
||||
else {
|
||||
Style::add(array(
|
||||
'type'=>'file',
|
||||
'data'=>'css/checkout_cartlist.css',
|
||||
));
|
||||
|
||||
// Show a list of items in the cart
|
||||
$output = '<table class="checkout_cartlist" border="0">';
|
||||
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);
|
||||
|
||||
$output .= View::factory('cart/checkout_list')
|
||||
->set('price_firstinvoice',$item->quantity*$ppa[$item->recurr_schedule]['price_base']*$pdata['prorata'])
|
||||
->set('price_setup',$item->quantity*$ppa[$item->recurr_schedule]['price_setup'])
|
||||
->set('service_start',$pdata['date'])
|
||||
->set('service_end',$pdata['end'])
|
||||
->set('price_recurring',$item->quantity*$ppa[$item->recurr_schedule]['price_base'])
|
||||
->set('item',$item)
|
||||
->set('mediapath',$mediapath);
|
||||
}
|
||||
$output .= '</table>';
|
||||
|
||||
$block->add(array(
|
||||
'title'=>_('Your Items'),
|
||||
'body'=>$output,
|
||||
));
|
||||
|
||||
$po = ORM::factory('checkout')
|
||||
->payment_options_cart();
|
||||
|
||||
// @todo Country value should come from somewhere?
|
||||
$block->add(array(
|
||||
'title'=>_('Order Total'),
|
||||
'body'=>View::factory('cart/checkout_total')
|
||||
->set('cart',Cart::instance())
|
||||
->set('country',61),
|
||||
));
|
||||
|
||||
$output = Form::open();
|
||||
$output .= '<table class="payment_options_box" border="0">';
|
||||
|
||||
foreach ($po as $payment) {
|
||||
$output .= View::factory('checkout/payment_option')
|
||||
->set('payment',$payment);
|
||||
}
|
||||
|
||||
// @todo Add Javascript to stop submission if something not selected
|
||||
$output .= '<tr><td> </td></tr>';
|
||||
$output .= '<tr>';
|
||||
$output .= sprintf('<td>%s</td>',Form::submit('submit',_('Submit Order')));
|
||||
$output .= '</tr>';
|
||||
|
||||
$output .= '</table>';
|
||||
$output .= Form::close();
|
||||
|
||||
$block->add(array(
|
||||
'title'=>_('Available Payment Methods'),
|
||||
'body'=>$output,
|
||||
));
|
||||
}
|
||||
|
||||
$this->template->content = $block;
|
||||
|
||||
// Suppress our right hand tab
|
||||
$this->template->right = ' ';
|
||||
}
|
||||
|
||||
/**
|
||||
* Process checkout
|
||||
*/
|
||||
private function checkout() {
|
||||
$invoice = ORM::factory('invoice');
|
||||
|
||||
// Add our individual items to the invoice
|
||||
foreach (Cart::instance()->contents()->find_all() as $item) {
|
||||
$invoice_item = $invoice->add_item();
|
||||
|
||||
$invoice_item->product_id = $item->product_id;
|
||||
$invoice_item->product_attr = $item->product_attr;
|
||||
$invoice_item->product_attr_cart = $item->product_attr;
|
||||
$invoice_item->quantity = $item->quantity;
|
||||
$invoice_item->recurring_schedule = $item->recurr_schedule;
|
||||
|
||||
$ppa = $item->product->get_price_array();
|
||||
$period = Period::details($item->recurr_schedule,$item->product->price_recurr_weekday,time(),TRUE);
|
||||
// @todo rounding should be a global config
|
||||
$invoice_item->price_base = round($item->quantity*$ppa[$item->recurr_schedule]['price_base']*$period['prorata'],2);
|
||||
$invoice_item->price_setup = round($item->quantity*$ppa[$item->recurr_schedule]['price_setup'],2);
|
||||
}
|
||||
|
||||
$invoice->account_id = Auth::instance()->get_user()->id;
|
||||
$invoice->type = 2; // INVOICED VIA CHECKOUT
|
||||
$invoice->status = 1; // INVOICE IS NOT CANCELLED
|
||||
$invoice->due_date = time(); // DATE INVOICE MUST BE PAID
|
||||
$invoice->billed_currency_id = 6; // @todo This should come from the site config or the currency selected
|
||||
/*
|
||||
$invoice->process_status = NULL; // TO BE PROCESSED
|
||||
$invoice->billing_status = NULL; // UNPAID
|
||||
$invoice->refund_status = NULL; // NOT REFUNDED
|
||||
$invoice->print_status = NULL; // NOT YET PRINTED
|
||||
$invoice->discount_amt = NULL; // @todo CALCULATE DISCOUNTS
|
||||
$invoice->checkout_plugin_id = NULL; // @todo Update the selected checkout plugin
|
||||
$invoice->checkout_plugin_data = NULL; // @todo Data required for the checkout plugin
|
||||
*/
|
||||
|
||||
if ($invoice->check())
|
||||
$invoice->save();
|
||||
else
|
||||
throw new Kohana_Exception('Problem saving invoice - Failed check()');
|
||||
}
|
||||
}
|
||||
?>
|
67
modules/checkout/classes/model/checkout.php
Normal file
67
modules/checkout/classes/model/checkout.php
Normal file
@@ -0,0 +1,67 @@
|
||||
<?php defined('SYSPATH') or die('No direct access allowed.');
|
||||
|
||||
/**
|
||||
* This class provides checkout capabilities.
|
||||
*
|
||||
* @package OSB
|
||||
* @subpackage Checkout
|
||||
* @category Models
|
||||
* @author Deon George
|
||||
* @copyright (c) 2010 Open Source Billing
|
||||
* @license http://dev.osbill.net/license.html
|
||||
*/
|
||||
class Model_Checkout extends ORMOSB {
|
||||
protected $_has_many = array(
|
||||
'payment' => array()
|
||||
);
|
||||
|
||||
/**
|
||||
* Give a cart, this will present the available checkout options
|
||||
*
|
||||
* Trial Products are NEW products
|
||||
* Cart items are NEW products
|
||||
* Invoice items are RE-OCCURING items (ie: carts are not re-occuring)
|
||||
*
|
||||
*/
|
||||
public function payment_options_cart() {
|
||||
$cart = Cart::instance();
|
||||
|
||||
$available_payments = array();
|
||||
|
||||
if ($cart->has_trial())
|
||||
$this->and_where('allow_trial','=',TRUE);
|
||||
|
||||
$this->and_where('allow_new','=',TRUE);
|
||||
|
||||
foreach ($this->where('active','=',TRUE)->find_all() as $item) {
|
||||
// Check that the cart total meets the minimum requirement
|
||||
if ($item->total_minimum AND $cart->total() < $item->total_minimum)
|
||||
continue;
|
||||
|
||||
// Check the cart total meets the maximum requirement
|
||||
if (($item->total_maximum AND $cart->total() > $item->total_maximum) OR ($item->total_maximum == '0' AND $cart->total()))
|
||||
continue;
|
||||
|
||||
// Check that the payment option is available to this client based on groups
|
||||
// @todo Enable this test
|
||||
|
||||
// Check that the payment option is not prohibited by an SKU item
|
||||
// @todo Enable this test
|
||||
|
||||
// Check if this payment method is a default payment method
|
||||
// @todo Enable this test
|
||||
// By Amount
|
||||
// By Currency
|
||||
// By Group
|
||||
// By Country
|
||||
|
||||
// This payment option is valid
|
||||
array_push($available_payments,$item);
|
||||
// Sort the checkout options
|
||||
// @todo Is this required?
|
||||
}
|
||||
|
||||
return $available_payments;
|
||||
}
|
||||
}
|
||||
?>
|
Reference in New Issue
Block a user