Description
Preconditions
Ubuntu, Standard LAMP (Apache, MySQL, ....)
Magento ver. 2.1.9 - Clean setup by command line
PHP 7.0.8-0ubuntu0.16.04.3 (cli) ( NTS )
Copyright (c) 1997-2016 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2016 Zend Technologies
mysql Ver 14.14 Distrib 5.7.17, for Linux (x86_64) using EditLine wrapper
Steps to reproduce
Magento Store Configuration
The magento store has been configured as multistore with multiviews.
- Store A
- Store View Italian (default) - id:1 - invoice prefix: S-
- Store View English - id:3 - invoice prefix: SS-
- Store B
- Store View Italian (default) - id:2 - invoice prefix: Z-
- Store View English - id:4 - invoice prefix: ZZ-
I have discovered that Magento 2 set the DefaultStoreId in the second getSequence() parameter but this is not good if you need to set a correct prefix for the invoices. Look at https://github.com/magento/magento2/blob/2.2-develop/app/code/Magento/Sales/Model/ResourceModel/EntityAbstract.php#L129
If create an order from the administration panel for the Store B English Store View you'll get the Default Store Id equals to 2 but the correct value is 4.
Expected result
I would like to set the correct invoice prefix when I try to create a new invoice from a specific store view.
Actual result
Magento creates the invoice number using the default store view id
I suggest to change the storeid parameter:
protected function _beforeSave(\Magento\Framework\Model\AbstractModel $object)
{
/** @var \Magento\Sales\Model\AbstractModel $object */
if ($object instanceof EntityInterface && $object->getIncrementId() == null) {
$object->setIncrementId(
$this->sequenceManager->getSequence(
$object->getEntityType(),
$object->getStore()->getId() // <<< This parameter will be get from the invoice object
)->getNextValue()
);
}
parent::_beforeSave($object);
return $this;
}
thanks