WSOD when removing item from cart in combination with currency resolver module.

Created on 12 August 2021, almost 3 years ago
Updated 6 December 2023, 7 months ago

Describe your bug or feature request.

Whenever I remove an item (the only item) that's in the cart using remove button, I am receiving a WSOD.
This happens only if I switch the currency mid way using currency resolver block (more details below).
Here's the error:

The website encountered an unexpected error. Please try again later.
TypeError: Argument 1 passed to Drupal\commerce_cart\CartManager::removeOrderItem() must implement interface Drupal\commerce_order\Entity\OrderInterface, null given, called in C:\wamp64\www\modules\contrib\commerce\modules\cart\src\Plugin\views\field\RemoveButton.php on line 121 in Drupal\commerce_cart\CartManager->removeOrderItem() (line 156 of modules\contrib\commerce\modules\cart\src\CartManager.php).
Drupal\commerce_cart\CartManager->removeOrderItem(NULL, Object) (Line: 121)
Drupal\commerce_cart\Plugin\views\field\RemoveButton->viewsFormSubmit(Array, Object) (Line: 188)
Drupal\views\Form\ViewsFormMainForm->submitForm(Array, Object) (Line: 187)
Drupal\views\Form\ViewsForm->submitForm(Array, Object)
call_user_func_array(Array, Array) (Line: 113)
Drupal\Core\Form\FormSubmitter->executeSubmitHandlers(Array, Object) (Line: 51)
Drupal\Core\Form\FormSubmitter->doSubmitForm(Array, Object) (Line: 593)
Drupal\Core\Form\FormBuilder->processForm('views_form_commerce_cart_form_default_96', Array, Object) (Line: 321)
Drupal\Core\Form\FormBuilder->buildForm(Object, Object) (Line: 219)
Drupal\Core\Form\FormBuilder->getForm(Object, Object, Array) (Line: 2258)
Drupal\views\Plugin\views\display\DisplayPluginBase->elementPreRender(Array)
call_user_func_array(Array, Array) (Line: 101)
Drupal\Core\Render\Renderer->doTrustedCallback(Array, Array, 'Render #pre_render callbacks must be methods of a class that implements \Drupal\Core\Security\TrustedCallbackInterface or be an anonymous function. The callback was %s. See https://www.drupal.org/node/2966725', 'exception', 'Drupal\Core\Render\Element\RenderCallbackInterface') (Line: 786)
Drupal\Core\Render\Renderer->doCallback('#pre_render', Array, Array) (Line: 377)
Drupal\Core\Render\Renderer->doRender(Array) (Line: 449)
Drupal\Core\Render\Renderer->doRender(Array) (Line: 449)
Drupal\Core\Render\Renderer->doRender(Array, ) (Line: 201)
Drupal\Core\Render\Renderer->render(Array, ) (Line: 241)
Drupal\Core\Render\MainContent\HtmlRenderer->Drupal\Core\Render\MainContent\{closure}() (Line: 578)
Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 242)
Drupal\Core\Render\MainContent\HtmlRenderer->prepare(Array, Object, Object) (Line: 132)
Drupal\Core\Render\MainContent\HtmlRenderer->renderResponse(Array, Object, Object) (Line: 90)
Drupal\Core\EventSubscriber\MainContentViewSubscriber->onViewRenderArray(Object, 'kernel.view', Object)
call_user_func(Array, Object, 'kernel.view', Object) (Line: 142)
Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher->dispatch(Object, 'kernel.view') (Line: 163)
Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 80)
Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 57)
Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 47)
Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 50)
Drupal\ban\BanMiddleware->handle(Object, 1, 1) (Line: 47)
Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 52)
Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 23)
Stack\StackedHttpKernel->handle(Object, 1, 1) (Line: 716)
Drupal\Core\DrupalKernel->handle(Object) (Line: 19)

If a bug, provide steps to reproduce it from a clean install.

Commerce Core 2.25
Commerce Currency Resolver 1.60
(I have internal page cache disabled, if that matters, I had to disable it to make currency resolver work for anonymous users).
The currency resolver is set to work on Cookie (currency block selector).

I am testing an item, 1000EUR worth \( ^_^ )/

1. Adding it to the cart using a user (regardless if it's just authenticated user or superadmin). (NOTE: if I remove the item at this point, it works fine).

I have a Currency Resolver block at the bottom, in the footer area. The item is displayed in EUR.

2. I click on the currency resolver and change from EUR to USD (if I go the other way it's same result).
3. Ok, now I want to remove the item, after the currency change.
4. WSOD (the one included above).

NOTE:
The WSOD happens only whenever I click on the remove button. BUT, if instead of Just put 0 instead of 1 in the items number. That clears the cart without any error.

So yeah, big think.
Hope you guys can figure this one out. For now I will try to make a button myself that would change number of items to 0 as a workaround.

UPDATE:
Did some more testing.
Just to add here.

The error does not happen if I change the currency prior to actually adding the item to the cart. It happens only if I change currency with the item already in the cart.

Also, promotion does not affect this. I have tested without the discount and the same error shows up.

πŸ› Bug report
Status

Active

Version

1.0

Component

Code

Created by

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡ΉπŸ‡·Turkey RgnYLDZ

    I also have a similar issue. Probably related or same. I have multiple currencies. The button patch does not work.

    When I remove all products from cart the site gives WSOD and the error message in logs.

    Error: Call to a member function getCurrencyCode() on null in Drupal\commerce_currency_resolver\EventSubscriber\CurrencyOrderRefresh->checkCurrency() (line 87 of /home/keratai2/public_html/newjoy.com/web/modules/contrib/commerce_currency_resolver/src/EventSubscriber/CurrencyOrderRefresh.php).

  • πŸ‡¬πŸ‡§United Kingdom Londova

    I have the same error.
    It is storage to see that this error was registered for over 2 years ago?!

  • πŸ‡¬πŸ‡§United Kingdom Londova

    One more issue to report here.
    The "currency conversion" is not working for Shopping Cart (see the image attached)

  • πŸ‡¬πŸ‡§United Kingdom Londova

    (3) One more error to report here:
    I use 3 currencies on one of my trial sites: GBP, EUR, BGN.
    However the following error is logged when I tried to use the option "Currency converter price" in
    Product variation types -> Default -> Manage display -> Price
    ---
    Drupal\commerce_exchanger\Exception\ExchangeRatesDataMismatchException: There are no exchange rates set for GBP and USD in Drupal\commerce_exchanger\AbstractExchangerCalculator->priceConversion() (line 87 of /modules/commerce_exchanger/src/AbstractExchangerCalculator.php).
    ---
    we don't use currency USD at all, so why such error appears here?

Production build 0.69.0 2024