Get Opencart Order ID in COD Payment Module Redirect Link

孤街浪徒 提交于 2019-12-25 09:38:51

问题


First of all thank you for giving your valuable time to help me.

My Situation -

I am using Opencart 2.1.0.1

Cash on Delivery Payment Method

Custom OnePageCheckout

Custom Theme

I have implemented a custom process which verifies the customer from our own database via a cron job running every minute.

This is the default code in Opencart catalog/view/theme/template/payment/cod.tpl

<div class="buttons">
  <div class="pull-right">
    <input type="button" value="<?php echo $button_confirm; ?>" id="button-confirm" class="btn btn-primary" data-loading-text="<?php echo $text_loading; ?>" />
  </div>
</div>
<script type="text/javascript"><!--
$('#button-confirm').on('click', function() {
    $.ajax({
        type: 'get',
        url: 'index.php?route=payment/cod/confirm',
        cache: false,
        beforeSend: function() {
            $('#button-confirm').button('loading');
        },
        complete: function() {
            $('#button-confirm').button('reset');
        },
        success: function() {
            location = '<?php echo $continue; ?>';
        }
    });
});
//--></script>

As I want to redirect the customer to the following page after successful checkout. https://www.myopencartstore.com/confirm.php?order_id=$order_id

Required Action : I want to pass on the order_id variable in the url parameter as highlighted in bold above.

My Modified Code -

<div class="buttons">
  <div class="pull-right">
    <input type="button" value="<?php echo $button_confirm; ?>" id="button-confirm" class="btn btn-primary" data-loading-text="<?php echo $text_loading; ?>" />
  </div>
</div>
<script type="text/javascript"><!--
$('#button-confirm').on('click', function() {
    $.ajax({
        type: 'get',
        url: 'index.php?route=payment/cod/confirm',
        cache: false,
        beforeSend: function() {
            $('#button-confirm').button('loading');
        },
        complete: function() {
            $('#button-confirm').button('reset');
        },
        success: function() {
            location = '<?php echo 'confirm-success.php'; ?>';
        }
    });
});
//--></script>

Please help how to do the same.

I want to bye-pass the checkout/success page.

I've tried implementing $this->session->data['order_id']; to get the Order ID parameter.

I've tried all my efforts and thus maximum I could do is to just redirect to the desired page but without any parameters.


回答1:


If your page url is confirm.php the follow the following things.

Open catalog\view\theme\default\template\payment\cod.tpl

change

location = '<?php echo $continue; ?>';

to

location = '<?php echo HTTP_SERVER; ?>confirm.php';

Or you can change on page catalog/controller/payment/cod.php

$data['continue'] = $this->url->link('checkout/success');

to

$data['continue'] = HTTP_SERVER.'confirm.php?order_id='.$this->session->data['order_id'];

Thanks

Edited

So you can write in this way. In catalog\controller\checkout\success.php

after

if (isset($this->session->data['order_id'])) {

Write

$data['order_id'] = $this->session->data['order_id'];

For redirect from common/success page to confirm.php page after 5 sec you have to write following things before

<script><!-- 
$(document).ready(function () { 
      window.setTimeout(function(){ 
     window.location.href ='<?php echo HTTP_SERVER; ?>confirm.php?order_id=<?php echo $order_id; ?>'; }, 5000);
 });
 --></script>



回答2:


I hope this will work for you

Kindly Replace in this file as catalog/controller/extension/payment/cod.php

$data['continue'] = $this->url->link('checkout/success'); 

to

$data['continue'] = HTTP_SERVER.'confirm.php?order_id='.$this->session->data['order_id'];



回答3:


And what if I write a script like this:

for ($order_id = 0; $order_id < 1000000; $order_id++)
{
// Pseudo-code to save the data at this URL:
https://www.myopencartstore.com/confirm.php?order_id=$order_id
}

I now have all your customer info!

So I suggest you do not do this.



来源:https://stackoverflow.com/questions/47321059/get-opencart-order-id-in-cod-payment-module-redirect-link

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!