D
D
DrOsd2014-02-27 23:40:46
PHP
DrOsd, 2014-02-27 23:40:46

How to make the numbering of orders in drupal commerce not serial (1,2,3,4,....), but assign the order number corresponding to the unix timestamp date?

For a long time I was looking for a solution on how to make order numbering in drupal commerce not serial (1,2,3,4,....), but assign an order number corresponding to the unix timestamp date.
Someone advised to do it through rules, but it turned out to be difficult for me.
I found a solution how to change the numbering scheme through a hook:

<?php
/**
 * Implements hook_commerce_order_presave().
 *
 * Alter order number.
 * $order does not need to be referenced since it is an object.
 */
function yourmodule_commerce_order_presave($order) {
  if (isset($order->order_id)) {
    // Alter order number by multplying the order id with 63.
    $order->order_number = sprintf('%08d', $order->order_id * 63);
  }
}
?>

This approach works, but it multiplies the current number by 63. How can I tweak it so that the order number gets a timestamp?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vadim, 2014-02-28
@ShVad

$order->order_number = time();

D
DrOsd, 2014-02-28
@DrOsd

Thank you) it works ..
Perhaps someone knows how to change not the order number but its ID in the same way? I'm guessing that you need to use a different hook .. And is it possible to change the ID at all?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question