Post by Qphoria » Tue Jan 05, 2010 4:33 am

UPDATE: NEW DYNAMIC VERSION!! SHOULD SUPPORT 1.4.7 through 3.0 and should theoretically support later versions with no need for update (Attached)

Many people have commented about their distaste for the way OpenCart generates a new order id each time the checkout/confirm page is reloaded.

This is a very simple modification to force the cart to reuse the same order id once it has been set at the session level. This means, that if a customer gets to the confirm page and his order id is 101, if he goes back and buys more and returns to the confirm page, it will still be order id 101.

This will cut down on the thousands of "no status" orders that get generated for a single person who can't make up his mind.

INCLUDES FIX FOR ORDER STATUS CHECK TO RESOLVE POTENTIAL FOR CUSTOMER CLICKING BACK ALL THE WAY AFTER PAYMENT

Supports 1.4.7 through 3.0
You must install vQmod to use it

NEW Dynamic Version - PLEASE TEST - Works with all current versions 1.4.x, 1.5.x, 2.x, 3.0. Should be more compatible with custom mods that add new fields to the order record. Should also be more future proof with future opencart updates.

Attachments

Dynamic Version - Tested up to 3.0


Image


User avatar
Administrator

Posts

Joined
Tue Jul 22, 2008 3:02 am

Post by richard211986 » Fri Mar 26, 2010 5:41 am

Q, this mod if a customer places an item in the basket registers and clicks confirm order this obviously creates a missing order if they then go off site or press the back button another order is created.........does this mod stop that and only use 1 order number for the repeat same order session as such? ive got alot of invoices which ive just had to move to cancelled =/

Active Member

Posts

Joined
Sun Sep 20, 2009 5:34 am

Post by Qphoria » Fri Mar 26, 2010 5:42 am

Yes.. if a customer goes to your site. When they get to the confirm page an order id is generated. If they hit refresh, another order id is generated, and so on.

With my mod, it stops this. It keeps the same order_id that was generated on the first load and prevents the constant regeneration of a new number while that customer session is logged in.

Image


User avatar
Administrator

Posts

Joined
Tue Jul 22, 2008 3:02 am

Post by Daniel » Fri Mar 26, 2010 6:01 am

I'm sure the problem with this is that if paypal callback cannot get through and a customer click back instead of returning to the store the order with be overwritten.

OpenCart®
Project Owner & Developer.


User avatar
Administrator

Posts

Joined
Fri Nov 03, 2006 6:57 pm

Post by Qphoria » Mon Mar 29, 2010 3:32 am

No, A session doesn't change just because they click back vs click "Return". It would still be the same session id. If you are describing the rare situation where the callback didn't go through AND the customer clicked back 4 times, then it would be no different if a new temp order was created. You'd still end up with an uncleared cart and no finalized order state. Doesn't matter if the number is the same or different. I've been using this mod on my store since 1.3.0 and have never had a problem.

Image


User avatar
Administrator

Posts

Joined
Tue Jul 22, 2008 3:02 am

Post by Qphoria » Wed Mar 31, 2010 8:11 am

The Alchemist wrote:The goal is to get them to come back and complete the order

If installing this mod would still keep their orders accurate in their accounts.
Yes, that is still the goal. This does not change that. It just cuts down on the multiple temp orders per customer. orders ids are not reused across different people. Once it is used, its used.. and the order id that is first generated for that customer session will remain his for that session. If he ends up leaving then you only have 1 dead order instead of multiple. If he comes back 3 hours later and has to re-login, then that session is over and he will get a new number, but only one number.

(Added version for v1.3.2)
1. EDIT: catalog/model/checkout/order.php
2. FIND (around line 21 & 23):

Code: Select all

