public function PriceResolverPriceTable::resolve in Commerce Price Table 8
Resolves a price for the given purchasable entity.
Use $context->getData('field_name', 'price') to get the name of the field for which the price is being resolved (e.g "list_price", "price").
Parameters
\Drupal\commerce\PurchasableEntityInterface $entity: The purchasable entity.
string $quantity: The quantity.
\Drupal\commerce\Context $context: The context.
Return value
\Drupal\commerce_price\Price|null A price value object, if resolved. Otherwise NULL, indicating that the next resolver in the chain should be called.
Overrides PriceResolverInterface::resolve
File
- src/
Resolvers/ PriceResolverPriceTable.php, line 19
Class
- PriceResolverPriceTable
- Price resolver alter the base price.
Namespace
Drupal\commerce_price_table\ResolversCode
public function resolve(PurchasableEntityInterface $entity, $quantity, Context $context) {
foreach ($entity
->getFieldDefinitions() as $name => $field) {
$types[] = $field
->getType();
if ($field
->getType() == 'commerce_price_table') {
$price = $this
->getTablePrice($entity
->get($name), $quantity);
if ($price) {
$entity
->setPrice($price);
}
}
}
}