Drupal 9 commerce - get order number:
By the below method you can generate order number:
public function generateOrderNumber(OrderInterface $order) {
if ($order->getOrderNumber()) {
return $order->getOrderNumber();
}
$order_type_storage = \Drupal::entityTypeManager()->getStorage('commerce_order_type');
/** @var \Drupal\commerce_order\Entity\OrderTypeInterface $order_type */
$order_type = $order_type_storage->load($order->bundle());
/** @var \Drupal\commerce_number_pattern\Entity\NumberPatternInterface */
$number_pattern = $order_type->getNumberPattern();
$order_number = $number_pattern->getPlugin()->generate($order);
$order->setOrderNumber($order_number);
return $order->getOrderNumber();
}
.:Happy coding:.
No comments:
Post a Comment