class DefaultPriceResolver in Price 2.0.x
Provides the default price, taking it directly from the entity.
Hierarchy
- class \Drupal\price\Resolver\DefaultPriceResolver implements PriceResolverInterface
Expanded class hierarchy of DefaultPriceResolver
1 string reference to 'DefaultPriceResolver'
1 service uses DefaultPriceResolver
File
- src/
Resolver/ DefaultPriceResolver.php, line 11
Namespace
Drupal\price\ResolverView source
class DefaultPriceResolver implements PriceResolverInterface {
/**
* {@inheritdoc}
*/
public function resolve(ContentEntityInterface $entity, $quantity, Context $context) {
$field_name = $context
->getData('field_name', 'price');
if ($field_name == 'price') {
// Use the price getter to allow custom purchasable entity types to have
// computed prices that are not backed by a field called "price".
return $entity
->getPrice();
}
elseif ($entity
->hasField($field_name) && !$entity
->get($field_name)
->isEmpty()) {
return $entity
->get($field_name)
->first()
->toPrice();
}
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
DefaultPriceResolver:: |
public | function |
Resolves a price for the given purchasable entity. Overrides PriceResolverInterface:: |