Post by zo0ol » Sun Dec 06, 2020 1:30 am

I want to add a confirmation when choosing a payment method Cash On Delivery





You have edited a file

catalog/view/theme/default/template/extension/payment/cod.twig

Code: Select all



<input type="checkbox" id="confirm" class="confirm">
{{ text_checkbox }}
 

<div class="buttons">
  <div class="pull-right">
    <input type="button" value="{{ button_confirm }}" id="button-confirm" data-loading-text="{{ text_loading }}" class="btn btn-primary" />
  </div>
</div>
<script type="text/javascript"><!--

$('#button-confirm').on('click', function() {
    if (!$('#confirm').is(':checked')) {
        alert('not checked');
        return false;
    }

	$.ajax({
		url: 'index.php?route=extension/payment/cod/confirm',
		dataType: 'json',
		beforeSend: function() {
			$('#button-confirm').button('loading');
		},
		complete: function() {
			$('#button-confirm').button('reset');
		},
		success: function(json) {
			if (json['redirect']) {
				location = json['redirect'];	
			}
		},
		error: function(xhr, ajaxOptions, thrownError) {
			alert(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText);
		}
	});
});


//--></script>
The code I have tried it works but there is a problem

If the option is not selected, an error message appears (not checked)

Then code is suspended ( button_confirm)

Remains (loading)

Can you help?

opencart 3.0.2
Theme : journal3
Last edited by zo0ol on Mon Dec 07, 2020 9:13 pm, edited 1 time in total.

Newbie

Posts

Joined
Sat Feb 02, 2019 7:28 pm

Post by sw!tch » Sun Dec 06, 2020 3:26 am

Check your error logs.

You should really do validation like this from the controller and then handle the json response client side.

Backup and learn how to recover before you make any changes!


Active Member

Posts

Joined
Sat Apr 28, 2012 2:32 pm

Post by thekrotek » Sun Dec 06, 2020 4:16 am

Use JS confirm() function instead, this is much better.

Professional OpenCart extensions, support and custom work.
Contact me via email or Skype by support@thekrotek.com


User avatar
Expert Member

Posts

Joined
Sun Jul 03, 2016 12:24 am


Post by zo0ol » Sun Dec 06, 2020 4:23 pm

sw!tch wrote:
Sun Dec 06, 2020 3:26 am
Check your error logs.

You should really do validation like this from the controller and then handle the json response client side.
No errors appear in the file error logs

thekrotek wrote:
Sun Dec 06, 2020 4:16 am
Use JS confirm() function instead, this is much better.
How is that done with thanks

Newbie

Posts

Joined
Sat Feb 02, 2019 7:28 pm

Post by sw!tch » Sun Dec 06, 2020 6:06 pm

zo0ol wrote:
Sun Dec 06, 2020 4:23 pm
sw!tch wrote:
Sun Dec 06, 2020 3:26 am
Check your error logs.

You should really do validation like this from the controller and then handle the json response client side.
No errors appear in the file error logs
You must have some other error if the loading is hanging. Check your console & Server error logs.

zo0ol wrote:
Sun Dec 06, 2020 4:23 pm
thekrotek wrote:
Sun Dec 06, 2020 4:16 am
Use JS confirm() function instead, this is much better.
How is that done with thanks
https://www.w3schools.com/jsref/met_win_confirm.asp

-

Backup and learn how to recover before you make any changes!


Active Member

Posts

Joined
Sat Apr 28, 2012 2:32 pm

Post by zo0ol » Sun Dec 06, 2020 6:39 pm

sw!tch wrote:
Sun Dec 06, 2020 6:06 pm
zo0ol wrote:
Sun Dec 06, 2020 4:23 pm
sw!tch wrote:
Sun Dec 06, 2020 3:26 am
Check your error logs.

You should really do validation like this from the controller and then handle the json response client side.
No errors appear in the file error logs
You must have some other error if the loading is hanging. Check your console & Server error logs.

zo0ol wrote:
Sun Dec 06, 2020 4:23 pm
thekrotek wrote:
Sun Dec 06, 2020 4:16 am
Use JS confirm() function instead, this is much better.
How is that done with thanks
https://www.w3schools.com/jsref/met_win_confirm.asp

-
Could you clarify
Tried but failed

This video is to explain the code I used

https://youtu.be/cedZRX5cAIw

Newbie

Posts

Joined
Sat Feb 02, 2019 7:28 pm

Post by sw!tch » Mon Dec 07, 2020 2:32 am

That is a onepage checkout contact the extension developer or post in the commercial section.

Backup and learn how to recover before you make any changes!


Active Member

Posts

Joined
Sat Apr 28, 2012 2:32 pm

Post by zo0ol » Mon Dec 07, 2020 2:54 pm

sw!tch wrote:
Mon Dec 07, 2020 2:32 am
That is a onepage checkout contact the extension developer or post in the commercial section.
Thank you
Not a private checkout page
But the method of payment - Cash On Delivery

I modified the code, but there is only one problem, which is a comment button_confirm

Newbie

Posts

Joined
Sat Feb 02, 2019 7:28 pm

Post by sw!tch » Mon Dec 07, 2020 4:01 pm

Doesn't matter, the issue is you are using a modified checkout. If it's a commercial extension you need to reach out to the developer for support or otherwise hire a professional.

Support here is typically for default opencart functionality.

Switch to the default checkout and you shouldn't have any issue.

Backup and learn how to recover before you make any changes!


Active Member

Posts

Joined
Sat Apr 28, 2012 2:32 pm
Who is online

Users browsing this forum: No registered users and 12 guests