Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't place order because Sequence::getNextValue() crashes #3066

Closed
tdgroot opened this issue Jan 21, 2016 · 17 comments
Closed

Can't place order because Sequence::getNextValue() crashes #3066

tdgroot opened this issue Jan 21, 2016 · 17 comments
Labels
bug report Component: Checkout Fixed in 2.1.x The issue has been fixed in 2.1 release line Fixed in 2.2.x The issue has been fixed in 2.2 release line Issue: Format is not valid Gate 1 Failed. Automatic verification of issue format is failed Issue: Ready for Work Gate 4. Acknowledged. Issue is added to backlog and ready for development

Comments

@tdgroot
Copy link
Member

tdgroot commented Jan 21, 2016

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?

@quynhvv
Copy link

quynhvv commented Feb 3, 2016

@Desmaster : That issue because have some new work flow of sales module in Magento 2.
and your database migrated is multiple stores
and it's missing needed tables for module-sales and module-sales-sequence.
You can see more at this: http://i.imgur.com/rkFvbC8.png
=> That are initial tables after you install a fresh Magento 2.
and after migrate data with this tool, you database was missing some tables for other stores (not default store)
See more: https://mage2.pro/t/topic/511
Regards
Mall.

@redboxmarcins
Copy link

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

@ilol
Copy link

ilol commented May 10, 2016

MAGETWO-52506

@victor-v-rad
Copy link
Contributor

Sorry for late reply. I assume you did not migrate settings before data migration
php bin/magento migrate:settings

@redboxmarcins
Copy link

@victor-v-rad - no I didn't migrate settings - is there any reference in the settings migration to recreate sequence tables?

@NadiyaS NadiyaS added Issue: Ready for Work Gate 4. Acknowledged. Issue is added to backlog and ready for development MX and removed CS labels Jun 8, 2016
@NadiyaS NadiyaS removed their assignment Jun 8, 2016
@victor-v-rad
Copy link
Contributor

When you migrate settings you migrate stores and websites. Skipping this probably causes the issue with sequence tables. Please stick close to the official documentation

@redboxmarcins
Copy link

@victor-v-rad thanks for the tip, I will try that and check

I was looking in the code and the Settings Step actually is copying data between core_config_data tables only - unless I miss something obvious

https://github.com/magento/data-migration-tool/blob/master/src/Migration/Step/Settings/Data.php

@victor-v-rad
Copy link
Contributor

See in
https://github.com/magento/data-migration-tool/blob/master/etc/ce-to-ce/1.9.2.3/config.xml.dist
Settings mode consist of Settings Step and Stores Step

@redboxmarcins
Copy link

Thanks for pointing that, Settings mode consists of two steps - settings and stores

So actual task is here - https://github.com/magento/data-migration-tool/blob/master/src/Migration/Step/Stores/Data.php#L66

But again - this is just simple data copy between 3 tables hardcoded in helper
https://github.com/magento/data-migration-tool/blob/master/src/Migration/Step/Stores/Helper.php

Still don't see how sequence tables will be created by this step

@victor-v-rad please advice

@victor-v-rad
Copy link
Contributor

Sequence tables are created here \Migration\Step\SalesIncrement\Data::createSequenceTable

@redboxmarcins
Copy link

@victor-v-rad thanks - that's fine, but what if someone is not actually want to migrate orders?
Looks like there should be some dependencies betweens modes/steps

What do you think?

@victor-v-rad
Copy link
Contributor

Dependencies exist. You cannot migrate only orders by the tool out of the box

@redboxmarcins
Copy link

@victor-v-rad I think you mean opposite - that you need to migrate orders always to make sure that sequence tables are generated

@firestorm23
Copy link

I got this bug without any "migrate" operations. I just created second store for tutorial tasks and this bug occured.

@alexnos88
Copy link

please use one of the following:

  • either dispatch an event after you create the store view (store_type = 'store')

    $this->_eventManager->dispatch('store_add', ['store' => $storeModel]);

    where $storeModel is 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

    foreach ($this->entityPool->getEntities() as $entityType) {
    $this->sequenceBuilder->setPrefix($storeId)
        ->setSuffix($this->sequenceConfig->get('suffix'))
        ->setStartValue($this->sequenceConfig->get('startValue'))
        ->setStoreId($storeId)
        ->setStep($this->sequenceConfig->get('step'))
        ->setWarningValue($this->sequenceConfig->get('warningValue'))
        ->setMaxValue($this->sequenceConfig->get('maxValue'))
        ->setEntityType($entityType)
        ->create();
    }

    where $storeId is 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.

@csdougliss
Copy link
Contributor

@victor-v-rad my development database does not have any orders in it due to PCI complaince. The sequence tables for stores > 1 are never created.

@magento-engcom-team magento-engcom-team added Issue: Ready for Work Gate 4. Acknowledged. Issue is added to backlog and ready for development bug report Component: Checkout Issue: Format is not valid Gate 1 Failed. Automatic verification of issue format is failed labels Sep 11, 2017
@magento-engcom-team
Copy link
Contributor

Hi @tdgroot the issued has been fixed in 2.1.8. Please, let us know if you still have the issue

@magento-engcom-team magento-engcom-team added Fixed in 2.1.x The issue has been fixed in 2.1 release line Fixed in 2.2.x The issue has been fixed in 2.2 release line labels Oct 6, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug report Component: Checkout Fixed in 2.1.x The issue has been fixed in 2.1 release line Fixed in 2.2.x The issue has been fixed in 2.2 release line Issue: Format is not valid Gate 1 Failed. Automatic verification of issue format is failed Issue: Ready for Work Gate 4. Acknowledged. Issue is added to backlog and ready for development
Projects
None yet
Development

No branches or pull requests