Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

PayPal Express ~ Duplicate Orders


pete2007

Recommended Posts

We use osCommerce Online Merchant v2.3.4 and PayPal App v5.018

I've had a duplicate order issue for awhile now, and never knew the reason why... but today I tested PayPal express and once I clicked on the 'confirm' button it took ages to load/or do anything, so I assumed it was just slow internet connection or I clicked on it again and eventually it loaded and said order completed. I then received two confirmation emails and two orders were showing in admin.

Does anyone know how I can resolve this problem, and speed up the process once the button has been clicked on?

Thank you in advance.

Link to comment
Share on other sites

@pete2007

You need some javascript/jquery to disable the button once clicked.

In checkout_confirmation.php add this to the bottom of the page.  I've made this based on a default install of v2.4.3.1 and will work providing your store still uses jQuery and jQuery UI

Find:

<script type="text/javascript">
$('#coProgressBar').progressbar({
  value: 100
});
</script>

Add this beneath it (do not replace, just add beneath):

<script>
	$('form[name=checkout_confirmation]').submit(function(){
		var btnLoadingTxt = 'Loading Please Wait';
		var confirmationForm = $(this);
		$(this).find('button[type=submit]').each(function (index) {  
			var btnHtml = $(this).html();
			$(this).clone(false).attr('id', 'disabledBtn').prop('disabled', true).html(btnHtml).insertBefore($(this));
			$('#disabledBtn .ui-button-text').text(btnLoadingTxt);
			$(this).hide();
			confirmationForm.prepend($(this));
		});
	});
</script>

With the above script, once the form is submitted it will copy the styling and text displayed of the original button, clone it and make the cloned button disabled.  It then hides the original submit button and changes the text of the cloned button to "Loading Please Wait".

If it still don't work, hit it again!

Senior PHP Dev with 18+ years of commercial experience for hire, all requirements considered, see profile for more information.

Is your version of osC up to date? You'll find the latest osC version (the community-supported responsive version) here.

Link to comment
Share on other sites

Thank you for your reply.

This sounds exactly what I need but unfortunately I cannot locate this code within my checkout_confirmation.php

<script type="text/javascript">
$('#coProgressBar').progressbar({
  value: 100
});
</script>

 

Link to comment
Share on other sites

Hi,

Sounds like you're not using v2.4.3.1 default install in that case.  Can you post the contents of the bottom half of checkout_confirmation.php I don't need all of it, but if providing all of it is easier then do that.  And/or post a link to your site so I can can make sure jQuery/jQuery UI is being used and where it's loaded in the page (I only need to look at the html source view of the index page in the browser for this).

Alternatively if you're comfortable detecting where jQuery and jQuery UI is loaded yourself, find out if it's being loaded in <head> tags.  If it's loaded in <head> tags then feel free to pasted that code anywhere towards the bottom of checkout_confirmation.php preferably after the closing </form> tag for the checkout confirmation page.

If it still don't work, hit it again!

Senior PHP Dev with 18+ years of commercial experience for hire, all requirements considered, see profile for more information.

Is your version of osC up to date? You'll find the latest osC version (the community-supported responsive version) here.

Link to comment
Share on other sites

Hi @pete2007

Thank you for sending the files in a PM.  I've placed my response here so that if anyone else is in the same situation as you then they can see the solution also.

Your store setup:

  • Doesn't use or load jQuery UI
  • jQuery and javascript is executed from includes/template_bottom.php and not in the <head> tag.
    • Because of this, the script cannot be added directly to checkout_confirmation.php because jQuery loads after the contents of this page.
  • Your site makes good use of a ext/jquery/main.js file instead of inline/on-page Javascript so we'll use this to house the new script.
  • Your store submit button doesn't have any classes applied so no need to copy them to the new dynamic button before hiding the submit button once clicked.

Please backup the ext/jquery/main.js file before making changes and be sure to test the checkout_confirmation.php page after making the changes as I've not been able to test this.  You may also need to clear your temporary internet files/cache if your browser doesn't detect the additional code to the file immediately.

