I am trying to find a solution to add different prefix on invoice number based on payment method.


  • Invoice for order with credit card payment => CC as prefix
  • Invoice for order with checkout money => CM as prefix

How can I manage this?

1 Answer 1


You need to work on the below methods:

  1. \Magento\Sales\Model\ResourceModel\Order::_beforeSave
  2. \Magento\Sales\Model\ResourceModel\EntityAbstract::_beforeSave

I think you have to override the above methods.

nameSpace Vendor\Module\Model;

use Magento\Sales\Model\EntityInterface;

class Order extends \Magento\Sales\Model\ResourceModel\Order
    protected function _beforeSave(\Magento\Framework\Model\AbstractModel $object)
        $parentResult =  parent::_beforeSave($object);
            /** @var \Magento\Sales\Model\AbstractModel $object */
            if ($object instanceof EntityInterface && $object->getEntityId() == null && $object->getIncrementId() != null) {
                $coreIncrement = $object->getIncrementId();
        return $parentResult;
  • Hello. I need to add a prefix based on payment method. Can you elaborate more?
    – andy1786
    Commented Dec 7, 2020 at 19:15

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.