Error: Call to a member function getCurrencyCode() on null in Drupal\google_tag\Plugin\GoogleTag\Event\Commerce\ViewItemEvent->getData() (line 69 of modules/contrib/google_tag/src/Plugin/GoogleTag/Event/Commerce/ViewItemEvent.php).

This happens when products do not have a price.
So when this gets called comes back NULL resulting on white screen:
$item->getPrice()->getCurrencyCode()

Issue fork google_tag-3422723

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

jcontreras created an issue. See original summary.

abhishek_gupta1’s picture

Assigned: jcontreras » Unassigned
Status: Active » Reviewed & tested by the community

I cloned the repository from the mentioned version and verified it locally, Its working fine for me, moving RTBC++

djg_tram’s picture

Could we urge acceptance of the MR? A WSOD is, after all, quite serious a problem...

anybody’s picture

Priority: Normal » Major

I can confirm the error and WSOD! Please merge this and tag a new release asap! Thank you!

I'll add a similar MR fixing code style and solving this a bit shorter. Maintainer may decide which approach is better, but this definitely needs to be more defensive!

anybody’s picture

Status: Reviewed & tested by the community » Needs work

Just saw that there are various other cases with similar calls. On it!

anybody’s picture

Please note that $item->getPrice() may also return NULL:
@return \Drupal\commerce_price\Price|null — The price, or NULL.

For that reason, I also changed

protected function formatPriceNumber(?Price $price): string {

to accept null values and return 0.00 then! Otherwise, I think me might run into the next issue, if $price is NULL somewhere? Hope I wasn't too defensive now.

anybody’s picture

Status: Needs work » Needs review

anybody’s picture

Title: Call to a member function getCurrencyCode() on null » Call to a member function getCurrencyCode() on null (Drupal Commerce WSOD!)
anybody’s picture

Title: Call to a member function getCurrencyCode() on null (Drupal Commerce WSOD!) » Error: Call to a member function getCurrencyCode() on null (Drupal Commerce WSOD!)
thomas.frobieter’s picture

Status: Needs review » Reviewed & tested by the community

RTBC for MR!100

anybody’s picture

#3489811: AddToCartEvent WSOD for order items with no price is similar, but not the same. Should be merged afterwards.
That one will need a rebase then.

hongqing’s picture

same issue with 2.0.9.

ehlovader made their first commit to this issue’s fork.

ehlovader changed the visibility of the branch 3422723-wider-fix-for-null-price to hidden.