buckaroo-it / Magento2

Repository containing the Magento2 plugin by Buckaroo
MIT License
28 stars 35 forks source link

The shipping information was unable to be saved. Error: "Invalid customer address id 123456" #366

Closed Shiriaev closed 3 years ago

Shiriaev commented 3 years ago

The error appear in the cart when you cancel your order on payment gateway page and then return to cart.

Step to reproduce:

  1. Go to the store
  2. Login or create an account
  3. Add some product to the cart
  4. Place an order via some Buckaroo payment like IDEAL with 'failed' status
  5. Go to the first checkout step again
  6. Click on 'Next' button
  7. Pay attention that the error is shown and customer is not able to proceed to the next step

The reason for this behavior lies in the quote activation mechanism after an order is placed and then cancelled.

After order cancellation on the payment gateway, the user is redirected to the controller \Buckaroo\Magento2\Controller\Redirect\Process, where the quota of cancelled order is duplicated.

The duplicate process in the \Buckaroo\Magento2\Service\Sales\Quote\Recreate::duplicate creates a guest quote which is then merged with the cancelled order quote. As a result, in the new quote customer_is_guest = 1 (apparently, this is a consequence of the merge mechanism), which is the reason for the error. In this case address can not pass the validation in \Magento\Quote\Model\QuoteAddressValidator::validateForCart

As a quick fix, we can get sustomer_is_guest value and set it to the new quote in \Buckaroo\Magento2\Service\Sales\Quote\Recreate::duplicate:

$oldQuote = $this->quoteFactory->create()->load($order->getQuoteId());
$emptyQuoteId = $this->quoteManagement->createEmptyCart();
$quote = $this->quoteFactory->create()->load($emptyQuoteId);
$quote->setCustomerIsGuest($oldQuote->getCustomerIsGuest());
$quote->merge($oldQuote)->save();
$this->recreate(false, $quote);

return $quote;
vladislav-padalka-hys commented 3 years ago

Good afternoon Pavel !

Yeah, we know about this issue which has appeared in 1.38.0 We're already in process of fixing this and issue is related not only to guest flag you've mentioned.

Anyway, thanks a lot for your advise !

vladislav-padalka-hys commented 3 years ago

Good morning Pavel !

The fix has been released within scope of https://github.com/buckaroo-it/Magento2/releases/tag/v1.38.1

Thanks again for addressing that issue to us !