class PriceResolverPriceTable in Commerce Price Table 8
Price resolver alter the base price.
Hierarchy
- class \Drupal\commerce_price_table\Resolvers\PriceResolverPriceTable implements PriceResolverInterface
Expanded class hierarchy of PriceResolverPriceTable
1 string reference to 'PriceResolverPriceTable'
1 service uses PriceResolverPriceTable
File
- src/
Resolvers/ PriceResolverPriceTable.php, line 14
Namespace
Drupal\commerce_price_table\ResolversView source
class PriceResolverPriceTable implements PriceResolverInterface {
/**
* {@inheritdoc}
*/
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);
}
}
}
}
/**
* Get Price object depending on quantity.
*
* @return \Drupal\commerce_price\Price|NULL
*/
public function getTablePrice(FieldItemList $values, $quantity) {
foreach ($values as $item) {
if ($quantity >= $item->min_qty and ($quantity <= $item->max_qty or $item->max_qty == -1)) {
return new Price($item->amount, $item->currency_code);
}
}
return NULL;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
PriceResolverPriceTable:: |
public | function | Get Price object depending on quantity. | |
PriceResolverPriceTable:: |
public | function |
Resolves a price for the given purchasable entity. Overrides PriceResolverInterface:: |