diff --git a/app/code/Magento/Sales/Model/Increment.php b/app/code/Magento/Sales/Model/Increment.php index daf27575351ac..6c3f8f7472ff3 100644 --- a/app/code/Magento/Sales/Model/Increment.php +++ b/app/code/Magento/Sales/Model/Increment.php @@ -22,6 +22,11 @@ class Increment */ protected $incrementValue; + /** + * @var string + */ + protected $entityType; + /** * @param EavConfig $eavConfig */ @@ -40,6 +45,16 @@ public function getCurrentValue() { return $this->incrementValue; } + + /* + * Sets the entity type + * @param string $entityType + * @return Magento\Sales\Model\Increment + */ + public function setEntityType($entityType){ + $this->entityType = $entityType; + return $this; + } /** * Returns new value of increment id @@ -51,8 +66,13 @@ public function getCurrentValue() */ public function getNextValue($storeId) { + if(empty($this->entityType)){ + throw new \Magento\Framework\Model\Exception( + __('EntityType is empty') + ); + } $this->incrementValue = - $this->eavConfig->getEntityType(Order::ENTITY)->fetchNewIncrementId($storeId); + $this->eavConfig->getEntityType($this->entityType)->fetchNewIncrementId($storeId); return $this->incrementValue; } } diff --git a/app/code/Magento/Sales/Model/Resource/Entity.php b/app/code/Magento/Sales/Model/Resource/Entity.php index 2cc6faf6f1266..f9782ca4c0dff 100644 --- a/app/code/Magento/Sales/Model/Resource/Entity.php +++ b/app/code/Magento/Sales/Model/Resource/Entity.php @@ -96,7 +96,7 @@ public function saveAttribute(\Magento\Framework\Model\AbstractModel $object, $a protected function _beforeSave(\Magento\Framework\Model\AbstractModel $object) { if ($object instanceof EntityInterface && $object->getIncrementId() == null) { - $object->setIncrementId($this->salesIncrement->getNextValue($object->getStoreId())); + $object->setIncrementId($this->salesIncrement->setEntityType($object->getEntityType())->getNextValue($object->getStoreId())); } parent::_beforeSave($object); return $this;