$this->db->query("INSERT INTO `" . DB_PREFIX . "order` SET customer_id = '" . (int)$data['customer_id'] . "', firstname = '" . $this->db->escape($data['firstname']) . "', lastname = '" . $this->db->escape($data['lastname']) . "', email = '" . $this->db->escape($data['email']) . "', telephone = '" . $this->db->escape($data['telephone']) . "', fax = '" . $this->db->escape($data['fax']) . "', total = '" . (float)$data['total'] . "', language_id = '" . (int)$data['language_id'] . "', currency = '" . $this->db->escape($data['currency']) . "', currency_id = '" . (int)$data['currency_id'] . "', value = '" . (float)$data['value'] . "', coupon_id = '" . (int)$data['coupon_id'] . "', ip = '" . $this->db->escape($data['ip']) . "', shipping_firstname = '" . $this->db->escape($data['shipping_firstname']) . "', shipping_lastname = '" . $this->db->escape($data['shipping_lastname']) . "', shipping_company = '" . $this->db->escape($data['shipping_company']) . "', shipping_address_1 = '" . $this->db->escape($data['shipping_address_1']) . "', shipping_address_2 = '" . $this->db->escape($data['shipping_address_2']) . "', shipping_city = '" . $this->db->escape($data['shipping_city']) . "', shipping_postcode = '" . $this->db->escape($data['shipping_postcode']) . "', shipping_zone = '" . $this->db->escape($data['shipping_zone']) . "', shipping_country = '" . $this->db->escape($data['shipping_country']) . "', shipping_address_format = '" . $this->db->escape($data['shipping_address_format']) . "', shipping_method = '" . $this->db->escape($data['shipping_method']) . "', payment_firstname = '" . $this->db->escape($data['payment_firstname']) . "', payment_lastname = '" . $this->db->escape($data['payment_lastname']) . "', payment_company = '" . $this->db->escape($data['payment_company']) . "', payment_address_1 = '" . $this->db->escape($data['payment_address_1']) . "', payment_address_2 = '" . $this->db->escape($data['payment_address_2']) . "', payment_city = '" . $this->db->escape($data['payment_city']) . "', payment_postcode = '" . $this->db->escape($data['payment_postcode']) . "', payment_zone = '" . $this->db->escape($data['payment_zone']) . "', payment_country = '" . $this->db->escape($data['payment_country']) . "', payment_address_format = '" . $this->db->escape($data['payment_address_format']) . "', payment_method = '" . $this->db->escape($data['payment_method']) . "', comment = '" . $this->db->escape($data['comment']) . "', date_modified = NOW(), date_added = NOW()");

		$order_id = $this->db->getLastId();
REPLACE WITH:

Code: Select all

