Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
AbstractPrice.php
Go to the documentation of this file.
1 <?php
8 
13 
21 abstract class AbstractPrice implements PriceInterface
22 {
26  const PRICE_CODE = 'abstract_price';
27 
31  protected $amount;
32 
36  protected $calculator;
37 
41  protected $product;
42 
46  protected $priceType;
47 
51  protected $quantity;
52 
56  protected $priceInfo;
57 
61  protected $value;
62 
66  protected $priceCurrency;
67 
74  public function __construct(
75  SaleableInterface $saleableItem,
76  $quantity,
79  ) {
80  $this->product = $saleableItem;
81  $this->quantity = $quantity;
82  $this->calculator = $calculator;
83  $this->priceCurrency = $priceCurrency;
84  $this->priceInfo = $saleableItem->getPriceInfo();
85  }
86 
92  abstract public function getValue();
93 
99  public function getAmount()
100  {
101  if (!isset($this->amount[$this->getValue()])) {
102  $this->amount[$this->getValue()] = $this->calculator->getAmount($this->getValue(), $this->getProduct());
103  }
104  return $this->amount[$this->getValue()];
105  }
106 
113  public function getCustomAmount($amount = null, $exclude = null, $context = [])
114  {
115  if (null !== $amount) {
116  $amount = $this->priceCurrency->convertAndRound($amount);
117  } else {
118  $amount = $this->getValue();
119  }
120  return $this->calculator->getAmount($amount, $this->getProduct(), $exclude, $context);
121  }
122 
128  public function getPriceCode()
129  {
130  return static::PRICE_CODE;
131  }
132 
136  public function getProduct()
137  {
138  return $this->product;
139  }
140 
144  public function getQuantity()
145  {
146  return $this->quantity;
147  }
148 }
if( $block->displayPriceExclTax()||$block->displayBothPrices())(__('Excl. Tax')) ?>"> <?php if ($block -> displayPriceWithWeeeDetails()): ?> <span class="cart-tax-total" data-mage-init=' Magento Weee Helper Data Magento Weee Helper Data title amount
Definition: unit.phtml:68
__construct(SaleableInterface $saleableItem, $quantity, CalculatorInterface $calculator, \Magento\Framework\Pricing\PriceCurrencyInterface $priceCurrency)
getCustomAmount($amount=null, $exclude=null, $context=[])