Zen Cart Logo
Forums / General Questions / Frequent Duplicate Orders - Cart Not Emptying

Frequent Duplicate Orders - Cart Not Emptying

Views: 421

Results 1 to 17 of 17
23 Jul 2026, 3:59 PM
#1
bumba000 avatar

bumba000

Totally Zenned

Join Date:
Feb 2007
Location:
Pennsylvania
Posts:
858
Plugin Contributions:
0

Frequent Duplicate Orders - Cart Not Emptying

Hello All,
Running ZC 2.2.2, PHP 8.2, Modified Responsive Classic Clone and Authorize (AIM) no other payment methods.

We just upgraded from ZC 1.5.8 and made the new site live on 7/5. Included in the upgrade is the One Page Checkout. Until yesterday OPC 2.6.2, now OPC 2.6.3.

On 7/9 we began using SendGrid email service.

What's happening... It seems that whether or not a customer registers an account or uses guest checkout, every couple of orders or at least once per day a customer checks out, but their cart is not emptied, the checkout confirmation page may stall (I'm not sure this always happens), but the resubmit / reload and end up with two orders. When this happens the transaction details are not added to the order and they still have the item in their cart.

There are no server error logs linked to their ip, however there are zc logs that point to functions_email.php.

[23-Jul-2026 11:15:31 America/New_York] Request URI: /index.php?main_page=checkout_process, IP address: 111.222.333.444
--> PHP Fatal error: Maximum execution time of 30 seconds exceeded in /home/hostname111/www.site .com/includes/functions/functions_email.php on line 191.

I have tried reverting back to using our own server email rather than sendgrid, I've also tried disabling OPC. This still happens and I'm really not sure how to track down the problem.

Any help here would be greatly appreciated.

Thank you,
John

23 Jul 2026, 5:07 PM
#2
swguy avatar

swguy

Administrator

Join Date:
Feb 2006
Location:
Tampa Bay, Florida
Posts:
10,718
Plugin Contributions:
56

Re: Frequent Duplicate Orders - Cart Not Emptying

Go to Admin > Customers > Customers, select your own account and click the Email button on the right. This will verify that sending email from your cart works.

That Software Guy. My Store: Zen Cart Support
Available for hire - See my ad in Services
Plugin Moderator, Documentation Curator, Chief Cook and Bottle-Washer.
Do you benefit from Zen Cart? Then please support the project.

23 Jul 2026, 5:12 PM
#3
bumba000 avatar

bumba000

Totally Zenned

Join Date:
Feb 2007
Location:
Pennsylvania
Posts:
858
Plugin Contributions:
0

Re: Frequent Duplicate Orders - Cart Not Emptying

swguy:

Go to Admin > Customers > Customers, select your own account and clic...

Hi Scott,
Email has been tested again and again. It's working fine. Works fine with sendgrid and with our own server's email. Sending from admin, contact us, ask a question, new account, order confirmation... they all send email just fine.

The only time there's ever a problem is during checkout and it's not every time.

Not sure if it'd matter at all, but we're also on a VPS using CWP rather than Cpanel. Same as prior to the upgrade from 1.5.8 to 2.2.2. Nothing about our environment has change.

Thank you,
John

23 Jul 2026, 6:14 PM
#4
bumba000 avatar

bumba000

Totally Zenned

Join Date:
Feb 2007
Location:
Pennsylvania
Posts:
858
Plugin Contributions:
0

Re: Frequent Duplicate Orders - Cart Not Emptying

I was looking through modules/checkout_process.php just to get an idea of the order of things. Looks like sending the email is basically the last thing that happens once an order completes. I still don't understand though why the auth id and transaction number isn't recorded. So I had disabled OPC and had reverted back to sending our own emails. But the more I think about it the more I come back to ... it's a problem with email. The only thing new about email is sendgrid.

So for the time being I'm leaving sendgrid off and have re-enabled OPC. We'll see how it plays out.

Thanks,
John

