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

Invalid state change requested - Checkout as customer #171

Closed
RickVendic opened this issue May 24, 2018 · 19 comments
Closed

Invalid state change requested - Checkout as customer #171

RickVendic opened this issue May 24, 2018 · 19 comments

Comments

@RickVendic
Copy link

Error message
Invalid state change requested

Reproduce

  • staging.[***].nl
  • Create account + log in
  • Add product to cart
  • Go to checkout

Errlog message
[2018-05-----] main.CRITICAL: Can't get setting with path:myparcelnl_magento_checkout/general/shipping_methods [] []

@RichardPerdaan
Copy link
Member

Hi @RickVendic,

Thank you for reporting the issue.
Which version of MyParcel plugin do you have?
Is the error only visible if the user is logged in?
Would you like to test the same actions, but with all shipping options that are possible.

@RickVendic
Copy link
Author

Hi @RichardPerdaan

Version 2.3.3
The error is only visible when customers are logged in.
None of the shipment options is visible
You can try it at staging.heevis.nl

@RichardPerdaan
Copy link
Member

Hi @RickVendic,

Can you try version 2.3.4 of the MyParcel plugin. If you are using composer you can update the version with the following command:

  • composer require myparcelnl/magento "~2.3.4"
  • rm -rf var/di/; rm -rf pub/static/; rm -rf var/cache/; rm -rf var/pagecache/; rm -rf var/generation/; rm -rf var/dir/; rm -rf var/view_preprocessed/*; php bin/magento cache:flush && php bin/magento setup:upgrade && php bin/magento setup:static-content:deploy && php bin/magento setup:static-content:deploy nl_NL && php bin/magento indexer:reindex

@RickVendic
Copy link
Author

Hi @RichardPerdaan , the problem still occurs on 2.3.4-beta-2

By the way, on Magento 2.2.x rm -rf var/generation has changed to rm -rf generated/*.

@RichardPerdaan
Copy link
Member

Hi @RickVendic,

Thank you for testing the new version. I will test this on my test environment. When I found something, you will hear from me.

@RickVendic
Copy link
Author

Hi @RichardPerdaan

I haven't heard back from you, are there any updates about this Bug?
Thank you.

@RichardPerdaan
Copy link
Member

RichardPerdaan commented Jun 8, 2018

Hi @RickVendic,

Will you try to enable all MyParcel shipping methods options and save the settings. Than you can try if the problems are solved.

configuration settings stores magento admin 2018-06-08 10-27-22

@RickVendic
Copy link
Author

HI @RichardPerdaan
We have updated the module to 2.3.4 and enabled all shipping options. The error still occurs.

@Kroellie
Copy link
Contributor

Hi @RickVendic: I had the same issue, do you happen to have an OSC extension installed as I see Mageplaza in your menu bar?

@RickVendic
Copy link
Author

Hi @Kroellie No, we are using the native Magento checkout. The screenshot is not from our installation.

@Kroellie
Copy link
Contributor

Oh well, in any case we did use OSC. Our invalid state change error was related to a change of permissions thingie in Magento 2.2.4. It tried to do a 'customer' activity on the quote, while in fact the user was still 'guest'. Maybe it helps looking in the right direction.

@RichardPerdaan
Copy link
Member

This problem is solved in version 2.3.5-beta.2 of the MyParcel plugin.

@Akki-8388
Copy link

Hi @Kroellie I have same issue in my OSC module and when i checkout with guest that problem occurred .

@RichardPerdaan
Copy link
Member

Hi @Akki-8388,

Is this a problem with the MyParcel plugin or with the OSC module. When it is a issue with the MyParcel plugin than I would like to know which version of the MyParcel plugin and the SDK you have installed.

@Akki-8388
Copy link

Hi @Kroellie,

The problem with the OSC module.

@sky-hub
Copy link

sky-hub commented Oct 21, 2019

Steps to reproduce:

  1. Enable checkout as guest
  2. Enable persistent shopping cart
  3. Create customer account
  4. Login to customer account
  5. Add product to cart
  6. Go to checkout
  7. Edit PHPSESID cookie and set a different value; or delete the cookie. Main idea is to get a different session (as if your current session expired for various reasons), meaning you wil no longer be logged in but persistence will keep your current customer data.
  8. Refresh page. If redirected to empty cart use minicart to go back to back to checkout. May have to try multiple times, sometimes it does not work from the first try.
  9. Fill checkout form data and place order
    1. At first try you will receive "Invalid state change requested"
    2. For later tries you will receive "Invalid state change requested" but the order email confirmation will be sent and order rolled back because the transaction fails.

Issue:

  1. Method beforeSave() from Magento\Quote\Model\Quote checks if current quote has customer assigned and if YES it will assign customer_id even if customer_id was set to null in \Magento\Persistent\Model\QuoteManager::convertCustomerCartToGuest

Solutions:

  1. Create a before plugin for \Magento\Persistent\Model\QuoteManager::convertCustomerCartToGuest and assign an empty customer object to quote.

@anil90
Copy link

anil90 commented Jan 14, 2020

hi @sky-hub

Can you explain the solution again. Do you have code to put in that plugin?

@anil90
Copy link

anil90 commented Jan 18, 2020

hi @sky-hub

I think the solution you have mention above is not working.
I changed \Magento\Persistent\Model\QuoteManager::convertCustomerCartToGuest function and assign empty object to quote and still few orders are missing.

I can see my logs so i assume my code executed while order went missing with error "Invalid state change requested"

public function convertCustomerCartToGuest()
{
    $quoteId = $this->checkoutSession->getQuoteId();
    /** @var $quote \Magento\Quote\Model\Quote */
    $quote = $this->quoteRepository->get($quoteId);
    if ($quote && $quote->getId()) {
        $writer = new \Zend\Log\Writer\Stream(BP . '/var/log/convertguestcodecalled.log');
        $logger = new \Zend\Log\Logger();
        $logger->addWriter($writer);

        $logger->info("Called now" );
        $logger->info("Quote id:" . $quote->getId() );

        $this->_setQuotePersistent = false;
        $this->_customer = $this->customerDataFactory->create();
        $this->_customer->setId(null);

        $quote->setIsActive(true)
            ->setCustomerId(null)
            ->setCustomerEmail(null)
            ->setCustomerFirstname(null)
            ->setCustomerLastname(null)
            ->setCustomerGroupId(\Magento\Customer\Api\Data\GroupInterface::NOT_LOGGED_IN_ID)
            ->setIsPersistent(false)
            ->setCustomer($this->_customer);

        $quote->getAddressesCollection()->walk('setCustomerAddressId', ['customerAddressId' => null]);
        $quote->getAddressesCollection()->walk('setCustomerId', ['customerId' => null]);
        $quote->getAddressesCollection()->walk('setEmail', ['email' => null]);
        $quote->collectTotals();
        $this->persistentSession->getSession()->removePersistentCookie();
        $this->quoteRepository->save($quote);
    }
}

Can you point out if i am missing something here.

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

6 participants