\Drupal\commerce_product\Entity\ProductVariationInterface::getListPrice has wrong return type

Created on 15 April 2025, about 2 months ago

The \Drupal\commerce_product\Entity\ProductVariationInterface::getListPrice has this signature:

/**
 * Gets the list price.
 *
 * @return \Drupal\commerce_price\Price
 *   The list price.
 */
public function getListPrice();

However, the default implementation \Drupal\commerce_product\Entity\ProductVariation::getListPrice can return NULL:

```php
public function getListPrice() {
if (!$this->get('list_price')->isEmpty()) {
return $this->get('list_price')->first()->toPrice();
}

return NULL;
}
```

I think the return type should be @return \Drupal\commerce_price\Price|null, because the list price is an optional field.

The interesting thing about it is that ::getPrice() has a nullable return type, which makes ::getListPrice() confusing, because it's unclear how a variation can have a list price but not have a regular price.

📌 Task
Status

Active

Version

3.0

Component

Developer experience

Created by

🇷🇺Russia niklan Russia, Perm

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

Merge Requests

Comments & Activities

Production build 0.71.5 2024