class DefaultPriceResolver in Commerce Core 8.2
Provides the default price, taking it directly from the purchasable entity.
Hierarchy
- class \Drupal\commerce_price\Resolver\DefaultPriceResolver implements PriceResolverInterface
Expanded class hierarchy of DefaultPriceResolver
1 string reference to 'DefaultPriceResolver'
- commerce_price.services.yml in modules/
price/ commerce_price.services.yml - modules/price/commerce_price.services.yml
1 service uses DefaultPriceResolver
File
- modules/
price/ src/ Resolver/ DefaultPriceResolver.php, line 11
Namespace
Drupal\commerce_price\ResolverView source
class DefaultPriceResolver implements PriceResolverInterface {
/**
* {@inheritdoc}
*/
public function resolve(PurchasableEntityInterface $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:: |