24 Jul 2026, 11:00 AM
#5
brittainmark avatar

brittainmark

Totally Zenned

Join Date:
Apr 2009
Posts:
508
Plugin Contributions:
1

Re: Frequent Duplicate Orders - Cart Not Emptying

I was having similar problems with opc with one of my clients. I added session_Id to the orders table, modified the orders class to record the info and modules\checkout processing to catch the duplicates. I also had to alter the papal processing . Since then we still get duplicates but all are caught. This replaced a previous effort that check if the order value and items were the same.
I thought about adding a feature request but I think it would need changes to other payment methods to so have not pushed it forward.

-- Run this SQL first
ALTER TABLE orders
  ADD COLUMN session_id VARCHAR(64) NOT NULL AFTER customers_id;

UPDATE orders
SET session_id = CONCAT('legacy_', orders_id)
WHERE session_id = '';

ALTER TABLE orders
  ADD UNIQUE KEY uniq_customer_session (customers_id, session_id);

includes/classes/order.php

    /*
     * Session id to avoid duplicate orders
     */
    public $session_id;

add to function __construct

    $this->session_id = zen_session_id();

Add to end of $sql_data_array (about line 970-1025)

 'session_id' => $this->session_id,

add to /includes/modules/YOURTEMPLATE/checkout_process.php