In ext/jquery/main.js

Go to the very bottom of the file after the closing }); and press return twice to create some spacing.

Add the following, save and upload.

/* BOF Prevent multiple form submissions from multiple clicks on checkout_confirmation.php */
if($('form[name=checkout_confirmation]').length > 0){
    $('form[name=checkout_confirmation]').submit(function(){
        var btnLoadingTxt = 'Loading Please Wait';
        var confirmationForm = $(this);
        confirmationForm.find('button[type=submit]').each(function (index) {  
            $(this).clone(false).attr('id', 'disabledBtn').prop('disabled', true).text(btnLoadingTxt).insertBefore($(this));
            $(this).hide();
            confirmationForm.prepend($(this));
        });
    });
}
/* EOF Prevent multiple form submissions from multiple clicks */

Because we can't add this code directly to the checkout_confirmation.php page if left as it was it would attempt to execute on every page load.  It would only work on the checkout_confirmation.php page but there's still no point taking extra resources to attempt to execute when not needed so I've added code to check if the confirmation form is present before execution.

If it still don't work, hit it again!

Senior PHP Dev with 18+ years of commercial experience for hire, all requirements considered, see profile for more information.

Is your version of osC up to date? You'll find the latest osC version (the community-supported responsive version) here.

Link to comment
Share on other sites

@pete2007 you're welcome :)

If it still don't work, hit it again!

Senior PHP Dev with 18+ years of commercial experience for hire, all requirements considered, see profile for more information.

Is your version of osC up to date? You'll find the latest osC version (the community-supported responsive version) here.

Link to comment
Share on other sites

Hi @burt

I'm well aware of it but the request wasn't to create a module and I don't have time to do that for free at the moment either.  Also it would not have worked in the OP's case, jQuery's script src is hardcoded into the OP's template_bottom.php file (sent via PM) and after the output of $oscTemplate->getBlocks('footer_scripts'); which is empty.  So if it had been pulled via footer_scripts it would not have worked and console would have shown the error $ is not defined.

If it still don't work, hit it again!

Senior PHP Dev with 18+ years of commercial experience for hire, all requirements considered, see profile for more information.

Is your version of osC up to date? You'll find the latest osC version (the community-supported responsive version) here.

Link to comment
Share on other sites

OK. 

For anyone looking to do this (and find this thread in the future)...core code changes in this manner are not necessary unless you are on an *ancient* version (2.2 stream, 10 years or more old?) or some version that has been totally shafted already by core code changes.

Edited by burt
Link to comment
Share on other sites

@pete2007 it sure is (but don't tell burt I told you this or he'll get all "Stack Overflow" on me!!).

Again, anyone else reading this, this is method is specific for pete2007's installation which doesn't make use of Header Tags modules nor $oscTemplate->getBlocks('footer_scripts'); and everything is hardcoded in template_bottom.php

In ext/jquery/main.js find:

/* BOF Prevent multiple form submissions from multiple clicks on checkout_confirmation.php */
if($('form[name=checkout_confirmation]').length > 0){
    $('form[name=checkout_confirmation]').submit(function(){

Replace with:

/* BOF Prevent multiple form submissions from multiple clicks on checkout_confirmation.php and contact_us.php */
if($('form[name=checkout_confirmation], form[name=contact_us]').length > 0){
    $('form[name=checkout_confirmation], form[name=contact_us]').submit(function(){

And then just for the sake of completeness find:

/* EOF Prevent multiple form submissions from multiple clicks */

And replace with:

/* EOF Prevent multiple form submissions from multiple clicks on checkout_confirmation.php and contact_us.php */

The only caveat is that it will only display one message i.e. "Loading please wait", might have been nicer to have "Sending please wait" for the contact form.  But if you want you could change it to just "Please wait" which would apply equally to both forms nicely.

If it still don't work, hit it again!

Senior PHP Dev with 18+ years of commercial experience for hire, all requirements considered, see profile for more information.

Is your version of osC up to date? You'll find the latest osC version (the community-supported responsive version) here.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...