The order number is currently set in OrderNumberSubscriber::setOrderNumber. IMO order number is what would be used as an invoice number; however, gateways would need the order number before it's set.

Should the order number be set on, for example, the `commerce_order.commerce_order.insert` event?

Comments

chrisrockwell created an issue. See original summary.

ryross’s picture

My client sets the order number after the order has been placed because they have a manufacturing facility that depends on sequential order numbers. So we have a Cart ID (visible to the users) and Order IDs (visible to the user after they order has been placed. So changing how the order number is set would negatively affect us.

mglaman’s picture

If we could get #2730131: Add a commerce_number_pattern submodule for sequential (order/invoice) number generation to land it would be interesting to support draft + placed order numbers.

bojanz’s picture

Status: Active » Fixed

An order number is by definition the number of a placed order. It can never be set before that.

Order numbers follow a specific pattern and need to be sequential. Generating them when the cart is created would create holes in the numbers, since each cart would get its own number. That means that it would be no better than the order ID.

Gateways should send the order ID, or nothing. Otherwise their support should be contacted for clarification ("Which number to send if the order is being prepaid at checkout, meaning that there is no invoice number yet")

Status: Fixed » Closed (fixed)

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

_dcre_’s picture

@bojanz

you wrote the following

Order numbers follow a specific pattern and need to be sequential. Generating them when the cart is created would create holes in the numbers, since each cart would get its own number. That means that it would be no better than the order ID.

however, looking at the code we see that the order number is only set once, according to the following

/**
* Sets the order number, if not already set explicitly, to the order ID.
*
* @param \Drupal\state_machine\Event\WorkflowTransitionEvent $event
* The transition event.
*/
public function setOrderNumber(WorkflowTransitionEvent $event) {
/** @var \Drupal\commerce_order\Entity\OrderInterface $order */
$order = $event->getEntity();
if (!$order->getOrderNumber()) {
$order->setOrderNumber($order->id());
}
}

The above event is triggered when an the commerce_order.place.pre_transition.

So it looks like order number do have holes, as it is indeed the order id.
Am i missing something here?