Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
AbstractAdjustment.php
Go to the documentation of this file.
1 <?php
8 
13 
19 abstract class AbstractAdjustment extends Template implements AdjustmentRenderInterface
20 {
24  protected $priceCurrency;
25 
29  protected $amountRender;
30 
36  public function __construct(
37  Template\Context $context,
39  array $data = []
40  ) {
41  $this->priceCurrency = $priceCurrency;
42  parent::__construct($context, $data);
43  }
44 
51  {
52  $this->amountRender = $amountRender;
53 
54  $origArguments = $this->getData();
55  $this->setData(array_replace($origArguments, $arguments));
56 
57  $html = $this->apply();
58 
59  // restore original block arguments
60  $this->setData($origArguments);
61  return $html;
62  }
63 
67  public function getAmountRender()
68  {
69  return $this->amountRender;
70  }
71 
76  public function getPriceType($priceCode)
77  {
78  return $this->getSaleableItem()->getPriceInfo()->getPrice($priceCode);
79  }
80 
84  public function getPrice()
85  {
86  return $this->amountRender->getPrice();
87  }
88 
92  public function getSaleableItem()
93  {
94  return $this->amountRender->getSaleableItem();
95  }
96 
105  public function formatCurrency(
106  $amount,
107  $includeContainer = true,
109  ) {
110  return $this->priceCurrency->format($amount, $includeContainer, $precision);
111  }
112 
121  public function convertAndFormatCurrency(
122  $amount,
123  $includeContainer = true,
125  ) {
126  return $this->priceCurrency->convertAndFormat($amount, $includeContainer, $precision);
127  }
128 
132  public function getAdjustment()
133  {
134  return $this->getSaleableItem()->getPriceInfo()->getAdjustment($this->getAdjustmentCode());
135  }
136 
140  abstract protected function apply();
141 }
__construct(Template\Context $context, PriceCurrencyInterface $priceCurrency, array $data=[])
render(AmountRenderInterface $amountRender, array $arguments=[])
$amount
Definition: order.php:14
convertAndFormatCurrency( $amount, $includeContainer=true, $precision=PriceCurrencyInterface::DEFAULT_PRECISION)
$arguments
setData($key, $value=null)
Definition: DataObject.php:72
formatCurrency( $amount, $includeContainer=true, $precision=PriceCurrencyInterface::DEFAULT_PRECISION)