//  [Prevent duplicate orders per customer/session
    $check = $db->Execute("SELECT orders_id 
                           FROM " . TABLE_ORDERS . "
                           WHERE customers_id = '" . (int)$_SESSION['customer_id'] . "'
                           AND session_id = '" . zen_db_input(zen_session_id()) . "'
                           LIMIT 1");

    $duplicate = !$check->EOF;

You will need to decide what to do. We wrote out to a file and redirected to checkout sucessful.

You may also need to check for duplictes inside your payment method and reset the session if necessary. (This was necessary for paypal I changed ipn_main_handler.php )

I know this does not fix the issue that is causing duplicate transactions but it means that it is no longer an issue for the customer/client

Mark Brittain
http:\innerlightcrystals.co.uk\sales\

24 Jul 2026, 12:30 PM
#6
bumba000 avatar

bumba000

Totally Zenned

Join Date:
Feb 2007
Location:
Pennsylvania
Posts:
858
Plugin Contributions:
0

Re: Frequent Duplicate Orders - Cart Not Emptying

brittainmark:

I was having similar problems with opc with one of my clients. I added session_Id to the orders table,....

Hey Mark,
Thanks for the response! I've seen in the OPC thread that some folks had an issue when using paypal. Was that the only payment method your client was having this issue with? We don't even have pp installed, we use Auth (aim) only. Do you happen to recall what you were seeing in zen logs?

We've only had a couple of sales since reverting back to sending our own emails yesterday, but (fingers crossed) we haven't had this problem again.. yet.

When this happens to us our logs all indicate a timeout on the zen mail function. I was thinking that if somehow the mailer is hanging up, why not move the send order confirmation mail from the order process to the checkout success page?

... just spitballin'..

Thanks again,
John

24 Jul 2026, 3:30 PM
#7
brittainmark avatar

brittainmark

Totally Zenned

Join Date:
Apr 2009
Posts:
508
Plugin Contributions:
1

Re: Frequent Duplicate Orders - Cart Not Emptying

No the issue also occurred with all payment methods. They also used opayo, and direct bank payments. There is probably a better way to write the changes to avoid core changes.
No there were no logs created in zen cart.

Mark Brittain
http:\innerlightcrystals.co.uk\sales\

24 Jul 2026, 4:28 PM
#8
swguy avatar

swguy

Administrator

Join Date:
Feb 2006
Location:
Tampa Bay, Florida
Posts:
10,718
Plugin Contributions:
56

Re: Frequent Duplicate Orders - Cart Not Emptying

Do you support foreign currencies? If not, try going to Admin > Configuration > Email and setting "Convert currencies for Text emails" to an empty string.

That Software Guy. My Store: Zen Cart Support
Available for hire - See my ad in Services
Plugin Moderator, Documentation Curator, Chief Cook and Bottle-Washer.
Do you benefit from Zen Cart? Then please support the project.

26 Jul 2026, 1:06 PM
#9
bumba000 avatar

bumba000

Totally Zenned

Join Date:
Feb 2007
Location:
Pennsylvania
Posts:
858
Plugin Contributions:
0

Re: Frequent Duplicate Orders - Cart Not Emptying

Hey Scott,
We do not. English and dollar bills. We're normally pretty slow over the weekend, but since reverting our email away from sendgrid we've had 6 sales and zero problems. Activity should kick up this evening and be pretty good through the middle of the week. I'll let you know if the issue shows up again.

Thank you,
John

3 Aug 2026, 12:31 AM
#10
bumba000 avatar

bumba000

Totally Zenned

Join Date:
Feb 2007
Location:
Pennsylvania
Posts:
858
Plugin Contributions:
0

Re: Frequent Duplicate Orders - Cart Not Emptying

moved to end of thread

3 Aug 2026, 12:33 AM
#11
bumba000 avatar

bumba000

Totally Zenned

Join Date:
Feb 2007
Location:
Pennsylvania
Posts:
858
Plugin Contributions:
0

Re: Frequent Duplicate Orders - Cart Not Emptying

I am happy to announce that I've found the problem. I confirmed with grok and then ran a test. So now it's double confirmed. Here's the scenario...
Admin > Configure > Email: Convert currencies for Text emails. The setting example and what comes standard in the cart is something like this: Example = £,£:€,€. But once you save any setting on that page and the page reloads, zen is using a function like zen_output_string to display the values of CURRENCIES_TRANSLATIONS in the form field which then looks like this. £,£:€,€:®,®:™,™ Not a problem as long as you don't save that page again without changing this back to ```
Example = £,£:€,€


So then you get a guy like me who decides to use the ® mark in some product names.... guess what... That's a problem when you have a block like this in the includes/functions/functions_email.php that gets stuck in a infinite while loop while trying to send an order confirmation email to a customer purchasing that product.

```php
            // clean up currencies for text emails
            if (defined('CURRENCIES_TRANSLATIONS') && !empty(CURRENCIES_TRANSLATIONS)) {
                $zen_fix_currencies = preg_split("/[:,]/", str_replace(' ', '', CURRENCIES_TRANSLATIONS));
                $size = count($zen_fix_currencies);
                for ($i = 0, $n = $size; $i < $n; $i += 2) {
                    if (empty($zen_fix_currencies[$i + 1])) {
                        break;
                    }
                    $zen_fix_current = $zen_fix_currencies[$i];
                    $zen_fix_replace = $zen_fix_currencies[$i + 1];
                    if (strlen($zen_fix_current) !== 0) {
                        while (strpos($email_text, $zen_fix_current)) {
                            $email_text = str_replace($zen_fix_current, $zen_fix_replace, $email_text);
                        }
                    }
                }
            }

I added the following and ran a test transaction

           // clean up currencies for text emails
            if (defined('CURRENCIES_TRANSLATIONS') && !empty(CURRENCIES_TRANSLATIONS)) {
                error_log('CURRENCIES_TRANSLATIONS active. Email text length: ' . strlen($email_text));
                error_log('Contains £? ' . (strpos($email_text, '£') !== false ? 'YES' : 'no'));
                error_log('Contains €? ' . (strpos($email_text, '€') !== false ? 'YES' : 'no'));
                error_log('Contains ®? ' . (strpos($email_text, '®') !== false ? 'YES' : 'no'));
                error_log('Contains ™? ' . (strpos($email_text, '™') !== false ? 'YES' : 'no'));
                $zen_fix_currencies = preg_split("/[:,]/", str_replace(' ', '', CURRENCIES_TRANSLATIONS));
                $size = count($zen_fix_currencies);
                for ($i = 0, $n = $size; $i < $n; $i += 2) {
                    if (empty($zen_fix_currencies[$i + 1])) {
                        break;
                    }
                    $zen_fix_current = $zen_fix_currencies[$i];
                    $zen_fix_replace = $zen_fix_currencies[$i + 1];
                    if (strlen($zen_fix_current) !== 0) {
                        while (strpos($email_text, $zen_fix_current)) {
                            $email_text = str_replace($zen_fix_current, $zen_fix_replace, $email_text);
                        }
                    }
                }
            }

and the error logs reported the following

[03-Aug-2026 00:08:02 UTC] CURRENCIES_TRANSLATIONS active. Email text length: 1508
[03-Aug-2026 00:08:02 UTC] Contains £? no
[03-Aug-2026 00:08:02 UTC] Contains €? no
[03-Aug-2026 00:08:02 UTC] Contains ®? YES
[03-Aug-2026 00:08:02 UTC] Contains ™? no

So. I've deleted those values from the CURRENCIES_TRANSLATIONS field and also replaced that while loop with a simple str_replace.

Thank you,
John

3 Aug 2026, 12:35 AM
#12
bumba000 avatar

bumba000

Totally Zenned

Join Date:
Feb 2007
Location:
Pennsylvania
Posts:
858
Plugin Contributions:
0

Re: Frequent Duplicate Orders - Cart Not Emptying

Holy smokes posting a reply to my own post sure got messy. lol here we go.

Sorry. I got carried away and must have hit submit instead of preview post... lol

Please let me know if you think this will do a better job.

            if (defined('CURRENCIES_TRANSLATIONS') && !empty(CURRENCIES_TRANSLATIONS)) {
                $zen_replace_currencies = preg_split("/[:,]/", str_replace(' ', '', CURRENCIES_TRANSLATIONS));
                $size = count($zen_replace_currencies);
                for ($i = 0, $n = $size; $i < $n; $i += 2) {
                    if (empty($zen_replace_currencies[$i + 1])) {
                        break;
                    }
                    $zen_replace_current = $zen_replace_currencies[$i];
                    $zen_replace_replace = $zen_replace_currencies[$i + 1];
                    if (strlen($zen_replace_current) !== 0) {
                        // Safe single pass (no infinite loop possible)
                        $email_text = str_replace($zen_replace_current, $zen_replace_replace, $email_text);
                    }
                }
            }
3 Aug 2026, 12:43 AM
#13
bumba000 avatar

bumba000

Totally Zenned

Join Date:
Feb 2007
Location:
Pennsylvania
Posts:
858
Plugin Contributions:
0

Re: Frequent Duplicate Orders - Cart Not Emptying

swguy:

Do you support foreign currencies? If not, try going to Admin > Configuration > Email and setting "Convert currencies for Text emails" to an empty string.

Hey Scott,
Sorry dude. I honestly didn't see anything after "Do you support foreign currencies". I literally read that far and answered no we don't. But that wasn't the whole problem. After that factory value in there is save and loaded and again and saved again and also have a reg mark in the product name, it caused a huge problem. Because it was set ```
£,£:€,€:®,®:™,™


I wish I had finished reading and gone and made that change. 

Thank you,
John
3 Aug 2026, 10:47 PM
#14
swguy avatar

swguy

Administrator

Join Date:
Feb 2006
Location:
Tampa Bay, Florida
Posts:
10,718
Plugin Contributions:
56

Re: Frequent Duplicate Orders - Cart Not Emptying

It's all good - you really narrowed it down nicely; my fix was more of a sledgehammer patch because I was too lazy to chase it any further.

I will forgive you if you submit a PR. :)

