Skip to content

Commit

Permalink
Storefront: skipping of payment checkout page for orders with zero to…
Browse files Browse the repository at this point in the history
…tal amount added.
  • Loading branch information
abolabo@gmail.com committed Mar 1, 2013
1 parent 6a5d84d commit e1521a6
Show file tree
Hide file tree
Showing 8 changed files with 150 additions and 19 deletions.
15 changes: 12 additions & 3 deletions public_html/storefront/controller/api/checkout/confirm.php
Expand Up @@ -98,7 +98,11 @@ public function post() {
$this->data['payment_address'] = '';
}

$this->data['payment_method'] = $this->session->data['payment_method']['title'];
if($this->session->data['payment_method']['id'] != 'no_payment_required'){
$this->data['payment_method'] = $this->session->data['payment_method']['title'];
}else{
$this->data['payment_method'] = '';
}

$this->loadModel('tool/seo_url');
$this->loadModel('tool/image');
Expand Down Expand Up @@ -135,8 +139,13 @@ public function post() {
$this->data['text_accept_agree'] = '';
}

// Load selected paymnet required data from payment extension
$payment_controller = $this->dispatch( 'responses/extension/' . $this->session->data['payment_method']['id'] . '/api' );
// Load selected paymnet required data from payment extension
if($this->session->data['payment_method']['id'] != 'no_payment_required'){
$payment_controller = $this->dispatch( 'responses/extension/' . $this->session->data['payment_method']['id'] . '/api' );
}else{
$payment_controller = $this->dispatch( 'responses/checkout/no_payment/api' );
}

$this->load->library('json');
$this->data['payment'] = AJson::decode( $payment_controller->dispatchGetOutput(), TRUE );
//set process_rt for process step to run the payment
Expand Down
26 changes: 16 additions & 10 deletions public_html/storefront/controller/pages/checkout/confirm.php
Expand Up @@ -28,7 +28,7 @@ public function main() {

//init controller data
$this->extensions->hk_InitData($this,__FUNCTION__);

if (!$this->cart->hasProducts() || (!$this->cart->hasStock() && !$this->config->get('config_stock_checkout'))) {
$this->redirect($this->html->getSecureURL('checkout/cart'));
}
Expand Down Expand Up @@ -60,7 +60,7 @@ public function main() {
$this->tax->setZone($this->session->data['country_id'], $this->session->data['zone_id']);

}

if (!isset($this->session->data['payment_address_id']) || !$this->session->data['payment_address_id']) {
$this->redirect($this->html->getSecureURL('checkout/payment'));
}
Expand Down Expand Up @@ -136,17 +136,21 @@ public function main() {
$this->data['shipping_method_price'] = $this->session->data['shipping_method']['title'];
$this->data['checkout_shipping_edit'] = $this->html->getSecureURL('checkout/shipping', '&mode=edit');
$this->data['checkout_shipping_address'] = $this->html->getSecureURL('checkout/address/shipping');
$payment_address = $this->model_account_address->getAddress($this->session->data['payment_address_id']);

$payment_address = $this->model_account_address->getAddress($this->session->data['payment_address_id']);
if ($payment_address) {
$this->data['payment_address'] = $this->customer->getFormatedAdress($payment_address, $payment_address[ 'address_format' ] );
} else {
$this->data['payment_address'] = '';
}
if($this->session->data['payment_method']['id'] != 'no_payment_required'){
$this->data['payment_method'] = $this->session->data['payment_method']['title'];
}else{
$this->data['payment_method'] = '';
}

$this->data['payment_method'] = $this->session->data['payment_method']['title'];
$this->data['checkout_payment_edit'] = $this->html->getSecureURL('checkout/payment', '&mode=edit');
$this->data['checkout_payment_address'] = $this->html->getSecureURL('checkout/address/payment');
$this->data['checkout_payment_edit'] = $this->html->getSecureURL('checkout/payment', '&mode=edit');
$this->data['checkout_payment_address'] = $this->html->getSecureURL('checkout/address/payment');

$this->loadModel('tool/seo_url');
$this->loadModel('tool/image');
Expand Down Expand Up @@ -190,8 +194,11 @@ public function main() {
} else {
$this->data['text_accept_agree'] = '';
}

$this->addChild('responses/extension/' . $this->session->data['payment_method']['id'], 'payment');
if($this->session->data['payment_method']['id'] != 'no_payment_required'){
$this->addChild('responses/extension/' . $this->session->data['payment_method']['id'], 'payment');
}else{
$this->addChild('responses/checkout/no_payment', 'payment');
}

$this->view->batchAssign( $this->data );
$this->processTemplate('pages/checkout/confirm.tpl' );
Expand All @@ -200,4 +207,3 @@ public function main() {
$this->extensions->hk_UpdateData($this,__FUNCTION__);
}
}
?>
13 changes: 11 additions & 2 deletions public_html/storefront/controller/pages/checkout/payment.php
Expand Up @@ -135,6 +135,17 @@ public function main() {
$this->redirect($this->html->getSecureURL('checkout/confirm'));
}

// If total amount of order is zero - do redirect on confirmation page
$total = $this->cart->buildTotalDisplay();
if($total['total']==0){
$this->session->data[ 'payment_method' ] = array(
'id' => 'no_payment_required',
'title' => $this->language->get('no_payment_required')
);
$this->redirect($this->html->getSecureURL('checkout/confirm'));

}

//# If only 1 payment and it is set to be defaulted, select and skip and redirect to confirmation
if (count($this->session->data[ 'payment_methods' ]) == 1 && $this->request->get['mode'] != 'edit') {
//set only method
Expand Down Expand Up @@ -348,5 +359,3 @@ private function _validateCoupon() {
}
}
}

