magento2: Can't place order because Sequence::getNextValue() crashes
Some information good to know:
- I “successfully” ported a Magento 1.7.x database to Magento 2. Everything works so far, except the order creation, which, is a showstopper.
- The following information is as far as I could get, but I simply don’t have enough Magento 2 experience yet to find out what’s going wrong.
The method Magento\SalesSequence\Model\Sequence->getNextValue() crashes.
It looks like this:
public function getNextValue()
{
$this->connection->insert($this->meta->getSequenceTable(), []);
$this->lastIncrementId = $this->connection->lastInsertId($this->meta->getSequenceTable());
return $this->getCurrentValue();
}
$this->meta->getSequenceTable() returns NULL, causing the adapter to do the following:
INSERT INTO `` () VALUES ()
This obviously doesn’t work, thus the whole order creation crashes.
What could possibly cause $this->meta->getSequenceTable() to return NULL?
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Reactions: 4
- Comments: 17 (7 by maintainers)
I got this bug without any “migrate” operations. I just created second store for tutorial tasks and this bug occured.
please use one of the following:
either dispatch an event after you create the store view (store_type = ‘store’)
where
$storeModelis your \Magento\Store\Model\Store which has been saved now. This only works if you create store view for the first time.or you can run the code which is executing in \vendor\magento\module-sales-sequence\Observer\SequenceCreatorObserver.php
where
$storeIdis the id of your newly created store view. This is also useful if you have already created your store views and want to fix them.All required DIs can be found in the file mentioned above.
Completely agree here in my opinion it is dangerous that \Magento\SalesSequence\Model\Sequence::getNextValue() is relaying on $this->meta->getSequenceTable() being always populated.
\Magento\SalesSequence\Model\ResourceModel\Meta::loadByEntityTypeAndStore() is feeding data to \Magento\SalesSequence\Model\Manager
getSequence() method should throw Exception if meta is not found