magento2: Checkout/Cart visit results in error (500) after update 2.2.1 -> 2.2.2

Preconditions

  1. Using magento 2.2.2 (updated from 2.2.1), none of the new features.
  2. php, mysql and other libraries current from vanilla ubuntu 16.04

Steps to reproduce

  1. Populate cart, visist https://shop/checkout/cart

Expected result

  1. Get served a cart page as in magento 2.2.1

Actual result

  1. Magento answers with a snippet of shipping stuff (in our case translated “Versandgebühren hier abrufen”) in a block-shipping div nicely wrapped in a HTTP 500 response. The log shows:
2017/12/12 20:56:09 [error] 13026#13026: *1925924 FastCGI sent in stderr: "PHP message: PHP Fatal error:  Uncaught TypeError: Argument 1 passed to Magento\Quote\Model\Cart\Totals::setExtensionAttributes() must be an instance of Magento\Quote\Api\Data\TotalsExtensionInterface, instance of Magento\Quote\Api\Data\AddressExtension given, called in /var/www/XXX/vendor/magento/framework/Api/DataObjectHelper.php on line 125 and defined in /var/www/XXX/vendor/magento/module-quote/Model/Cart/Totals.php:592
Stack trace:
#0 /var/www/XXX/vendor/magento/framework/Api/DataObjectHelper.php(125): Magento\Quote\Model\Cart\Totals->setExtensionAttributes(Object(Magento\Quote\Api\Data\AddressExtension))
#1 /var/www/XXX/vendor/magento/framework/Api/DataObjectHelper.php(85): Magento\Framework\Api\DataObjectHelper->_setDataValues(Object(Magento\Quote\Model\Cart\Totals), Array, 'Magento\\Quote\\A...')
#2 /var/www/XXX/vendor/magento/module-quote/Model/Cart/CartTotalRepository.php(103): Magento\Framework\Api\DataObjectHelper->popu" while reading response header from upstream, client: 127.0.0.1, server: XXX, request: "GET /checkout/cart/ HTTP/1.0", upstream: "fastcgi://unix:/var/run/php/php7.0-fpm.sock:", host: "XXX", referrer: "https://XXX/myproduct.html"

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Reactions: 8
  • Comments: 32 (7 by maintainers)

Most upvoted comments

I had the same issue and I have created a standalone magento module flancer32/mage2_fix_is12655 based on https://github.com/magento/magento2/commit/aa535e to fix it.

@JonnyStecchino, @mombrea, @friimaind, @fwolfst, @cmuench, @twa8000, @webazad, @darinda This was an issue which had been fixed since 2.1.7 but for some reason it was not merged to 2.2.*. Here is the fix for it https://github.com/magento/magento2/commit/aa535e.

I’ve created a temporary plugin to fix this, so you could also do the same.

Same issue here. Upon a closer look, I found some behavior in \Magento\Checkout\Model\TotalsInformationManagement that did not align with similar procedures in the quote module. See excerpt from this class below:

/**
 * {@inheritDoc}
 */
public function calculate(
    $cartId,
    \Magento\Checkout\Api\Data\TotalsInformationInterface $addressInformation
) {
    /** @var \Magento\Quote\Model\Quote $quote */
    $quote = $this->cartRepository->get($cartId);
    $this->validateQuote($quote);

    if ($quote->getIsVirtual()) {
        $quote->setBillingAddress($addressInformation->getAddress());
    } else {
        $quote->setShippingAddress($addressInformation->getAddress());
        $quote->getShippingAddress()->setCollectShippingRates(true)->setShippingMethod(
            $addressInformation->getShippingCarrierCode() . '_' . $addressInformation->getShippingMethodCode()
        );
    }
    $quote->collectTotals();

    return $this->cartTotalRepository->get($cartId);
}

I’m not sure if this is intentional or what the logic is behind this, but the last 2 lines should be re-evaluated, to consider the following:

  • This is the only place where I find totals collection without a wrapping call to save by the repository
  • The quote is presumably reloaded by the repository on the return statement

I was able to solve my issue in a way different from @flancer64 by changing the totals collection call like so:

    $this->cartRepository->save($quote->collectTotals()); 

Alternatively you could return the prepared quote itself instead of reloading from the repository, but I’m unsure of the intention/design of this method to commit a save back on the record. I’d like to hear some thoughts from those more familiar with the architecture here.

@ferrazzuk Awesome. confirm that fix works.

I have tested this on various versions, including 2.2.3 and 2.3-develop, and confirmed that this issue has been fixed. Below are the relevant pull requests:

Original fix in 2.1-develop (https://github.com/magento/magento2/commit/aa535e) Forwardport to 2.2-develop (https://github.com/magento/magento2ce/pull/1975/files) Forwardport to 2.3-develop (https://github.com/magento/magento2/pull/17620/files)

CC @okorshenko

In my case the issue appeared after update from 2.1.9 to 2.2.3, @flancer64 's fix worked.

Another confirmation that the issue exists and that @flancer64 's fix works perfectly.

Is there an estimated time for fix and release on this as its a pretty large issue, clearly affecting many people?

Thanks

Same issue here with 2.2.1 -> 2.2.3 @flancer64 is a star!

We are facing the same issues on upgrade from m2.2.1 -> m2.2.2. The module of @flancer64 works for me! Thanks

@fwolfst, thank you for your report. We’ve acknowledged the issue and added to our backlog.

I have this issue after upgrading to 2.2.2 as well. Only happens for logged in users. Creating a new user account works for a time and then starts failing.

With PHP errors on the last output is:

window.checkoutConfig = <br />
--
  | <b>Fatal error</b>:  Uncaught TypeError: Argument 1 passed to Magento\Quote\Model\Cart\Totals::setExtensionAttributes() must be an instance of Magento\Quote\Api\Data\TotalsExtensionInterface, instance of Magento\Quote\Api\Data\AddressExtension given, called in /var/www/clients/client3/web4/web/vendor/magento/framework/Api/DataObjectHelper.php on line 125 and defined in /var/www/clients/client3/web4/web/vendor/magento/module-quote/Model/Cart/Totals.php:592
  | Stack trace:
  | #0 /var/www/clients/client3/web4/web/vendor/magento/framework/Api/DataObjectHelper.php(125): Magento\Quote\Model\Cart\Totals-&gt;setExtensionAttributes(Object(Magento\Quote\Api\Data\AddressExtension))
  | #1 /var/www/clients/client3/web4/web/vendor/magento/framework/Api/DataObjectHelper.php(85): Magento\Framework\Api\DataObjectHelper-&gt;_setDataValues(Object(Magento\Quote\Model\Cart\Totals), Array, 'Magento\\Quote\\A...')
  | #2 /var/www/clients/client3/web4/web/vendor/magento/module-quote/Model/Cart/CartTotalRepository.php(103): Magento\Framework\Api\DataObjectHelper-&gt;populateW in <b>/var/www/clients/client3/web4/web/vendor/magento/module-quote/Model/Cart/Totals.php</b> on line <b>592</b><br />

Downgrading to 2.2.1 solved the problem.

I have this issue also if a payment failed after the customer returns to the cart page.