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?
Magento Stack Exchange is a question and answer site for users of the Magento e-Commerce platform. It only takes a minute to sign up.
Sign up to join this communityI am trying to find a solution to add different prefix on invoice number based on payment method.
Example:
How can I manage this?
You need to work on the below methods:
\Magento\Sales\Model\ResourceModel\Order::_beforeSave
\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;
}
}