How to change the Order Reference to Number Reference

Vinoth picture Vinoth · Jan 3, 2014 · Viewed 20.8k times · Source

Using new version of Prestashop 1.5.2.0. I would like to change the Order reference ( alphabets ) to alphanumeric value. I tried searching in forums and Seen this forum. Unfortunately it wont work for me.

Can any one have solution to change Order reference ( alphabets ) to alphanumeric value in entire application.

I mean "AQMKATRQG" to "LD1001" and the increment it to "LD1002" I would like to change the Order reference ( alphabets ) to alphanumeric value. I tried searching in forums and Seen this forum. Unfortunately it wont work for me.

Can any one have solution to change Order reference ( alphabets ) to alphanumeric value in entire application.

I mean "AQMKATRQG" to "LD1001" and the increment it to "LD1002"

Answer

richhallstoke picture richhallstoke · May 5, 2015

In PrestaShop 1.6 (tested and confirmed working in v1.6.0.14) you can accomplish this by the following method.

  1. Copy the file /classes/PaymentModule.php to /override/classes/PaymentModule.php.

  2. Edit the file /override/classes/PaymentModule.php as follows.

At lines 337-341 is a code block that should read like this:

if (!result)
{
  PrestaShopLogger::addLog('PaymentModule::validateOrder - Order cannot be created',
    3, null, 'Cart', (int)$id_cart, true);
  throw new PrestaShopException('Can\'t save Order');
}

Immediately after that code block, insert the following two lines of code:

$order->reference = str_pad($order->id, 9, '0', STR_PAD_LEFT);
$order->update();
  1. Delete the file /cache/class_index.php so that Prestashop automatically re-creates this file taking into account the new override file.

  2. Any existing records in your PrestaShop database can be updated to use a numerical reference manually using a tool such as phpMyAdmin.

I would imagine the steps would be very similar if not identical to these for PrestaShop v1.5 but at this time I have not tested this solution with PrestaShop v1.5. If someone finds this solution works on v1.5 perhaps they could confirm this in the comments. Thank you.