Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change the Order Reference to Number Reference

Tags:

prestashop

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"

like image 460
Vinoth Avatar asked Jan 03 '14 05:01

Vinoth


2 Answers

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.

like image 179
richhallstoke Avatar answered Oct 20 '22 20:10

richhallstoke


The above solutions are essentially correct, but you REALLY should refrain from modifying any of the core code if you can keep from it. I put all of my mods in a special folder locally after I apply any upgrades to prestashop or my theme engine, then I upload the modifications one by one (after each one is tested).

These instructions are for 1.6.x users - but MAY work on 1.5.x - I don't have that code to test with.

1) Create a file named order.php and place the code below in that file

2) Next, upload the file to /override/classes/order/order.php

3) Navigate to the /cache folder and delete the file class_index.php (it will be recreated on the next page request)

<?php
/*
 *  RETURN ORDER REFERENCE TO SEQUENTIAL NUMERIC VALUE
 *
 *  2016 PrestaShop v1.6.1.x
 *  Override by obewanz
 *
 *  You can use the following SQL query to change the starting order no if desired
 *  where the number 101 is the next desired order number:
 *  ALTER TABLE `ps_orders` AUTO_INCREMENT = 101
 *  --------------------------------------------
 *  OPTION: (ALL NUMERIC)
 *  str_pad((int)$last_id + 1, 9, '000000000', STR_PAD_LEFT);
 *  OPTION SET TO ORIG 1.5.x STYLE REFERENCE NUMBERS: 
 *  str_pad((int)$last_id + 1, 6, '000000', STR_PAD_LEFT);
 */

Class Order extends OrderCore {
  public static function generateReference() {
    $last_id = Db::getInstance()->getValue('SELECT MAX(id_order)
                                            FROM '._DB_PREFIX_.'orders');
    return str_pad((int)$last_id + 1, 9, 'NR-000000', STR_PAD_LEFT);
  }
}

You should be finished now, and your next order will have a reference something like: NR-000101

The second "OPTION" in the code comments returns the order reference number to essentially that of PS 1.5.x - (I had a reference to it in an old file.)

I have also included the appropriate SQL statement in the code comments to set the next order number if needed.

like image 1
Obewan Avatar answered Oct 20 '22 18:10

Obewan