//Q: Prevent generating new temp order each time confirmation page loads.
		if (!isset($this->session->data['order_id'])) {
			$this->db->query("INSERT INTO `" . DB_PREFIX . "order` SET customer_id = '" . (int)$data['customer_id'] . "', firstname = '" . $this->db->escape($data['firstname']) . "', lastname = '" . $this->db->escape($data['lastname']) . "', email = '" . $this->db->escape($data['email']) . "', telephone = '" . $this->db->escape($data['telephone']) . "', fax = '" . $this->db->escape($data['fax']) . "', total = '" . (float)$data['total'] . "', language_id = '" . (int)$data['language_id'] . "', currency = '" . $this->db->escape($data['currency']) . "', currency_id = '" . (int)$data['currency_id'] . "', value = '" . (float)$data['value'] . "', coupon_id = '" . (int)$data['coupon_id'] . "', ip = '" . $this->db->escape($data['ip']) . "', shipping_firstname = '" . $this->db->escape($data['shipping_firstname']) . "', shipping_lastname = '" . $this->db->escape($data['shipping_lastname']) . "', shipping_company = '" . $this->db->escape($data['shipping_company']) . "', shipping_address_1 = '" . $this->db->escape($data['shipping_address_1']) . "', shipping_address_2 = '" . $this->db->escape($data['shipping_address_2']) . "', shipping_city = '" . $this->db->escape($data['shipping_city']) . "', shipping_postcode = '" . $this->db->escape($data['shipping_postcode']) . "', shipping_zone = '" . $this->db->escape($data['shipping_zone']) . "', shipping_country = '" . $this->db->escape($data['shipping_country']) . "', shipping_address_format = '" . $this->db->escape($data['shipping_address_format']) . "', shipping_method = '" . $this->db->escape($data['shipping_method']) . "', payment_firstname = '" . $this->db->escape($data['payment_firstname']) . "', payment_lastname = '" . $this->db->escape($data['payment_lastname']) . "', payment_company = '" . $this->db->escape($data['payment_company']) . "', payment_address_1 = '" . $this->db->escape($data['payment_address_1']) . "', payment_address_2 = '" . $this->db->escape($data['payment_address_2']) . "', payment_city = '" . $this->db->escape($data['payment_city']) . "', payment_postcode = '" . $this->db->escape($data['payment_postcode']) . "', payment_zone = '" . $this->db->escape($data['payment_zone']) . "', payment_country = '" . $this->db->escape($data['payment_country']) . "', payment_address_format = '" . $this->db->escape($data['payment_address_format']) . "', payment_method = '" . $this->db->escape($data['payment_method']) . "', comment = '" . $this->db->escape($data['comment']) . "', date_modified = NOW(), date_added = NOW()");
			$order_id = $this->db->getLastId();
		} else {
			$order_id = $this->session->data['order_id'];
			$this->db->query("UPDATE `" . DB_PREFIX . "order` SET customer_id = '" . (int)$data['customer_id'] . "', firstname = '" . $this->db->escape($data['firstname']) . "', lastname = '" . $this->db->escape($data['lastname']) . "', email = '" . $this->db->escape($data['email']) . "', telephone = '" . $this->db->escape($data['telephone']) . "', fax = '" . $this->db->escape($data['fax']) . "', total = '" . (float)$data['total'] . "', language_id = '" . (int)$data['language_id'] . "', currency = '" . $this->db->escape($data['currency']) . "', currency_id = '" . (int)$data['currency_id'] . "', value = '" . (float)$data['value'] . "', coupon_id = '" . (int)$data['coupon_id'] . "', ip = '" . $this->db->escape($data['ip']) . "', shipping_firstname = '" . $this->db->escape($data['shipping_firstname']) . "', shipping_lastname = '" . $this->db->escape($data['shipping_lastname']) . "', shipping_company = '" . $this->db->escape($data['shipping_company']) . "', shipping_address_1 = '" . $this->db->escape($data['shipping_address_1']) . "', shipping_address_2 = '" . $this->db->escape($data['shipping_address_2']) . "', shipping_city = '" . $this->db->escape($data['shipping_city']) . "', shipping_postcode = '" . $this->db->escape($data['shipping_postcode']) . "', shipping_zone = '" . $this->db->escape($data['shipping_zone']) . "', shipping_country = '" . $this->db->escape($data['shipping_country']) . "', shipping_address_format = '" . $this->db->escape($data['shipping_address_format']) . "', shipping_method = '" . $this->db->escape($data['shipping_method']) . "', payment_firstname = '" . $this->db->escape($data['payment_firstname']) . "', payment_lastname = '" . $this->db->escape($data['payment_lastname']) . "', payment_company = '" . $this->db->escape($data['payment_company']) . "', payment_address_1 = '" . $this->db->escape($data['payment_address_1']) . "', payment_address_2 = '" . $this->db->escape($data['payment_address_2']) . "', payment_city = '" . $this->db->escape($data['payment_city']) . "', payment_postcode = '" . $this->db->escape($data['payment_postcode']) . "', payment_zone = '" . $this->db->escape($data['payment_zone']) . "', payment_country = '" . $this->db->escape($data['payment_country']) . "', payment_address_format = '" . $this->db->escape($data['payment_address_format']) . "', payment_method = '" . $this->db->escape($data['payment_method']) . "', comment = '" . $this->db->escape($data['comment']) . "', date_modified = NOW(), date_added = NOW() WHERE order_id = '" . (int)$order_id . "'");
			$this->db->query("DELETE FROM " . DB_PREFIX . "order_product WHERE order_id = '" . (int)$order_id . "'");
			$this->db->query("DELETE FROM " . DB_PREFIX . "order_option WHERE order_id = '" . (int)$order_id . "'");
			$this->db->query("DELETE FROM " . DB_PREFIX . "order_download WHERE order_id = '" . (int)$order_id . "'");
			$this->db->query("DELETE FROM " . DB_PREFIX . "order_total WHERE order_id = '" . (int)$order_id . "'");
		}//->db->query("DELETE FROM " . DB_PREFIX . "order_total WHERE order_id = '" . (int)$order_id . "'");
         }//

Image


User avatar
Administrator

Posts

Joined
Tue Jul 22, 2008 3:02 am

Post by richard211986 » Wed Mar 31, 2010 4:40 pm

Hi Q,

Ive tried the above code and still get an error when i click on payment type then continue here is the error

Parse error: syntax error, unexpected T_FOREACH, expecting T_FUNCTION in /home/www/thegadgetshack.co.uk/catalog/model/checkout/order.php on line 36

do you think its because i have renamed to payment modules as such without changing the name in all files?

regards
Richard

Active Member

Posts

Joined
Sun Sep 20, 2009 5:34 am

Post by jefrey1983 » Sun Apr 25, 2010 8:09 pm

question it create a session then it will create an order ID for a customer what if i didn't order i decided not to but will it still create the order id

User avatar
Active Member

Posts

Joined
Sat Jan 30, 2010 6:58 pm

Post by Qphoria » Mon Apr 26, 2010 4:35 am

Yes. The temp order will still be created once.. even if they don't check out, they will still have the single order. It just won't create it 10 times if the same customer reloads the confirm page 10 times

Image


User avatar
Administrator

Posts

Joined
Tue Jul 22, 2008 3:02 am

Post by dbstr » Tue Apr 27, 2010 5:11 pm

Any reason this wasn't added in 1.4.7? And will it be added in 1.4.8? :)

