Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Renderer.php
Go to the documentation of this file.
1 <?php
7 
12 use Magento\Sales\Model\Order\CreditMemo\Item as CreditMemoItem;
14 use Magento\Sales\Model\Order\Item as OrderItem;
15 use Magento\Tax\Helper\Data as TaxHelper;
16 
25 {
29  protected $taxHelper;
30 
34  protected $item;
35 
39  protected $storeId = null;
40 
46  protected $zone = null;
47 
51  protected $priceCurrency;
52 
59  public function __construct(
60  Context $context,
61  TaxHelper $taxHelper,
63  array $data = []
64  ) {
65  $this->priceCurrency = $priceCurrency;
66  $this->taxHelper = $taxHelper;
67  if (isset($data['zone'])) {
68  $this->zone = $data['zone'];
69  }
70  parent::__construct($context, $data);
71  }
72 
79  public function setItem($item)
80  {
81  $this->item = $item;
82  $this->storeId = $item->getStoreId();
83  return $this;
84  }
85 
91  public function getZone()
92  {
93  return $this->zone;
94  }
95 
102  public function setZone($zone)
103  {
104  $this->zone = $zone;
105  return $this;
106  }
107 
111  public function getStoreId()
112  {
113  return $this->storeId;
114  }
115 
121  public function getItem()
122  {
123  return $this->item;
124  }
125 
131  public function displayPriceInclTax()
132  {
133  switch ($this->zone) {
134  case PricingRender::ZONE_CART:
135  return $this->taxHelper->displayCartPriceInclTax($this->storeId);
136  case PricingRender::ZONE_EMAIL:
137  case PricingRender::ZONE_SALES:
138  return $this->taxHelper->displaySalesPriceInclTax($this->storeId);
139  default:
140  return $this->taxHelper->displayCartPriceInclTax($this->storeId);
141  }
142  }
143 
149  public function displayPriceExclTax()
150  {
151  switch ($this->zone) {
152  case PricingRender::ZONE_CART:
153  return $this->taxHelper->displayCartPriceExclTax($this->storeId);
154  case PricingRender::ZONE_EMAIL:
155  case PricingRender::ZONE_SALES:
156  return $this->taxHelper->displaySalesPriceExclTax($this->storeId);
157  default:
158  return $this->taxHelper->displayCartPriceExclTax($this->storeId);
159  }
160  }
161 
167  public function displayBothPrices()
168  {
169  switch ($this->zone) {
170  case PricingRender::ZONE_CART:
171  return $this->taxHelper->displayCartBothPrices($this->storeId);
172  case PricingRender::ZONE_EMAIL:
173  case PricingRender::ZONE_SALES:
174  return $this->taxHelper->displaySalesBothPrices($this->storeId);
175  default:
176  return $this->taxHelper->displayCartBothPrices($this->storeId);
177  }
178  }
179 
186  public function formatPrice($price)
187  {
188  $item = $this->getItem();
189  if ($item instanceof QuoteItem) {
190  return $this->priceCurrency->format(
191  $price,
192  true,
194  $item->getStore()
195  );
196  } elseif ($item instanceof OrderItem) {
197  return $item->getOrder()->formatPrice($price);
198  } else {
199  return $item->getOrderItem()->getOrder()->formatPrice($price);
200  }
201  }
202 
209  public function getItemDisplayPriceExclTax()
210  {
211  $item = $this->getItem();
212  if ($item instanceof QuoteItem) {
213  return $item->getCalculationPrice();
214  } else {
215  return $item->getPrice();
216  }
217  }
218 
225  public function getTotalAmount($item)
226  {
227  $totalAmount = $item->getRowTotal()
228  - $item->getDiscountAmount()
229  + $item->getTaxAmount()
230  + $item->getDiscountTaxCompensationAmount();
231 
232  return $totalAmount;
233  }
234 
241  public function getBaseTotalAmount($item)
242  {
243  $totalAmount = $item->getBaseRowTotal()
244  - $item->getBaseDiscountAmount()
245  + $item->getBaseTaxAmount()
246  + $item->getBaseDiscountTaxCompensationAmount();
247 
248  return $totalAmount;
249  }
250 }
elseif(isset( $params[ 'redirect_parent']))
Definition: iframe.phtml:17
$price
__construct(Context $context, TaxHelper $taxHelper, PriceCurrencyInterface $priceCurrency, array $data=[])
Definition: Renderer.php:59