That Software Guy. My Store: Zen Cart Support
Available for hire - See my ad in Services
Plugin Moderator, Documentation Curator, Chief Cook and Bottle-Washer.
Do you benefit from Zen Cart? Then please support the project.

3 Aug 2026, 11:43 PM
#15
bumba000 avatar

bumba000

Totally Zenned

Join Date:
Feb 2007
Location:
Pennsylvania
Posts:
858
Plugin Contributions:
0

Re: Frequent Duplicate Orders - Cart Not Emptying

swguy:

It's all good - you really narrowed it down nicely; my fix was more of a sledgehammer patch because I was too lazy to chase it any further.

I will forgive you if you submit a PR. :)

Hey Scott,
Just did a lot of typing over there at github, thankfully I saved to notepad prior to clicking submit. lol Won't let me PR since I'm not a collaborator. Here ya go if you'd like to copy and paste.

In the admin > configure > email; after saving changes to the page (any changes) the values stored in CURRENCIES_TRANSLATIONS become actual entities rather than HTML entity code. So what's stored in the database looks like `£,£:€,€` rather than the intended goal of  `£,£:€,€`. This isn't only a problem for this field, but it's the only one which creates an infinite loop during checkout confirmation.

In includes/functions/functions_email.php around line 191 
`// clean up currencies for text emails
if (defined('CURRENCIES_TRANSLATIONS') && !empty(CURRENCIES_TRANSLATIONS)) {
        $zen_fix_currencies = preg_split("/[:,]/", str_replace(' ', '', CURRENCIES_TRANSLATIONS));
        $size = count($zen_fix_currencies);
        for ($i = 0, $n = $size; $i < $n; $i += 2) {
            if (empty($zen_fix_currencies[$i + 1])) {
                break;
            }
            $zen_fix_current = $zen_fix_currencies[$i];
            $zen_fix_replace = $zen_fix_currencies[$i + 1];
            if (strlen($zen_fix_current) !== 0) {
                while (strpos($email_text, $zen_fix_current)) {
                    $email_text = str_replace($zen_fix_current, $zen_fix_replace, $email_text);
                }
            }
        }
    }
`

