| ||||||||||
Shopping cart software Solutions for online shops and malls | ||||||||||
|
X-Cart Home | FAQ | Forum rules | Calendar | User manuals | Login |
Custom Order Numbering | |||
|
|
Thread Tools | Search this Thread |
#1
|
|||||||||
|
|||||||||
Custom Order Numbering
PREMISE
My current databases generates order numbers using a prefix, the current year, and a four-digit sequence, like 'SO/2020/0194'. X-Cart, natively simply uses a sequential number. In order for compatibility among my various systems, platforms and databases, I am working on an add-on which would override the current numbering system with one that matches my other platforms. CODE While some of my systems already have settings which allow me to easily perform this action, some do not. This is how I have overridden the native numbering format of one such platform: Code:
WHAT TO OVERRIDE? I assume I would need to override the findNextOrderNumber() function of the Oder model. Code:
QUESTIONS
__________________
X-Cart version 5.4.1.46 PHP version 7.4.33 MySQL version 15.1 Apache version 2.4.56 cURL version 7.74.0 |
|||||||||
#2
|
|||||||
|
|||||||
Re: Custom Order Numbering
Quote:
https://devs.x-cart.com/getting_started/working-with-database.html#query-builder For the question 2, normally you can just use the appropriate getter and setter, but I am not sure. 3 It suffices to create an abstract class that extends the Order class that implements iDecorator.
__________________
X-cart 5.2.12, php 5.6 Ed from Grenoble, France |
|||||||
#3
|
|||||||||
|
|||||||||
Re: Custom Order Numbering
There is ready one - https://market.x-cart.com/addons/order-prefix-suffix-by-cfl-systems.html
__________________
Steve Stoyanov CFLSystems.com Web Development |
|||||||||
#4
|
|||||||||
|
|||||||||
Re: Custom Order Numbering
Quote:
Thank you. That, unfortunately, does not suit my needs. It applies a prefix and suffix to the order number, but the order number itself continues to increment. I am looking to have intuitive order numbers where the sequence resets each year, and the current year is pre-appended. Since the orderNumber column of the orders model class is already a VARCHAR of length 255, so it already prepared to accept the form of order number required for my business logic. I just need to find the precise business logic which needs to be overridden by my module. It seems, though, that in my OP, I looked at the Order Repo model, rather than the actual Order Model itself. I am continuing my research to find exactly where in the business logic is found the code that sets the value of the orderNumber column.
__________________
X-Cart version 5.4.1.46 PHP version 7.4.33 MySQL version 15.1 Apache version 2.4.56 cURL version 7.74.0 |
|||||||||
#5
|
|||||||||
|
|||||||||
Re: Custom Order Numbering
Quote:
You will need to make a lot of changes to avoid issues with orderNumber. While the type in the database for this field is varchar this is the only place where orderNumber is treated as string. Everywhere else orderNumber is treated as integer. This was pointed out to XC veeery long time ago and I simply do not see them willing to change this behavior. If you start recording orderNumber as string, meaning the field having non-numeric characters, you will break orders search (both admin and customer), next/prev order, eventually payments and everything else that depends on orderNumber. Not to mention orderNumber is cast to (int) numerous times within the code, both for PHP and MySQL. If you keep it as number but start resetting it every so often you will end up with multiple orders having the same orderNumber which will again screw up lots of functionality. Unfortunately XC is coded within its core to work with orderNumber instead of orderId for lots of functions and behavior. For what you want your best bet is to have it say 202000001, then next year reset to 202100001 and so on. This will not cause any issues with current code. And you can easily set this at the beginning of every year through admin cart settings - next order number. Then you can use the module I mentioned to just add the SO/ prefix. And in this case you cannot have 2020/00001 as orderNumber as the / will mess things up.
__________________
Steve Stoyanov CFLSystems.com Web Development |
|||||||||
#6
|
|||||||||
|
|||||||||
Re: Custom Order Numbering
Quote:
Lots of good information here. Thank you, again. Instead of relying on the core orderNumber field, then; perhaps it might be better to add a column to the Order Model Class with behaviour defined by my module which would also include the necessary templates to display this value in both the FO and BO. This makes the module design a bit less of a challenge as I do not have to be as concerned with messing up the behaviours which access the orderNumber field itself. My next step was going to be to add a separate column for an invoice number, anyway, so it's just a matter of defining the columns and procedures associated with each. This is not so bad, since some of my other systems have separate numbers for the system and for the user/customer. Thanks again. Now I have a better idea of what direction to take.
__________________
X-Cart version 5.4.1.46 PHP version 7.4.33 MySQL version 15.1 Apache version 2.4.56 cURL version 7.74.0 |
|||||||||
#7
|
|||||||||
|
|||||||||
Re: Custom Order Numbering
I am working on a custom module which adds a column to the Order model for handling custom order reference numbers. Here is my .\Model\Order.php file:
Code:
Here is the workflow logic of the generateReference function:
It does create records in the Payment\Transaction and Order models, but xc_orders.orderNumber is Null and xc_orders.reference is blank. Is there a way to properly debug what is causing it to hang?
__________________
X-Cart version 5.4.1.46 PHP version 7.4.33 MySQL version 15.1 Apache version 2.4.56 cURL version 7.74.0 |
|||||||||
#8
|
|||||||||
|
|||||||||
Re: Custom Order Numbering
One thing I see, although it may not be the issue you have is
Code:
The way you have it PHP will assume \XLite\Model\Order\DateTime. Change it to Code:
Also use $this->getReference() == '' instead of $this->reference == '' - that's why you have the get method. However the reference in this case will always be empty. setOrderNumber() is called only when order is placed and turned into an order. Also you can make $reference nullable and assign default value of NULL instead of empty string. Then if you still want to check you can do Code:
or Code:
keeping in mind === will evaluate exact value of null while == will evaluate 0, '', false being null as well. While \ DateTime(date("Y")."-01-01") will give you what you want - Jan 1st @ 00:00:00am same is true for \DateTime(date("Y")."-12-31") - @ the very beginning of the day. You need to add 23 hrs 59 min and 59 seconds to end date to get to the end of year. Change your query to select max reference directly and get single result instead of looping through all. And since I assume you will always want to get the max number which will be current year anyway there is no need of min and max timestamp. I suggest you get the reference for the latest order that has one (meaning reference is not null, order number is not null and is_order is true) and then manipulate reference to increase by 1 for the next order.
__________________
Steve Stoyanov CFLSystems.com Web Development |
|||||||||
#9
|
|||||||||
|
|||||||||
Re: Custom Order Numbering
Thank you for your assistance and tips.
Quote:
The reason I filter the year of the orders is to reset the 4-digit sequence. When the query returns an empty result, the integer value of Null becomes 0, to which 1 is added, thus having an automatic reset of the numbering. I recognize what you mean by my range missing the last 23 hours, 59 minutes and 59 seconds of the year, so I added a year column to streamline the query. Code:
After these alterations based of your feedback, the reference numbers are being generated, and the site no longer hangs after payment is processed.
__________________
X-Cart version 5.4.1.46 PHP version 7.4.33 MySQL version 15.1 Apache version 2.4.56 cURL version 7.74.0 |
|||||||||
#10
|
|||||||||
|
|||||||||
Re: Custom Order Numbering
Good to know you got it working
__________________
Steve Stoyanov CFLSystems.com Web Development |
|||||||||
|
|||
X-Cart forums © 2001-2020
|