RemoveFromCartEvent occasionally WSOD

Created on 29 February 2024, 4 months ago
Updated 30 April 2024, 2 months ago

Problem/Motivation

Users occasionally hit a situation where the store is not loaded and a cart item is removed from their cart.
When this happens the users experiences a WSOD with the following error:

Error: Call to a member function getStore() on null in Drupal\google_tag\Plugin\GoogleTag\Event\Commerce\RemoveFromCartEvent->getData() (line 43 of /app/web/modules/contrib/google_tag/src/Plugin/GoogleTag/Event/Commerce/RemoveFromCartEvent.php).

Steps to reproduce

I've not been able to reproduce this myself.

Proposed resolution

Check if $order_item->getOrder()->getStore()->label() returns an order before checking for the store.

Remaining tasks

Provide merge request.

User interface changes

N/A

API changes

N/A

Data model changes

N/A

🐛 Bug report
Status

Needs work

Version

2.0

Component

Code

Created by

🇺🇸United States nicxvan

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

Merge Requests

Comments & Activities

  • Issue created by @nicxvan
  • Assigned to abhishek_virasat
  • Issue was unassigned.
  • Status changed to Needs review 4 months ago
  • Open in Jenkins → Open on Drupal.org →
    Core: 10.2.x + Environment: PHP 8.1 & MySQL 5.7
    last update 4 months ago
    53 pass, 1 fail
  • 🇮🇳India abhishek_virasat

    @nicxvan , I have fixed the issue and created Patch

  • The last submitted patch, 3: google_tag-3424695.patch, failed testing. View results
    - codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

  • 🇺🇸United States nicxvan

    Is there any chance you can put that into a merge request?

    I did some local testing I have not pushed up yet and I think there is a simpler fix where we assert the order is an Drupal\commerce_order\Entity\OrderInterface rather than just asserting it is !null.

  • 🇩🇪Germany Anybody Porta Westfalica

    I think this should be checked and solved in combination with the other commerce related issues?

  • 🇺🇸United States nicxvan

    I haven't been able to test this on my client yet, but just looking at the code this is not fixed:

    https://git.drupalcode.org/project/google_tag/-/blob/2.0.x/src/Plugin/Go...

    That line is what throws the error and there are no new protections.

    I think the patch does quite a bit more than needed, I think we just need to call:

    $order_item->getOrder()
    then assert that it's an OrderInterface before moving on.

    Nominally this patch seems to do the same, but rather than just exiting they try to pass as much info as exists.

    I think if the event is incomplete not sending the event is probably better, let me know which direction you would like to go.

  • 🇺🇸United States nicxvan

    Pushing a quick assertion as POC. I still need to review tests.

    I'm hiding the patch since it seems to make a lot of unnecessary changes.

  • Merge request !77Check for order → (Open) created by nicxvan
  • Open in Jenkins → Open on Drupal.org →
    Core: 10.2.x + Environment: PHP 8.1 & MySQL 5.7
    last update 3 months ago
    54 pass
  • 🇯🇴Jordan Ahmad Khader

    I'm having a similar issue but assert already exists there

    The website encountered an unexpected error. Please try again later.
    Error: Call to a member function subtract() on null in Drupal\google_tag\Plugin\GoogleTag\Event\Commerce\AddToCartEvent->getData() (line 44 of modules/contrib/google_tag/src/Plugin/GoogleTag/Event/Commerce/AddToCartEvent.php).
    Drupal\google_tag\Plugin\GoogleTag\Event\Commerce\AddToCartEvent->getData() (Line: 147)
    google_tag_page_attachments(Array) (Line: 315)
    Drupal\Core\Render\MainContent\HtmlRenderer->Drupal\Core\Render\MainContent\{closure}(Object, 'google_tag') (Line: 405)
    Drupal\Core\Extension\ModuleHandler->invokeAllWith('page_attachments', Object) (Line: 316)
    Drupal\Core\Render\MainContent\HtmlRenderer->invokePageAttachmentHooks(Array) (Line: 289)
    Drupal\Core\Render\MainContent\HtmlRenderer->Drupal\Core\Render\MainContent\{closure}() (Line: 580)
    Drupal\Core\Render\Renderer->executeInRenderContext(Object, Object) (Line: 290)
    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: 174)
    Symfony\Component\HttpKernel\HttpKernel->handleRaw(Object, 1) (Line: 81)
    Symfony\Component\HttpKernel\HttpKernel->handle(Object, 1, 1) (Line: 58)
    Drupal\Core\StackMiddleware\Session->handle(Object, 1, 1) (Line: 48)
    Drupal\Core\StackMiddleware\KernelPreHandle->handle(Object, 1, 1) (Line: 106)
    Drupal\page_cache\StackMiddleware\PageCache->pass(Object, 1, 1) (Line: 85)
    Drupal\page_cache\StackMiddleware\PageCache->handle(Object, 1, 1) (Line: 48)
    Drupal\Core\StackMiddleware\ReverseProxyMiddleware->handle(Object, 1, 1) (Line: 51)
    Drupal\Core\StackMiddleware\NegotiationMiddleware->handle(Object, 1, 1) (Line: 23)
    Stack\StackedHttpKernel->handle(Object, 1, 1) (Line: 718)
    Drupal\Core\DrupalKernel->handle(Object) (Line: 19)
Production build 0.69.0 2024