muynck Posted April 9, 2020 Posted April 9, 2020 Hi PrestaShop-merchants, I have created a module for solving a age old problem: changing the order reference into something meaning full. The random string of characters is not a preferred order reference for most merchants. You can use variables to fill the order reference with, like $cart->id, $order->id, $shop->name, or a combination of those. You can use any variable from several PrestaShop Objects (main classes). For a more detailed explanation checkout: https://github.com/blauwfruit/orderreference See the latest releases: https://github.com/blauwfruit/orderreference/releases Give me your opinion! Thanks! 5 Share this post Link to post Share on other sites More sharing options...
nekromantik Posted July 9, 2020 Posted July 9, 2020 Thanks Works great but what if I want permanent string or digit in the begining and order nummer with 4 preceding zeroes? For example 2020 or ABC. This doesnt work: 2020{order->id:%04d} - 20200001,20200002,20200003,.. ABC{order->id:%04d} - ABC0001,ABC0002,ABC0003,.. Thanks for answer. Share this post Link to post Share on other sites More sharing options...
nekromantik Posted July 9, 2020 Posted July 9, 2020 I got it,sorry {2020}{order->id:%04d} {ABC}{order->id:%04d} Share this post Link to post Share on other sites More sharing options...
muynck Posted July 9, 2020 Posted July 9, 2020 @nekromantik that is a good solution! I added it to the documentation: https://github.com/blauwfruit/PrestaShop-Order-Reference 1 Share this post Link to post Share on other sites More sharing options...
way1 Posted July 10, 2020 Posted July 10, 2020 Hello! Could you advice, how get this kind of format? [order date}_[random unique number of 3 digits] for example: 2020-07-10_678 Share this post Link to post Share on other sites More sharing options...
nekromantik Posted July 14, 2020 Posted July 14, 2020 On 7/9/2020 at 5:36 PM, muynck said: @nekromantik that is a good solution! I added it to the documentation: https://github.com/blauwfruit/PrestaShop-Order-Reference Great job man Thanks again. Share this post Link to post Share on other sites More sharing options...
Abu Sayed|CUET Posted October 3, 2020 Posted October 3, 2020 Thanks dude! Share this post Link to post Share on other sites More sharing options...
EstebanGarviso Posted November 3, 2020 Posted November 3, 2020 On 7/10/2020 at 12:50 PM, way1 said: Hello! Could you advice, how get this kind of format? [order date}_[random unique number of 3 digits] for example: 2020-07-10_678 {order->date_add:%10.10s}{_}{cart->id:%03d} = 2020-07-10_678 {order->date_add:%7.7s}{_}{cart->id:%03d} = 2020-07_678 {order->date_add:%4.4s}{_}{cart->id:%03d} = 2020_678 If your PS create more than 999 carts, then the 3 last numbers would be increase to 4 in order to fit 1000 and so on. Share this post Link to post Share on other sites More sharing options...
MuniGod Posted November 3, 2020 Posted November 3, 2020 How to install it? Share this post Link to post Share on other sites More sharing options...
muynck Posted November 4, 2020 Posted November 4, 2020 14 hours ago, EstebanGarviso said: {order->date_add:%10.10s}{_}{cart->id:%03d} = 2020-07-10_678 {order->date_add:%7.7s}{_}{cart->id:%03d} = 2020-07_678 {order->date_add:%4.4s}{_}{cart->id:%03d} = 2020_678 If your PS create more than 999 carts, then the 3 last numbers would be increase to 4 in order to fit 1000 and so on. At the moment a random number is not really possible. Can you create an issue to do this feature request? You can do this here: https://github.com/blauwfruit/PrestaShop-Order-Reference/issues Share this post Link to post Share on other sites More sharing options...
muynck Posted November 4, 2020 Posted November 4, 2020 12 hours ago, MuniGod said: How to install it? Through upload by FTP or backoffice and hit install. Download the zip at the top: https://github.com/blauwfruit/PrestaShop-Order-Reference/releases/tag/1.1.3 Share this post Link to post Share on other sites More sharing options...
Bjorn Lothbrok Posted February 22, 2021 Posted February 22, 2021 Great modul and thanks for it. Questions: 1. Can I add a new starting number e.x I want that my id start at 200 How can I do it? 2. e.x XYZ202100200 - starting at 200 This string: {XYZ}{order->date_add:%4.4s}{order->id:%05d} Right?? What would be the string for the year 21 instead of 2021 Thanks for some help and feedback! Bjorn Share this post Link to post Share on other sites More sharing options...
muynck Posted February 23, 2021 Posted February 23, 2021 Good one. That is not yet possible. I created an issue here: https://github.com/blauwfruit/PrestaShop-Order-Reference/issues/1 We don't have time to solve it. If you have a solution, you can create a pull request. Share this post Link to post Share on other sites More sharing options...
Bjorn Lothbrok Posted February 23, 2021 Posted February 23, 2021 Ok. But sorry I am not a coder, so I also don´t know. Maybe someone will do it in the future. In any case, great work from you and thanks for the modul!!! Share this post Link to post Share on other sites More sharing options...
mr_absinthe Posted June 13, 2021 Posted June 13, 2021 (edited) Hi and thanks for the module! I noticed one small glitch when I used this: {BE}{order->date_add:%4.4s}{order->id:%03d} I created few orders and all had the same number: BE2021210. I think it is due to the fact that it is taking first three digits from the id_order because in my case they are 2106003, 2106004, 2106005... Is it possible to change it so it will take last three digits instead first three from the order ID? Looks like I have an update. A customer received three emails, all with an identical ref.: BE2021210. However me, as a merchant, I received order confirmation email sent via ps_emailalerts contained correct numbers: BE20212106003, BE20212106004... In database, I see BE2021210 next to each of those orders. Since the reference cannot have more than 9 digits/letters, the only solution is to use last 3-4 numbers from the id_order. Edited June 13, 2021 by mr_absinthe (see edit history) Share this post Link to post Share on other sites More sharing options...
redrum Posted June 22, 2021 Posted June 22, 2021 (edited) On 6/13/2021 at 10:12 PM, mr_absinthe said: Hi and thanks for the module! I noticed one small glitch when I used this: {BE}{order->date_add:%4.4s}{order->id:%03d} I created few orders and all had the same number: BE2021210. I think it is due to the fact that it is taking first three digits from the id_order because in my case they are 2106003, 2106004, 2106005... Is it possible to change it so it will take last three digits instead first three from the order ID? Looks like I have an update. A customer received three emails, all with an identical ref.: BE2021210. However me, as a merchant, I received order confirmation email sent via ps_emailalerts contained correct numbers: BE20212106003, BE20212106004... In database, I see BE2021210 next to each of those orders. Since the reference cannot have more than 9 digits/letters, the only solution is to use last 3-4 numbers from the id_order. I wanted to fetch the last number from the order id myself. So I made an small addition to orderreference.php I haven't tested it, but it look fine in the back office preview. You can see what I changed athttps://github.com/topfuel75/PrestaShop-Order-Reference/commit/a6a87c6d01762a7470fb24d88410966943b7bd87#diff-1da936e8328bb26324e0931c8b2c217f8a6c73cbc56f1d05ea5f511b1146f455 So in your case the following format should pull out the last 3 digits from the order id: {BE}{order->date_add:%4.4s}{order->id:%03d:last:3} I noticed that the following also seems to work {BE}{order->date_add:%4.4s}{order->id:%d:last:3} Let me know how it goes. Edited June 22, 2021 by redrum Clarification (see edit history) Share this post Link to post Share on other sites More sharing options...
mr_absinthe Posted June 23, 2021 Posted June 23, 2021 (edited) I tested {BE}{order->date_add:%4.4s}{order->id:%03d:last:3} and it is working fine, as expected, well done! It would be nice if someone can change order date to have last two digits of the year (year short) and month. For example: June 2021 would become 2106. And if the yy and mm would be separate, we could use 21-06, 21_06, etc. Currently we can only have 2021-06 when using {order->date_add:%7.7s} Edited June 23, 2021 by mr_absinthe (see edit history) Share this post Link to post Share on other sites More sharing options...
redrum Posted June 23, 2021 Posted June 23, 2021 (edited) 29 minutes ago, mr_absinthe said: It would be nice if someone can change order date to have last two digits of the year (year short) and month. For example: June 2021 would become 2106. Currently we can only have 2021-06 when using {order->date_add:%7.7s} The closest I come to that, without changing the code further, is 21-06. {order->date_add:%7.7s:last:5} Edited June 23, 2021 by redrum (see edit history) Share this post Link to post Share on other sites More sharing options...
mr_absinthe Posted December 1, 2021 Posted December 1, 2021 (edited) I updated to your latest version and this no longer works (works just fine in previous version) {BE}{order->date_add:%4.4s}{order->id:%03d:last:3} It returns BE2021ord this is working fine on previous version: {order->date_add:%7.7s:last:5} but not in version v1.2.0 (returns ANJPZFLNX) - tested twice this is also not working on the latest PS v 1.7.7.6.: {BE}{order->date_add:%4.4s:last:2}{order->id:%05d} returns GUYWNOULU as well as this: {BE}{order->date_add:%4.4s:last:2}{order->id:%05d:last:5} also returns letters Edited December 1, 2021 by mr_absinthe (see edit history) Share this post Link to post Share on other sites More sharing options...
muynck Posted December 1, 2021 Posted December 1, 2021 In the new update a bug is fixed. The reference will not be longer than 9 characters. Because if it was, there could be an error and it would return an empty value. Try to create a format that will not exceed the 9 characters. Let me know if this helps. Share this post Link to post Share on other sites More sharing options...
mr_absinthe Posted December 1, 2021 Posted December 1, 2021 (edited) I did, see my edited post above. For example this should only return something like 21-11: {order->date_add:%7.7s:last:5} Actually, none of my examples is longer than 9 characters. Edited December 2, 2021 by mr_absinthe (see edit history) Share this post Link to post Share on other sites More sharing options...
mr_absinthe Posted December 2, 2021 Posted December 2, 2021 (edited) This seems to fix the issue, change in this: public function getFormattedReference($id_order) { $string = $this->getFormat(); preg_match_all('/{(.*?)}/', $string, $matches); $reference = ''; foreach ($matches[1] as $value) { $vars = explode(':', $value); if (count($vars)==2) { $reference .= sprintf("$vars[1]", $this->getVariable($vars[0], $id_order)); } elseif (count($vars)==3) { if ($vars[2] == 'capitalize') { $reference .= strtoupper(sprintf("$vars[1]", $this->getVariable($vars[0], $id_order))); } } else { $reference .= $vars[0]; } } to this: public function getFormattedReference($id_order) { $string = $this->getFormat(); preg_match_all('/{(.*?)}/', $string, $matches); $reference = ''; foreach ($matches[1] as $value) { $vars = explode(':', $value); if (count($vars)==2) { $reference .= sprintf("$vars[1]", $this->getVariable($vars[0], $id_order)); } elseif (count($vars)==3) { if ($vars[2] == 'capitalize') { $reference .= strtoupper(sprintf("$vars[1]", $this->getVariable($vars[0], $id_order))); } } elseif (count($vars)==4) { if ($vars[2] == 'last') { $reference .= substr(strtoupper(sprintf("$vars[1]", $this->getVariable($vars[0], $id_order))), -($vars[3])); } } else { $reference .= $vars[0]; } } Edited December 2, 2021 by mr_absinthe (see edit history) Share this post Link to post Share on other sites More sharing options...
muynck Posted December 2, 2021 Posted December 2, 2021 To be honest, I don't know what "last:5" does. Can you give me an example of a format that you're trying to achieve? BE2021003 Is that it? Share this post Link to post Share on other sites More sharing options...
muynck Posted December 2, 2021 Posted December 2, 2021 (edited) 5 minutes ago, mr_absinthe said: This seems to fix the issue, change in this: public function getFormattedReference($id_order) { $string = $this->getFormat(); preg_match_all('/{(.*?)}/', $string, $matches); $reference = ''; foreach ($matches[1] as $value) { $vars = explode(':', $value); if (count($vars)==2) { $reference .= sprintf("$vars[1]", $this->getVariable($vars[0], $id_order)); } elseif (count($vars)==3) { if ($vars[2] == 'capitalize') { $reference .= strtoupper(sprintf("$vars[1]", $this->getVariable($vars[0], $id_order))); } } else { $reference .= $vars[0]; } } to this: public function getFormattedReference($id_order) { $string = $this->getFormat(); preg_match_all('/{(.*?)}/', $string, $matches); $reference = ''; foreach ($matches[1] as $value) { $vars = explode(':', $value); if (count($vars)==2) { $reference .= sprintf("$vars[1]", $this->getVariable($vars[0], $id_order)); } elseif (count($vars)==3) { if ($vars[2] == 'capitalize') { $reference .= strtoupper(sprintf("$vars[1]", $this->getVariable($vars[0], $id_order))); } } elseif (count($vars)==4) { if ($vars[2] == 'last') { $reference .= substr(strtoupper(sprintf("$vars[1]", $this->getVariable($vars[0], $id_order))), -($vars[3])); } } else { $reference .= $vars[0]; } } Can you create an issue and a pull request for this? Edited December 2, 2021 by muynck (see edit history) Share this post Link to post Share on other sites More sharing options...
mr_absinthe Posted December 2, 2021 Posted December 2, 2021 23 minutes ago, muynck said: To be honest, I don't know what "last:5" does. Can you give me an example of a format that you're trying to achieve? BE2021003 Is that it? last will return last digits, for example date_add:%7.7s will normally return 2021-12 (if order placed today) but last:5 will return 21-12 only. Feel free to do the pull request. Share this post Link to post Share on other sites More sharing options...
muynck Posted December 7, 2021 Posted December 7, 2021 Can you try this: {BE}{order->date_add:%4.4s}{order->id:%03d} The problem with this one however, is that when you have 1000 orders, the order number will be: BE2021100 Because the last 0 is the 10th characters... Share this post Link to post Share on other sites More sharing options...
mr_absinthe Posted December 7, 2021 Posted December 7, 2021 That is why you would be better to use this: {BE}{order->date_add:%4.4s}{order->id:%04d:last:3} and you'll get BE2021000 or even better {BE}{order->date_add:%4.4s:last:2}{order->id:%05d:last:5} which should give you BE211000 and if you reach 10000 orders, you're safe: BE2110000 Share this post Link to post Share on other sites More sharing options...
Max Clee Posted January 10 Posted January 10 Hi @muynck Thanks for solving a age old problem 😉 its really big step forward would be possible create an field to full up manually in order ? I asking because i have a very special customer who wants his own number .... ;( could you help me or give some tip how to do this ? Share this post Link to post Share on other sites More sharing options...
redrum Posted January 10 Posted January 10 Sorry for not being able to check the latest post until now @mr_absinthe. I haven't looked at the latest releases of this module, but I don't think they have added the code I posted with the possibility to fetch the last characters. That's probably why it stopped working after you did an update of the module. Share this post Link to post Share on other sites More sharing options...
mr_absinthe Posted January 11 Posted January 11 Never mind that, my fix above is working just fine 😉 Share this post Link to post Share on other sites More sharing options...
muynck Posted January 11 Posted January 11 18 hours ago, Max Clee said: Hi @muynck Thanks for solving a age old problem 😉 its really big step forward would be possible create an field to full up manually in order ? I asking because i have a very special customer who wants his own number .... ;( could you help me or give some tip how to do this ? I don't know what you mean by "create an field to full up manually"? Share this post Link to post Share on other sites More sharing options...
redrum Posted January 11 Posted January 11 On 12/7/2021 at 5:39 PM, mr_absinthe said: That is why you would be better to use this: {BE}{order->date_add:%4.4s}{order->id:%04d:last:3} and you'll get BE2021000 or even better {BE}{order->date_add:%4.4s:last:2}{order->id:%05d:last:5} which should give you BE211000 and if you reach 10000 orders, you're safe: BE2110000 Cool! Hopefully that code will be added in future releases.@muynck Perhaps you should take a look at these two post and include that feature in the next release. and Share this post Link to post Share on other sites More sharing options...
muynck Posted January 12 Posted January 12 @redrum @mr_absinthe Please create pull request mentioning this issue (create one if it does not exist yet). I will approve, merge, and release it! Thanks! Share this post Link to post Share on other sites More sharing options...
kaleske Posted April 25 Posted April 25 Hello does this module compatible with prestashop 1.7.8.5? Share this post Link to post Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now