Request Reviews v1.0 released.


Active Member

Posts

Joined
Sun Aug 30, 2009 12:20 am

Post by American » Mon May 24, 2010 3:08 am

dbstr wrote:Any reason this wasn't added in 1.4.7? And will it be added in 1.4.8? :)
I second that motion! I just had my first two orders using OC and the first was 4, then the next was 16. This could make things interesting if I need to research past orders for some reason. At the very least it makes things a bit messy.

It would be good to see this in 1.4.8.

Brad G
Granbury, Texas
OC 1.5.6.4


User avatar
New member

Posts

Joined
Fri May 21, 2010 7:39 am
Location - Fort Worth, Texas

Post by Qphoria » Thu Sep 22, 2011 10:45 pm

UPDATED first post.
- Added 1.5.x support
- Added order status id check as noted by CarpeNoctumDC above

This should actually resolve the concerns daniel had about adding it to the core now.

Image


User avatar
Administrator

Posts

Joined
Tue Jul 22, 2008 3:02 am

Post by terrier » Fri Sep 23, 2011 11:28 am

Just wondering, let say if a customer go all the way up to confirm page and generates a new order id.

At the point of time, he decided to make the payment later and therefore close the browser. When he return and start to check out again, will he get a new order ID or reuse order iD?

New member

Posts

Joined
Wed Aug 31, 2011 7:05 pm

Post by Xsecrets » Fri Sep 23, 2011 11:55 am

terrier wrote:Just wondering, let say if a customer go all the way up to confirm page and generates a new order id.

At the point of time, he decided to make the payment later and therefore close the browser. When he return and start to check out again, will he get a new order ID or reuse order iD?
if you close the browser it kills the session, so they would get a new order_id the next time they came back.

OpenCart commercial mods and development http://spotonsolutions.net
Layered Navigation
Shipment Tracking
Vehicle Year/Make/Model Filter


Guru Member

Posts

Joined
Sun Oct 25, 2009 3:51 am
Location - FL US

Post by terrier » Fri Sep 23, 2011 1:56 pm

Hmm...

why is it not possible that order ID is generated only after clicking the confirm order?

Just like inv no. only generated after confirm order

New member

Posts

Joined
Wed Aug 31, 2011 7:05 pm

Post by Qphoria » Fri Sep 23, 2011 8:35 pm

terrier wrote:Hmm...

why is it not possible that order ID is generated only after clicking the confirm order?

Just like inv no. only generated after confirm order
The last step of the process is actually the payment form. Clicking Confirm goes directly to the external payment gateway url and doesn't go through opencart. So opencart creates a temp order one step earlier.

Yes, it could be possible to change this behavior and have it first send back to opencart, and then load the payment step with a jscript form submit onload like osc does it... or even with the ajax confirm step it could be done.. but it just isn't done like this at this time. Initially it was simpler to do it the way it is. This mod helps to retain the balance of the way you want it and the way it is.

Image


User avatar
Administrator

Posts

Joined
Tue Jul 22, 2008 3:02 am

Post by scanreg » Sat Sep 24, 2011 12:10 am

Thanks for this :)

Are there any plans to change the native method of order-id generation?

Active Member

Posts

Joined
Thu May 06, 2010 12:15 am

Post by Qphoria » Sat Sep 24, 2011 12:13 am

scanreg wrote:Thanks for this :)

Are there any plans to change the native method of order-id generation?
Not at this time

Image


User avatar
Administrator

Posts

Joined
Tue Jul 22, 2008 3:02 am

Post by cpuricelli » Fri May 11, 2012 12:16 am

Hi Qphoria, I installed the xml but seems that is not working, opencart is still generating new orders ID for missing orders. I have no logs in the vqmod log file, but I have another xml which changes the catalog/model/checkout/order.php ... can this be an issue?

Newbie

Posts

Joined
Tue Aug 09, 2011 8:56 pm

Post by Qphoria » Fri May 11, 2012 3:04 am

dunno.. check your vqmod/vqmod.log file for errors
Also be aware that you will still get temp orders, just not a new one everytime you reload step 6 of checkout for the same person.

To test.

Goto step 6 of checkout
in another tab, check the Abandoned order filter in the admin order area
Then on the first time, click Modify for step 5 again
Then continue to step 6 again
In the other tab, check the abandoned order filter again
You should not see a new temp order for yourself

I am actively using in 1.5.1.3 store.. haven't had a chanced to test on 1.5.2.x yet

Image


User avatar
Administrator

Posts

Joined
Tue Jul 22, 2008 3:02 am
Who is online

Users browsing this forum: No registered users and 20 guests