-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixed unique order number error #904
Conversation
MAX will work on varchar field as long as we keep them numbers. In case someone wants to use codes ... he will need to replace the order number generator right? (my main point here is that "number" is varchar, because sometimes you want stuff like "ABCFOO-1424" or whatever) |
What about getting order with last id?
|
Ping @pjedrzejewski |
Yeah, but ... we have to take the order with a) last ID b) only if it has been completed (completedAt property is not empty). This way it should work properly and avoid this error. |
@pjedrzejewski What if there is order number |
@pjedrzejewski Fixed according to your instructions anyway, but I would remove |
This will show you the carts (not completed orders). We should base the id on the number, not the sql id. What do you think? |
I dont understand your last comment. Is my PR ok now? I'm fine if we merge
|
return $queryBuilder | ||
->select('o.number') | ||
->andWhere('o.completedAt IS NOT NULL') | ||
->orderBy('o.id', 'desc') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@umpirsky I think @pjedrzejewski is referring to this line. Should we order by o.number
instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kayue That was my original idea, but then @pjedrzejewski wanted to cover order numbers like ABCFOO-1424
. See #904 (comment).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The ID definitely does not work for this (that is what it originally was). The issue is that the order number sequence is related to the completedAt of the order, not the original insertion time. See #631
👎 on ordering by ID. I had some more thoughts over here: #880 (comment) Basically, I think the only really reliable way is to use a separate table to track an autoincrement for completed orders only. |
@Richtermeister In that case I vote for this logic, or previous + adding unique check, which means if order number already exists, increment it and try again until we find non existing one. Thoughts? @pjedrzejewski @kayue |
Ping @pjedrzejewski |
@umpirsky I vote for sorting by And people can always introduce new generator if they want something fancy. |
@kayue I agree. I just think @pjedrzejewski want to make number generator as flexible as possible and non sortable order numbers. @pjedrzejewski Please help us make decision and I will fix it since we need this fix. |
I'm in favor of @Richtermeister's solution, aka not sorting a field without knowing its content. |
I'll have a look at existing solutions... it's a bit tricky for me as well. |
@pjedrzejewski Any decision? This is a blocker for us. |
Ok, after some research I think there is no other clean way than going with a separate table like @Richtermeister said. So if we want the default order number generator work with sequential numbers, then we need to go this way. BUT, I'd like to have a separate customizable generator, which would handle something like this. |
@pjedrzejewski OK. Please suggest table name. Customizable number generator can be handled in separate PR. Agree? |
@umpirsky Yes! |
I would vote for: |
|
@pjedrzejewski Yes, thanks! So, I just need to insert into |
I would say The paid/not paid order with or without number is a real problem. If no number we can't use it as idnetifier to pass to the payment gateway. If number, then some numbers will be taken by orders and then deleted if no payment received. |
@winzou Right, |
If it is in order bundle |
I'd say it should go to the OrderBundle for now. When we have another use case, we could move it somehow. |
@pjedrzejewski Please check this PR. It is not finished yet. I want to remove persisting from listener https://github.com/Sylius/Sylius/pull/904/files#diff-a3e834f246ffed7bca4e312d71f0e3d8R74 but how to persist this number then? Making bidirectional one to one relation order - number does not make much sense, and we already have number property in order model which can cause confusion. I am also not sure if number and order models should be related at all. Any ideas how to handle this? @winzou @Richtermeister @stloyd |
|
||
class NumberRepository extends EntityRepository implements NumberRepositoryInterface | ||
{ | ||
public function getLastNumber() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you add directly a type
or any better name for future entities distinction? So that this method would become getLastNumber('order')
to get the last number for order
.
@pjedrzejewski Is it good to go now? |
@pjedrzejewski Piiing :) |
@pjedrzejewski Please, 5 days... |
{ | ||
try { | ||
return $this->getQueryBuilder() | ||
->select('o.id') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you use $this->getAlias
instead?
Apart from the |
@winzou Fixed. |
@umpirsky Waiting for travis. Why wouldn't you use composer repository override method, instead of waiting for merge? |
@pjedrzejewski I can wait, but I see no reason simple PRs like this stand and wait for several days. |
@umpirsky Because merging them does not involve only clicking the merge button. This PR is not that simple as you would think. |
:) |
Fixed unique order number error
Thank you patient Sasha! 👍 |
@umpirsky Nice work man! Thanks for getting this done. |
I have encountered an issue related to this.
|
@lucian-v Could you open a separate issue? |
$number = $this->numberRepository->createNew(); | ||
$number->setOrder($order); | ||
|
||
$this->numberManager->persist($number); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There shouldn't be a Number persist if the order already has a number, bug reproduces on :
- Fail on paypal express checkout -> payment page
- Dummy payment -> place order runs into a fatal error doctrine can't sava another sylius_number with same order_id
Order with latest
completedAt
value, is not always order with greatest order number. That is why you can get:This should be fixed now.