Jump to content

Custom order numbers, like 101202001-002-...


DenisDT

Recommended Posts

Hello everony!

Is somebody interested in being able to do this? I have found a way to do it.
Example:
Today is 02-12-10, first order -> order number 101202001
next order number of the day, 101202002, then 101202003 and so on.
The next day, order number simply changes to 101203001, then 101203002 etc etc...

The date/time structure is changeable of course.

Post it here if you need it and i'll share it!

Link to comment
Share on other sites

  • 3 weeks later...

Well, put this in header.php for a yymmdd001 kind of numbering:

$order_res = Db::getInstance()->Execute("SHOW TABLE STATUS LIKE 'ps_orders'");
$order_row = mysql_fetch_assoc($order_res);
$order_nextautoid = $order_row['Auto_increment'];
mysql_close($order_res);

if (substr($order_nextautoid, 0, 6) != date("ymd")) {
   Db::getInstance()->Execute('ALTER TABLE `'._DB_PREFIX_.'orders` AUTO_INCREMENT = '.intval(date("ymd").'001'));
}



It checks if the auto_increment has already been changed that day. If no, change it to today and add suffix '001'.
If yes, do nothing.

Sound good?

D.

Link to comment
Share on other sites

  • 2 weeks later...
  • 4 weeks later...
  • 1 month later...
  • 2 weeks later...

No problem :), but I have one question (problem).

For example:
Today date is: 110406
auto_increment in ps_orders is: 110404006
If someone makes an order. The order number is 110404006, although the today date is different, and auto_increment value should be overridden.

Whether this means that retrieves the value id_order Presta earlier than execute the command ALTER TABLE in the module?

Link to comment
Share on other sites

I have installed this module on Prestashop 1.4. First it looks it will work just fine, but today (17.4.2011) I made a test order and the module generated order number 110412001, which corresponds to the first order on date 12.4.2011. Why the order number is not 110417001?

Link to comment
Share on other sites

hi angora,

your coding is actually working fine, except for the part that the 1st invoice of the day will not be "reset". you get what i mean? i think it has something to do with caches or something. the 2nd invoice of the day onward will work fine with the update date infront of the invoice number.

Link to comment
Share on other sites

  • 1 month later...
hi angora,

your coding is actually working fine, except for the part that the 1st invoice of the day will not be "reset". you get what i mean? i think it has something to do with caches or something. the 2nd invoice of the day onward will work fine with the update date infront of the invoice number.


I have exactly the same problem, only the first order of the day has a wrong number (it is the next number of order from previous day) ... did you find solution for it?
Link to comment
Share on other sites

hi angora,

your coding is actually working fine, except for the part that the 1st invoice of the day will not be "reset". you get what i mean? i think it has something to do with caches or something. the 2nd invoice of the day onward will work fine with the update date infront of the invoice number.


Me too. Any fix for the invoices ? All my invoices are writing Invoice #0, not only the first, but all of the whole day.
Link to comment
Share on other sites

Problem is with hook.
Solution is uninstall the module and move dirty hack ;) in order.php under function:

if (!$cart->checkQuantities())
{
   $step = 0;
   $errors[] = Tools::displayError('An item in your cart is no longer available, you cannot proceed with your order');
}



should look like this:

if (!$cart->checkQuantities())
{
   $step = 0;
   $errors[] = Tools::displayError('An item in your cart is no longer available, you cannot proceed with your order');
}

/* Number of order */

         $order_res = Db::getInstance()->Execute("SHOW TABLE STATUS LIKE '"._DB_PREFIX_."orders'");
         $order_row = mysql_fetch_assoc($order_res);
         $order_nextautoid = $order_row['Auto_increment'];
         mysql_close($order_res);
         if (substr($order_nextautoid, 0, 6) != date("ymd"))
         {

                 Db::getInstance()->Execute('ALTER TABLE `'._DB_PREFIX_ .'orders` AUTO_INCREMENT = '.intval(date("ymd").'001'));
         }


...and voila. :)

Link to comment
Share on other sites

Yes, I have very old ;) PS 1.2.5. HookNewOrder not working correctly in PS 1.2.4 and 1.2.5. (module code is executed after the approval of the order and first of the day have wrong number).

Dirty hack can be placed after line ~15 order.php file(PS 1.2.5)

$errors = array();

/* here */



- it will work.

Link to comment
Share on other sites



I'm curious to learn why hookNewOrder is working fine for some, but not all, v1.4+ shops
but no "fix" is forthcoming (from me, at least) because for me it's working as intended.


It's ok and valid, but as it's not working for me and although I have deinstalled it on BO and also deleted the module on BO, all new orders are coming with the order format 11-mm-dd-nr.

How to reset the DB ? I just tried by deleting of all orders to begin from zero, but this didn't solved it. Which table I have to put zero, so that counter begans to count from zero (I'm not in production but going by end of this week).
Link to comment
Share on other sites

  • 9 months later...
  • 3 weeks later...

1.4.7.3 Test: Ok

 

OrderController.php edit

original:

 

/* If some products have disappear */

if (!self::$cart->checkQuantities())

{

$this->step = 0;

$this->errors[] = Tools::displayError('An item in your cart is no longer available for this quantity, you cannot proceed with your order.');

}

 

under paste:

 

 

/* Number of order */

 

$order_res = Db::getInstance()->Execute("SHOW TABLE STATUS LIKE '"._DB_PREFIX_."orders'");

$order_row = mysql_fetch_assoc($order_res);

$order_nextautoid = $order_row['Auto_increment'];

mysql_close($order_res);

if (substr($order_nextautoid, 0, 6) != date("ymd"))

{

 

Db::getInstance()->Execute('ALTER TABLE `'._DB_PREFIX_ .'orders` AUTO_INCREMENT = '.intval(date("ymd").'001'));

}

Link to comment
Share on other sites

  • 2 months later...
  • 3 weeks later...
  • 4 months later...

For those who might be a little confused on how to make this work, I did the following for my PS 1.4.7.3 so you may follow the same if you'd like.

 

First:

Download the module from the post below from page 1.

 

' timestamp='1301931525' post='522055']

Version for PS 1.2.4 (in attachment).

 

In loyalty module must change in file loyalty.tpl:

		'id_order' => 8,

to

		'id_order' => 10,

 

and voila. :)

 

Then make the following changes to your ordercontroller.php file under the controller folder.

 

1.4.7.3 Test: Ok

 

OrderController.php edit

original:

 

/* If some products have disappear */

if (!self::$cart->checkQuantities())

{

$this->step = 0;

$this->errors[] = Tools::displayError('An item in your cart is no longer available for this quantity, you cannot proceed with your order.');

}

 

under paste:

 

 

/* Number of order */

 

$order_res = Db::getInstance()->Execute("SHOW TABLE STATUS LIKE '"._DB_PREFIX_."orders'");

$order_row = mysql_fetch_assoc($order_res);

$order_nextautoid = $order_row['Auto_increment'];

mysql_close($order_res);

if (substr($order_nextautoid, 0, 6) != date("ymd"))

{

 

Db::getInstance()->Execute('ALTER TABLE `'._DB_PREFIX_ .'orders` AUTO_INCREMENT = '.intval(date("ymd").'001'));

}

 

Make sure your modules permissions are set to 777 recursively. This should work now. Make test orders to confirm.

Edited by peanut (see edit history)
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...