?>
@@ -0,0 +1,74 @@
<?php
/*------------------------------------------------------------------------------
$Id$
AbanteCart, Ideal OpenSource Ecommerce Solution
http://www.AbanteCart.com
Copyright © 2011 Belavier Commerce LLC
This source file is subject to Open Software License (OSL 3.0)
License details is bundled with this package in the file LICENSE.txt.
It is also available at this URL:
<http://www.opensource.org/licenses/OSL-3.0>
UPGRADE NOTE:
Do not edit or add to this file if you wish to upgrade AbanteCart to newer
versions in the future. If you wish to customize AbanteCart for your
needs please refer to http://www.AbanteCart.com for more information.
------------------------------------------------------------------------------*/

class ControllerResponsesCheckoutNoPayment extends AController {
public function main() {

$item = HtmlElementFactory::create( array( 'type' => 'button',
'name' => 'back',
'style' => 'button',
'text' => $this->language->get('button_back') ));
$item = $item->getHtml();
$this->view->assign('button_back', $item);

$item = HtmlElementFactory::create( array( 'type' => 'button',
'name' => 'checkout',
'style' => 'button',
'text' => $this->language->get('button_confirm') ));
$item = $item->getHtml();
$this->view->assign('button_confirm', $item);

$this->view->assign('continue', $this->html->getSecureURL('checkout/success'));

if ($this->request->get['rt'] != 'checkout/guest_step_3') {
$this->view->assign('back', $this->html->getSecureURL('checkout/cart'));
} else {
$this->view->assign('back', $this->html->getSecureURL('checkout/guest_step_2'));
}

$this->processTemplate('responses/checkout/no_payment.tpl' );
}

public function api() {
$data = array();

$data['text_note'] = $this->language->get('text_note');
$data['process_rt'] = 'checkout/no_payment/api_confirm';

$this->load->library('json');
$this->response->setOutput(AJson::encode($data));
}


public function api_confirm() {
$data = array();

$this->confirm();
$data[ 'success' ] = 'completed';

$this->load->library('json');
$this->response->setOutput(AJson::encode($data));
}

public function confirm() {
$this->load->model('checkout/order');
$this->model_checkout_order->confirm($this->session->data['order_id'], $this->config->get('config_order_status_id'));
}
}
6 changes: 5 additions & 1 deletion public_html/storefront/language/english/english.xml
Expand Up @@ -159,5 +159,9 @@
<definition>
<key>notice_out_of_stock_body</key>
<value><![CDATA[Product "%s" has reached zero or negative stock count for main product or all options. <br> As a result of autodisable setting, product (%s) was auto disabled!]]></value>
</definition>
</definition>
<definition>
<key>no_payment_required</key>
<value><![CDATA[No Payment Required]]></value>
</definition>
</definitions>
6 changes: 5 additions & 1 deletion public_html/storefront/language/spanish/spanish.xml
Expand Up @@ -159,5 +159,9 @@
<definition>
<key>notice_out_of_stock_body</key>
<value><![CDATA[Product "%s", habet nulla seu negative stirpe attigit, Numerabis main productum sive omnia bene. ut a praecessi of <br> autodisable occasum, uber (%s) disabled car erat!]]></value>
</definition>
</definition>
<definition>
<key>no_payment_required</key>
<value><![CDATA[No Pago Requerido]]></value>
</definition>
</definitions>
Expand Up @@ -43,7 +43,7 @@
</table>
<div class="gray_separator"></div>
<?php } ?>

<?php if ($payment_method) { ?>
<table width="100%">
<tr>
<td align="left" valign="top" class="checkout_heading"><?php echo $text_payment; ?></td>
Expand All @@ -66,7 +66,7 @@
</tr>
</table>
<div class="gray_separator"></div>

<?php } ?>
<table width="100%">
<tr>
<td align="left" valign="top" class="checkout_heading"><?php echo $text_cart_items; ?></td>
Expand Down
@@ -0,0 +1,25 @@
<div class="buttons">
<table>
<tr>
<td align="left"><?php echo $button_back; ?></td>
<td align="right"><?php echo $button_confirm; ?></td>
</tr>
</table>
</div>
<script type="text/javascript"><!--
$('#back').click(function() {
location = '<?php echo $back; ?>';
});
$('body').append('<div id="blocker" style="display: none; width: 1667px; height: 1200px; z-index: 1001; background: none repeat scroll 0 0 white; opacity: 0; left: 0; position: absolute; top: 0;"></div>');
$('#checkout').click(function() {
$('#blocker').show();
$.ajax({
type: 'GET',
url: 'index.php?rt=r/checkout/no_payment/confirm',
success: function() {
location = '<?php echo $continue; ?>';
}
});
});
//--></script>

0 comments on commit e1521a6

Please sign in to comment.