Currently, the Order class sets an order number to its ID in its postSave() hook, if it's not already set, regardless if it was placed or not, so by other means on first save of the cart.

When you want to ensure sequential and ascending order numbers, which is for sure a very common wish, you'll need to override this number. In general not a problem, you could hook into the place transition and set it to any other number.

But with the current implementation, you'll always have to take care that your "real" order numbers do not interfere with the temporary ones. That means, you can never start with 1... instead you must prefix, suffix or start at order number 1000000, etc..

Talked to mglaman on IRC. He agrees that this is a PITA for him too.

First question: is it really necessary to always have an order number for carts? mglman means: "an order _should_ have a number.. whether draft or not because admin based workflows"

How can we get around that?

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

agoradesign created an issue. See original summary.

bojanz’s picture

I believe that in 1.x carts didn't have order numbers.
An order should get a number when it's placed.

So we need to kill the preSave() part + do #2730131: Add a commerce_number_pattern submodule for sequential (order/invoice) number generation.

agoradesign’s picture

We don't have to implement the other issue necessarily in the same step, do we?

Means, that we could refactor the architecture and provide a default order number generation, which points to the order id - or maybe already do a sequential numbering - but leave the configurable part aside and extend that within the other issue.

Should we do that like the price resolvers, so that it can easily be swapped?

agoradesign’s picture

Status: Active » Needs review
FileSize
3.29 KB

Here's the patch. It removes the code from the postSave() hook and moves the logic to a place transition subscriber (with a low priority to be easily overridable by custom module) -> from now on, draft orders will no longer have an order number set by default.

Github PR to follow...

agoradesign’s picture

Sorry, uploaded the wrong patch... that one was beta4 compatible, this is the right one against dev

agoradesign’s picture

agoradesign’s picture

FileSize
6.43 KB

updated patch to be in sync with the Github PR. No functional changes, only fixing OrderUserTest and added OrderNumberTest

agoradesign’s picture

btw, I've started building a module for generating order numbers, based upon this patch. It's sandbox currently, as I'll have to finish configuration, add a proper description, write tests,... But the functionality does work already: https://www.drupal.org/sandbox/agoradesign/2845422

bojanz’s picture

@agoradesign
Make sure to look at the commerce_billy logic, that's the one we want to replicate.

agoradesign’s picture

Ok, I will... currently that is only partially covered. But I'm gonna to refactor the whole module anyway, coz I'm not satisfied with the current architecture anyway

  • bojanz committed 9b7bff4 on 8.x-2.x authored by agoradesign
    Issue #2842356 by agoradesign: Rethink the default order number...
bojanz’s picture

Status: Needs review » Fixed

Thanks!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.