Error: Call to a member function setDisplay() on null in ConfirmationMessageSubscriber->onAddToCart()

Created on 4 September 2023, 10 months ago
Updated 2 December 2023, 7 months ago

Problem/Motivation

The module installs an optional view confirm_message_product_display but in the code it assumes that the view is always available. If the view is not installed because its dependencies are not met, or if it is removed by a site builder, a fatal error occurs when an item is added to a cart.

Steps to reproduce

  1. Remove the confirm_message_product_display view.
  2. Add an item to the cart.

Result:

Error: Call to a member function setDisplay() on null in Drupal\commerce_add_to_cart_confirmation\EventSubscriber\ConfirmationMessageSubscriber->onAddToCart() (line 60 of modules/contrib/commerce_add_to_cart_confirmation/src/EventSubscriber/ConfirmationMessageSubscriber.php).

Proposed resolution

  • Check that the view is present before calling methods on it.
  • Show a message in the status report if the view is missing, with instructions on how to restore it.

User interface changes

None

API changes

None

Data model changes

None

πŸ› Bug report
Status

Fixed

Version

1.0

Component

Code

Created by

πŸ‡§πŸ‡¬Bulgaria pfrenssen Sofia

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

Merge Requests

Comments & Activities

Production build 0.69.0 2024