You are here

class PriceListPriceResolver in Commerce Pricelist 8.2

Hierarchy

Expanded class hierarchy of PriceListPriceResolver

1 string reference to 'PriceListPriceResolver'
commerce_pricelist.services.yml in ./commerce_pricelist.services.yml
commerce_pricelist.services.yml
1 service uses PriceListPriceResolver
commerce_pricelist.price_resolver in ./commerce_pricelist.services.yml
Drupal\commerce_pricelist\PriceListPriceResolver

File

src/PriceListPriceResolver.php, line 9

Namespace

Drupal\commerce_pricelist
View 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

Namesort descending Modifiers Type Description Overrides
PriceListPriceResolver::$priceListRepository protected property The price list repository.
PriceListPriceResolver::resolve public function Resolves a price for the given purchasable entity. Overrides PriceResolverInterface::resolve
PriceListPriceResolver::__construct public function Constructs a new PriceListPriceResolver.