Is it possible to skip the payment step if the value of the cart is $0? For example, with a 100% off coupon we'd prefer not to show the payment step. I could write some logic to set the payment method to a hidden "Free" payment method, but that seems a little hacky and I'm wondering if there's a better way?
Thanks,
Phil
Page 1 of 1
Skip payment step
#2
Posted 31 August 2010 - 04:09 PM
Hi, Phil!
You can use API for hiding the payment step. Please read this thread: http://forum.lemonst...n-is-available/
You need:
1. On the checkout page, check whether the order total is 0. If so, set the no-payment payment method (you will find the details in the thread).
2. In the checkout progress partial hide the Payment Method step if the order total is 0.
3. On the Shipping Method step add the skip_to hidden field with the "review" value to jump to the Order Review step after the Shipping Method step.
Thanks
You can use API for hiding the payment step. Please read this thread: http://forum.lemonst...n-is-available/
You need:
1. On the checkout page, check whether the order total is 0. If so, set the no-payment payment method (you will find the details in the thread).
2. In the checkout progress partial hide the Payment Method step if the order total is 0.
3. On the Shipping Method step add the skip_to hidden field with the "review" value to jump to the Order Review step after the Shipping Method step.
Thanks
#3
Posted 09 September 2010 - 08:38 AM
Aleksey,
I've been working on this more, and there are cases where the cart could come to a total of 0, but they still need to pay for shipping. It seems to me that the steps you recommended wouldn't work in that case. What do you suggest?
Thanks,
Phil
I've been working on this more, and there are cases where the cart could come to a total of 0, but they still need to pay for shipping. It seems to me that the steps you recommended wouldn't work in that case. What do you suggest?
Thanks,
Phil
#4
Posted 09 September 2010 - 03:11 PM
Hi, Phil!
Shipping cost is not known until the customer selects a shipping method on the Shipping Method checkout step. This means that we can make a decision about jumping over the payment method step only after the Shipping Method step. I just made a minor improvement in the API which will allow us to implement this trick.
1. Please update your copy.
2. On the checkout page - remove the code for setting the payment method which you added earlier
3. Go to the AJAX tab on the Checkout page and paste the following code into the text area:
4. On the Shipping Method partial, replace the onclick handler on the Next button with the following:
How it works
When you click the Next button on the Shipping Method checkout step, the new process_shipping_method event handler first calls the default event handler, which processes the shipping method form. After that it checks whether the shipping quote and order total is 0. If so, it assigns the default payment method, sets the skip_to hidden field to the 'review' value (to skip the payment method) and calls the default page action again (it is equal to clicking the Next button in this case).
Thanks
Shipping cost is not known until the customer selects a shipping method on the Shipping Method checkout step. This means that we can make a decision about jumping over the payment method step only after the Shipping Method step. I just made a minor improvement in the API which will allow us to implement this trick.
1. Please update your copy.
2. On the checkout page - remove the code for setting the payment method which you added earlier
3. Go to the AJAX tab on the Checkout page and paste the following code into the text area:
function process_shipping_method($controller)
{
$controller->action();
if ($controller->data['shipping_quote'] == 0 && $controller->data['estimated_total'] == 0)
{
$default_method = Shop_PaymentMethod::find_by_api_code('default');
Shop_CheckoutData::set_payment_method($default_method->id);
$_POST['skip_to'] = 'review';
$controller->action();
}
}4. On the Shipping Method partial, replace the onclick handler on the Next button with the following:
onclick="return $(this).getForm().sendRequest('process_shipping_method', {update:{'checkout_page': 'checkout_partial'}})"How it works
When you click the Next button on the Shipping Method checkout step, the new process_shipping_method event handler first calls the default event handler, which processes the shipping method form. After that it checks whether the shipping quote and order total is 0. If so, it assigns the default payment method, sets the skip_to hidden field to the 'review' value (to skip the payment method) and calls the default page action again (it is equal to clicking the Next button in this case).
Thanks
#6
Posted 26 April 2011 - 01:55 PM
It's not working so well for me.
I have created a shipping method with the api code of 'free'
I am also using the customised checkout method found in the Utility theme. Anyway, this is the partial for my payment_method block.
My submit button in the shipping_method block
and these are my Ajax handlers.
To me it seems to be right, but perhaps my amateur eye isn't the best.
Basically what is happening is that I am seeing the payment methods, apart from the free method - but I want it to just go direct to the review and pay screen.
Any ideas where I am going wrong?
I have created a shipping method with the api code of 'free'
I am also using the customised checkout method found in the Utility theme. Anyway, this is the partial for my payment_method block.
<?
$sales_email = $site_settings->company->sales_email;
?>
<div class="col-8">
<h3 class="style-2">Payment Method</h3>
<em>Credit Card payments are on their way, but go on now, pay by credit card using our PayPal if you like.</em>
<? if(!count($payment_methods)): ?>
<p>There are no payment methods available for your location. Please contact our sales department: <a href="mailto:<?= $sales_email ?>"><?= $sales_email ?></a>.</p>
<? return ?>
<? endif ?>
<p>Please select payment method.</p>
<ul class="form clearfix">
<? foreach($payment_methods as $method): ?>
<? if($method->ls_api_code != 'free'): ?>
<li class="field checkbox <?= ($method->ls_api_code) ?>">
<div><input <?= radio_state($method->id == $payment_method->id) ?> id="method<?= $method->id ?>" type="radio" name="payment_method" value="<?= $method->id ?>" /></div>
<label for="method<?= $method->id ?>">
<?= h($method->name) ?>
<? if($method->description): ?>
<span class="comment"><?= h($method->description) ?></span>
<? endif ?>
</label>
</li>
<? endif ?>
<? endforeach ?>
</ul>
<div id="notes">
<label for="customer_notes">Special Instructions</label>
<textarea name="customer_notes" id="customer_notes" class="txt_area"><?= h(Shop_CheckoutData::get_customer_notes()) ?></textarea>
</div>
<div class="grid_4 omega next_step pay">
<p>Continue to review & pay</p>
<input class="checkout btn" type="submit" value="Next →" onclick="
$('#payment_method').sendRequest('on_action', {
update: {'content': 'ls_cms_page'},
extraFields: {
'skip_to': 'review'
}
}); return false;" />
</div>
<script>
$('#payment_method input[type=radio]').click(function() {
return $('#payment_method').sendRequest('on_action', {
update: {'payment_method': 'ls_cms_page'},
extraFields: {
'checkout_step': 'payment_method',
'skip_to': 'payment_method',
'partial_step': true
}
});
});
</script>My submit button in the shipping_method block
$('#shipping_method input[type=radio]').click(function() {
return $('#shipping_method').sendRequest('process_shipping_method', {
update: {'payment_method': 'ls_cms_page'},
extraFields: {
'checkout_step': 'shipping_method',
'skip_to': 'payment_method',
'partial_step': true
}
});
});and these are my Ajax handlers.
function on_updateBilling($controller) {
if ((!$controller->customer || $controller->customer->guest) && !trim(post('customer_password'))) {
foreach(Shop_Cart::list_active_items() as $item) {
if (count($item->product->files)) {
throw new Cms_Exception("You must create an account to download your digital goods. Please enter a password");
}
}
}
Shop_CheckoutData::set_billing_info(null);
if(post('customer_password')) {
$_POST['register_customer'] = 1;
Shop_CheckoutData::set_customer_password();
}
}
function process_shipping_method($controller)
{
$controller->action();
if ($controller->data['shipping_quote'] == 0 && $controller->data['estimated_total'] == 0)
{
$default_method = Shop_PaymentMethod::find_by_api_code('free');
Shop_CheckoutData::set_payment_method($default_method->id);
$_POST['skip_to'] = 'review';
$controller->action();
}
}
function on_updateShipping($controller) {
Shop_CheckoutData::set_shipping_info(null);
}
function on_copyBillingToShipping($controller) {
$billing_info = Shop_CheckoutData::get_billing_info();
$shipping_info = Shop_CheckoutData::get_shipping_info();
$shipping_info->copy_from($billing_info);
Shop_CheckoutData::set_shipping_info($shipping_info);
}
function on_doPayment($controller) {
$order_hash = trim(post('order_hash'));
if (!$order_hash)
return;
$order = Shop_Order::create()->find_by_order_hash($order_hash);
if (!$order)
return;
if (post('customer_notes')) {
$order->customer_notes = post('customer_notes');
try { $order->save(); } catch ( Exception $ex ) { }
}
try {
$order->payment_method->define_form_fields();
$payment_method_obj = $order->payment_method->get_paymenttype_object();
$payment_method_obj->process_payment_form($_POST, $order->payment_method, $order);
} catch ( Exception $ex ) {
if ( $ex->getMessage() == 'The card was declined by the payment gateway.' ) {
$message = Shop_PaymentLogRecord::create()
->where('order_id = ?', $order->id)
->order('created_at DESC')->limit(1)
->find();
$message = $message ? ( ': ' . $message->message ) : '.';
throw new Phpr_ApplicationException('The card was declined by the payment gateway' . $message );
} else {
throw $ex;
}
}
$return_page = $order->payment_method->receipt_page;
// Reset all data
Cms_VisitorPreferences::set('order_hash', null);
Shop_Cart::remove_active_items();
Shop_CheckoutData::set_customer_notes('');
Shop_CheckoutData::set_coupon_code('');
if ($return_page)
Phpr::$response->redirect(root_url($return_page->url.'/'.$order->order_hash));
}
To me it seems to be right, but perhaps my amateur eye isn't the best.
Basically what is happening is that I am seeing the payment methods, apart from the free method - but I want it to just go direct to the review and pay screen.
Any ideas where I am going wrong?
#7
Posted 01 November 2011 - 12:11 PM
I've just implemented this too and it works perfectly.
Thanks Aleksey.
Thanks Aleksey.
Share this topic:
Page 1 of 1

Help














