My client wants the current month and year as a prefix in order numbers. I have read many blogs but they are all for static prefix for order number.

I am looking for a solution in Magento 2.

  • have you done this?
    – Bojjaiah
    Commented Dec 1, 2016 at 9:08
  • @magentotwo No I am Not able to do this, do You have solution or you want solution for this ? Commented Dec 1, 2016 at 9:11
  • I want solution for this?
    – Bojjaiah
    Commented Dec 1, 2016 at 9:15
  • @magentotwo Sorry brother I am not able to find solution for this Commented Dec 1, 2016 at 9:16
  • @magentotwo You can ask new question and put this question link as reference may be someone help you out Commented Dec 1, 2016 at 9:20

1 Answer 1


You can do that with a custom increment model.

You can read about increment models here: How to set order increment id iterator in magento 1?

In Magento 2, the implementation is still the same. In your case, you would extend Magento\Eav\Model\Entity\Increment\NumericValue and add a getPrefix() method to implement your custom prefix:

namespace Stack\OrderNumber\Model\Entity\Increment;

use Magento\Eav\Model\Entity\Increment\NumericValue;
class DatePrefix extends NumericValue
    public function getPrefix()
        return \date('m-y');

Then update increment_model for orders in the eav_entity_type table and change it from Magento\Eav\Model\Entity\Increment\NumericValue to your model (e.g. Stack\OrderNumber\Model\Entity\Increment\DatePrefix)

  • Does it actually works for you for Magento 2? I've added breakpoints on all Increment* classes, created new one and set it for the order entity. The interpeter doesn't even walks into those classes.
    – dudzio
    Commented Jan 23, 2019 at 19:46
  • You're right, it's different now, at least in Magento 2.2 Commerce. I recently had to look into it, will try to update the answer accordingly. Remind me if I don't get back in the next days Commented Jan 23, 2019 at 21:12
  • Magento is so ambitious in concepts, then so badly driven... I've ended adding one more after plugin.
    – dudzio
    Commented Jan 25, 2019 at 19:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.