class PriceListPriceResolver in Commerce Pricelist 8.2
Hierarchy
- class \Drupal\commerce_pricelist\PriceListPriceResolver implements PriceResolverInterface
Expanded class hierarchy of PriceListPriceResolver
1 string reference to 'PriceListPriceResolver'
1 service uses PriceListPriceResolver
File
- src/
PriceListPriceResolver.php, line 9
Namespace
Drupal\commerce_pricelistView source
class PriceListPriceResolver implements PriceResolverInterface {
/**
* The price list repository.
*
* @var \Drupal\commerce_pricelist\PriceListRepositoryInterface
*/
protected $priceListRepository;
/**
* Constructs a new PriceListPriceResolver.
*
* @param \Drupal\commerce_pricelist\PriceListRepositoryInterface $price_list_repository
* The price list repository.
*/
public function __construct(PriceListRepositoryInterface $price_list_repository) {
$this->priceListRepository = $price_list_repository;
}
/**
* {@inheritdoc}
*/
public function resolve(PurchasableEntityInterface $entity, $quantity, Context $context) {
$price = NULL;
$price_list_item = $this->priceListRepository
->loadItem($entity, $quantity, $context);
if ($price_list_item) {
$field_name = $context
->getData('field_name', 'price');
if ($field_name == 'list_price') {
$price = $price_list_item
->getListPrice();
}
elseif ($field_name == 'price') {
$price = $price_list_item
->getPrice();
}
}
return $price;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
PriceListPriceResolver:: |
protected | property | The price list repository. | |
PriceListPriceResolver:: |
public | function |
Resolves a price for the given purchasable entity. Overrides PriceResolverInterface:: |
|
PriceListPriceResolver:: |
public | function | Constructs a new PriceListPriceResolver. |