If any of the CURRENCIES_TRANSLATIONS values appear in the email this while loop is never ending.

Proposed solution is basically to replace the while with a str_replace

`if (defined('CURRENCIES_TRANSLATIONS') && !empty(CURRENCIES_TRANSLATIONS)) {
    $zen_replace_currencies = preg_split("/[:,]/", str_replace(' ', '', CURRENCIES_TRANSLATIONS));
    $size = count($zen_replace_currencies);
    for ($i = 0, $n = $size; $i < $n; $i += 2) {
        if (empty($zen_replace_currencies[$i + 1])) {
            break;
        }
        $zen_replace_current = $zen_replace_currencies[$i];
        $zen_replace_replace = $zen_replace_currencies[$i + 1];
        if (strlen($zen_replace_current) !== 0) {
            // Safe single pass (no infinite loop possible)
            $email_text = str_replace($zen_replace_current, $zen_replace_replace, $email_text);
        }
    }
}
`
I also feel that the data being displayed in the admin > configure... form fields should be done in a way that doesn't convert html entity code into entities which happens in many other fields in configure areas other than email.

Sorry if I'm doing this pull request wrong, it's my first.

Thank you,
John (Bumba000 @ ZC)
4 Aug 2026, 9:56 AM
#16
lat9 avatar

lat9

Administrator

Join Date:
Sep 2009
Location:
Stuart, FL
Posts:
14,108
Plugin Contributions:
56

Re: Frequent Duplicate Orders - Cart Not Emptying

Noting that this has been corrected for the forthcoming Zen Cart 2.3.0; see this PR's change list: https://github.com/zencart/zencart/pull/7793/changes

9 Aug 2026, 4:19 PM
#17
brittainmark avatar

brittainmark

Totally Zenned

Join Date:
Apr 2009
Posts:
508
Plugin Contributions:
1

Re: Frequent Duplicate Orders - Cart Not Emptying

I have raised a PR#7950 as although the cause was fixed if the user were to put in the same value for search and replace the infinite loop issue remained.
Change was made to email.php class. This fixes it for 3.0.0 not 2.3.

Mark Brittain
http:\innerlightcrystals.co.uk\sales\