2

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

Example:

  • 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

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.

<?php
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();
                $object->setIncrementId('Yourvaluee');
            }
        return $parentResult;
    }
}
1
  • Hello. I need to add a prefix based on payment method. Can you elaborate more?
    – andy1786
    Dec 7, 2020 at 19:15

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.