4

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 Dec 1 '16 at 9:08
  • @magentotwo No I am Not able to do this, do You have solution or you want solution for this ? – Murtuza Zabuawala Dec 1 '16 at 9:11
  • I want solution for this? – Bojjaiah Dec 1 '16 at 9:15
  • @magentotwo Sorry brother I am not able to find solution for this – Murtuza Zabuawala Dec 1 '16 at 9:16
  • @magentotwo You can ask new question and put this question link as reference may be someone help you out – Murtuza Zabuawala Dec 1 '16 at 9:20
4

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 Jan 23 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 – Fabian Schmengler Jan 23 at 21:12
  • Magento is so ambitious in concepts, then so badly driven... I've ended adding one more after plugin. – dudzio Jan 25 at 19:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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