You are here

public function PriceResolverPriceTable::getTablePrice in Commerce Price Table 8

Get Price object depending on quantity.

Return value

\Drupal\commerce_price\Price|NULL

1 call to PriceResolverPriceTable::getTablePrice()
PriceResolverPriceTable::resolve in src/Resolvers/PriceResolverPriceTable.php
Resolves a price for the given purchasable entity.

File

src/Resolvers/PriceResolverPriceTable.php, line 36

Class

PriceResolverPriceTable
Price resolver alter the base price.

Namespace

Drupal\commerce_price_table\Resolvers

Code

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;
}