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 also using a promotion that's giving 10USD off for every purchase above 50USD, not sure if that's relevant.
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.
| Comment | File | Size | Author |
|---|---|---|---|
| #12 | shop-cart currecy.jpg | 44.31 KB | londova |
Comments
Comment #2
ShenHua commentedComment #3
ShenHua commentedComment #4
jsacksick commentedIf the bug occurs in combination with the Commerce currency resolver module, why don't you submit a bug report there?
Comment #5
ShenHua commentedBecause the error shows cart button as being at fault? Which is part of Commerce Core and not resolver?
It's ok, I will post the report there too, since you asked :)
UPDATE:
Oh, ok I see you moved it already. Thanks.
BTW I did one more test run.
One more thing I have learned:
1. add item to cart.
2. switch currency.
3. (this time if I click remove, I would get a WSOD)...
but let's not remove it, let's see what happens if I add something more.
4. Add one more item. You can even remove this new item.
Basically if I add one more item or remove the new item added after the "trigger" for WSOD in point 3. It kind of "unlocks" the arrangement, and then I am able to remove any item using remove button.
But if I only go to the point 3. And not add any other item after switching currency, then removing that item which was added prior to currency change, would trigger the WSOD.
Hope this information will prove useful.
UPDATE2:
After more testing. I found another way to "suppress" the error.
This workflow will NOT trigger this WSOD:
1. Add an item to shopping cart.
2. Change currency using currency resolver block.
3. (if we remove the item now, it would trigger WSOD).
4. Click "checkout"
5. Click "checkout review".
6. Go back to the shopping cart page.
7. Now you may remove the item without triggering the WSOD.
UPDATE3:
And this should really narrow down what's the issue here.
This workflow manually works around the issue:
1. Add an item to shopping cart.
2. Change currency using currency resolver block.
3. (if we remove the item now, it would trigger WSOD).
4. Instead, I open dev console in Chrome. And I manually adjust the value of the input field from 1 to 0. So it's like this:
<input class="quantity-edit-input form-number required" data-drupal-selector="edit-edit-quantity-0" type="number" id="edit-edit-quantity-0" name="edit_quantity[0]" value="0" step="1" min="0" max="9999" size="4" required="required" aria-required="true">(from value 1 to value 0).
5. I click the "remove" button. And there is no WSOD then.
NOTE: UPDATE 3 manual workaround works only if we don't trigger the WSOD but manually work around it while anticipating it.
UPDATE 2 "suppression" of the WSOD works even after the WSOD has already been triggered (as in, we tried to remove the item and it showed a WSOD).
Comment #6
a.sopkoHave same issue,
have found a way to temporary fix the issue, by altering Views plugin button
the problem is "$order_item->getOrder()" - returns NULL instead for Commerce Order Object
in this line
Comment #7
valicAre you using tax? Did manage to reproduce this issue, but only when tax had been used (regardless if commerce currency resolver is used)
Comment #8
valicTo be more specific, shipping tax plugin?
Comment #9
valicComment #10
rgnyldz commentedI 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).EDIT: I'm using Drupal10 and php 8.1
Comment #11
londova commentedI have the same error, I use multi-currencies.
It is strange to see this error exists for over 2 years ?!
Comment #12
londova commented(2) Another issue to report here.
The "currency conversion" is not working for Shopping Cart (see the image attached).
The Unit Price and Subtotal are displayed in EUR, while the TOTAL is in GBP (quite strange behaviour).
The currency selected is GBP.
Comment #13
londova commented(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?
Comment #14
djg_tram commentedThe problem is with the Commerce Cart module, it should be reported there. The
viewsFormSubmit()function simply grabs the order item from the view and this apparently means that if an order processor (not just this module but any order processor) modifies the order in the meantime, the cart will grab the wrong one.Comment #15
sjmcl commentedThat problem is caused by the order_id of the order items being set to null, as reported in this issue:
Stop unsetting the order ID reference from the order refresh
Applying the patch attached to the above issue solved this problem for me.