Problem/Motivation

On the referrals admin listing, the page can fatally error when a referral has not yet been redeemed and therefore has no referee_user assigned.

In normal module behavior, a referral entity is created as soon as a user visits /user/referral and a referral code is generated. At that point, the referral has a referrer_user and referral_coupon, but referee_user is still empty until another customer actually uses the code on an order.

However, Drupal\commerce_referral\Entity\ReferralListBuilder::buildRow() assumes referee_user is always present and calls label() / toUrl() on a null entity, which crashes the admin page.

Observed error:

Error: Call to a member function label() on null in Drupal\commerce_referral\Entity\ReferralListBuilder->buildRow()

Steps to reproduce

  • Enable Commerce Referral and configure a valid referral type with a referral promotion.
  • Grant a user permission to access their referral page.
  • Log in as that user and visit /user/referral so a referral code is generated.
  • Before any other user redeems that code, visit the referrals admin listing.
  • The listing attempts to render the row for the new referral.

Proposed resolution

Update ReferralListBuilder::buildRow() to safely handle empty or missing user references.

Remaining tasks

None

User interface changes

The referrals admin listing would show a safe fallback label such as “Not assigned” for referrals that have not yet been redeemed, instead of crashing.

API changes

None

Data model changes

None

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

dustin1221 created an issue. See original summary.

avpaderno’s picture

Version: 1.0.2 » 1.0.x-dev

daniel.j made their first commit to this issue’s fork.

daniel.j’s picture

Created test to demonstrate the issue "tests/src/Kernel/ReferralListBuilderTest.php".

Updated the List Builder to conditionally print '-' incases where 'referee_user' or 'refferrer_user' do not exist.

Thank you @dustin1221 for the issue. I'll merge and make a release.

daniel.j’s picture

Status: Active » Fixed

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

  • daniel.j committed d70eda10 on 1.0.x
    fix: #3581794 admin/commerce/referral Call to a member function label()...
daniel.j’s picture

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.