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 
9 use Magento\Sales\Model\Order\CreditMemo\Item as CreditMemoItem;
11 use Magento\Sales\Model\Order\Item as OrderItem;
12 use Magento\Weee\Model\Tax as WeeeDisplayConfig;
13 
22 {
26  protected $weeeHelper;
27 
35  public function __construct(
36  \Magento\Framework\View\Element\Template\Context $context,
37  \Magento\Tax\Helper\Data $taxHelper,
39  \Magento\Weee\Helper\Data $weeeHelper,
40  array $data = []
41  ) {
42  $this->weeeHelper = $weeeHelper;
43  parent::__construct($context, $taxHelper, $priceCurrency, $data);
44  $this->_isScopePrivate = true;
45  }
46 
52  public function displayPriceWithWeeeDetails()
53  {
54  if (!$this->weeeHelper->isEnabled($this->getStoreId())) {
55  return false;
56  }
57 
58  $displayWeeeDetails = $this->weeeHelper->typeOfDisplay(
59  [WeeeDisplayConfig::DISPLAY_INCL_DESCR, WeeeDisplayConfig::DISPLAY_EXCL_DESCR_INCL],
60  $this->getZone(),
61  $this->getStoreId()
62  );
63  if (!$displayWeeeDetails) {
64  return false;
65  }
66  if ($this->weeeHelper->getWeeeTaxAppliedAmount($this->getItem()) <= 0) {
67  return false;
68  }
69 
70  return true;
71  }
72 
78  public function getIncludeWeeeFlag()
79  {
80  $includeWeee = $this->weeeHelper->typeOfDisplay(
81  [WeeeDisplayConfig::DISPLAY_INCL_DESCR, WeeeDisplayConfig::DISPLAY_INCL],
82  $this->getZone(),
83  $this->getStoreId()
84  );
85  return $includeWeee;
86  }
87 
94  public function getUnitDisplayPriceInclTax()
95  {
96  $priceInclTax = $this->getItem()->getPriceInclTax();
97 
98  if (!$this->weeeHelper->isEnabled($this->getStoreId())) {
99  return $priceInclTax;
100  }
101 
102  if ($this->getIncludeWeeeFlag()) {
103  return $priceInclTax + $this->weeeHelper->getWeeeTaxInclTax($this->getItem());
104  }
105 
106  return $priceInclTax;
107  }
108 
116  {
117  $basePriceInclTax = $this->getItem()->getBasePriceInclTax();
118 
119  if (!$this->weeeHelper->isEnabled($this->getStoreId())) {
120  return $basePriceInclTax;
121  }
122 
123  if ($this->getIncludeWeeeFlag()) {
124  return $basePriceInclTax + $this->weeeHelper->getBaseWeeeTaxInclTax($this->getItem());
125  }
126 
127  return $basePriceInclTax;
128  }
129 
136  public function getRowDisplayPriceInclTax()
137  {
138  $rowTotalInclTax = $this->getItem()->getRowTotalInclTax();
139 
140  if (!$this->weeeHelper->isEnabled($this->getStoreId())) {
141  return $rowTotalInclTax;
142  }
143 
144  if ($this->getIncludeWeeeFlag()) {
145  return $rowTotalInclTax + $this->weeeHelper->getRowWeeeTaxInclTax($this->getItem());
146  }
147 
148  return $rowTotalInclTax;
149  }
150 
158  {
159  $baseRowTotalInclTax = $this->getItem()->getBaseRowTotalInclTax();
160 
161  if (!$this->weeeHelper->isEnabled($this->getStoreId())) {
162  return $baseRowTotalInclTax;
163  }
164 
165  if ($this->getIncludeWeeeFlag()) {
166  return $baseRowTotalInclTax + $this->weeeHelper->getBaseRowWeeeTaxInclTax($this->getItem());
167  }
168 
169  return $baseRowTotalInclTax;
170  }
171 
178  public function getUnitDisplayPriceExclTax()
179  {
180  $priceExclTax = $this->getItemDisplayPriceExclTax();
181 
182  if (!$this->weeeHelper->isEnabled($this->getStoreId())) {
183  return $priceExclTax;
184  }
185 
186  if ($this->getIncludeWeeeFlag()) {
187  return $priceExclTax + $this->weeeHelper->getWeeeTaxAppliedAmount($this->getItem());
188  }
189 
190  return $priceExclTax;
191  }
192 
200  {
201  $orderItem = $this->getItem();
202  if ($orderItem instanceof InvoiceItem || $orderItem instanceof CreditMemoItem) {
203  $orderItem = $orderItem->getOrderItem();
204  }
205 
206  $qty = $orderItem->getQtyOrdered();
207  $basePriceExclTax = $orderItem->getBaseRowTotal() / $qty;
208 
209  if (!$this->weeeHelper->isEnabled($this->getStoreId())) {
210  return $basePriceExclTax;
211  }
212 
213  if ($this->getIncludeWeeeFlag()) {
214  return $basePriceExclTax + $this->getItem()->getBaseWeeeTaxAppliedAmount();
215  }
216 
217  return $basePriceExclTax;
218  }
219 
226  public function getRowDisplayPriceExclTax()
227  {
228  $rowTotalExclTax = $this->getItem()->getRowTotal();
229 
230  if (!$this->weeeHelper->isEnabled($this->getStoreId())) {
231  return $rowTotalExclTax;
232  }
233 
234  if ($this->getIncludeWeeeFlag()) {
235  return $rowTotalExclTax + $this->weeeHelper->getWeeeTaxAppliedRowAmount($this->getItem());
236  }
237 
238  return $rowTotalExclTax;
239  }
240 
248  {
249  $baseRowTotalExclTax = $this->getItem()->getBaseRowTotal();
250 
251  if (!$this->weeeHelper->isEnabled($this->getStoreId())) {
252  return $baseRowTotalExclTax;
253  }
254 
255  if ($this->getIncludeWeeeFlag()) {
256  return $baseRowTotalExclTax + $this->getItem()->getBaseWeeeTaxAppliedRowAmnt();
257  }
258 
259  return $baseRowTotalExclTax;
260  }
261 
268  {
269  $priceInclTax = $this->getItem()->getPriceInclTax();
270 
271  if (!$this->weeeHelper->isEnabled($this->getStoreId())) {
272  return $priceInclTax;
273  }
274 
275  return $priceInclTax + $this->weeeHelper->getWeeeTaxInclTax($this->getItem());
276  }
277 
284  {
285  $basePriceInclTax = $this->getItem()->getBasePriceInclTax();
286 
287  if (!$this->weeeHelper->isEnabled($this->getStoreId())) {
288  return $basePriceInclTax;
289  }
290 
291  return $basePriceInclTax + $this->weeeHelper->getBaseWeeeTaxInclTax($this->getItem());
292  }
293 
300  {
301  $rowTotalInclTax = $this->getItem()->getRowTotalInclTax();
302 
303  if (!$this->weeeHelper->isEnabled($this->getStoreId())) {
304  return $rowTotalInclTax;
305  }
306 
307  return $rowTotalInclTax + $this->weeeHelper->getRowWeeeTaxInclTax($this->getItem());
308  }
309 
316  {
317  $baseRowTotalInclTax = $this->getItem()->getBaseRowTotalInclTax();
318 
319  if (!$this->weeeHelper->isEnabled($this->getStoreId())) {
320  return $baseRowTotalInclTax;
321  }
322 
323  return $baseRowTotalInclTax + $this->weeeHelper->getBaseRowWeeeTaxInclTax($this->getItem());
324  }
325 
332  {
333  $priceExclTax = $this->getItemDisplayPriceExclTax();
334 
335  if (!$this->weeeHelper->isEnabled($this->getStoreId())) {
336  return $priceExclTax;
337  }
338 
339  return $priceExclTax + $this->weeeHelper->getWeeeTaxAppliedAmount($this->getItem());
340  }
341 
348  {
349  $orderItem = $this->getItem();
350  if ($orderItem instanceof InvoiceItem || $orderItem instanceof CreditMemoItem) {
351  $orderItem = $orderItem->getOrderItem();
352  }
353 
354  $qty = $orderItem->getQtyOrdered();
355  $basePriceExclTax = $orderItem->getBaseRowTotal() / $qty;
356 
357  if (!$this->weeeHelper->isEnabled($this->getStoreId())) {
358  return $basePriceExclTax;
359  }
360 
361  return $basePriceExclTax + $this->getItem()->getBaseWeeeTaxAppliedAmount();
362  }
363 
370  {
371  $rowTotalExclTax = $this->getItem()->getRowTotal();
372 
373  if (!$this->weeeHelper->isEnabled($this->getStoreId())) {
374  return $rowTotalExclTax;
375  }
376 
377  return $rowTotalExclTax + $this->weeeHelper->getWeeeTaxAppliedRowAmount($this->getItem());
378  }
379 
386  {
387  $baseRowTotalExclTax = $this->getItem()->getBaseRowTotal();
388 
389  if (!$this->weeeHelper->isEnabled($this->getStoreId())) {
390  return $baseRowTotalExclTax;
391  }
392 
393  return $baseRowTotalExclTax + $this->getItem()->getBaseWeeeTaxAppliedRowAmnt();
394  }
395 
401  public function displayFinalPrice()
402  {
403  $flag = $this->weeeHelper->typeOfDisplay(
404  WeeeDisplayConfig::DISPLAY_EXCL_DESCR_INCL,
405  $this->getZone(),
406  $this->getStoreId()
407  );
408 
409  if (!$flag) {
410  return false;
411  }
412 
413  if ($this->weeeHelper->getWeeeTaxAppliedAmount($this->getItem()) <= 0) {
414  return false;
415  }
416  return true;
417  }
418 
425  public function getTotalAmount($item)
426  {
427  $totalAmount = $item->getRowTotal()
428  - $item->getDiscountAmount()
429  + $item->getTaxAmount()
430  + $item->getDiscountTaxCompensationAmount()
431  + $this->weeeHelper->getRowWeeeTaxInclTax($item);
432 
433  return $totalAmount;
434  }
435 
442  public function getBaseTotalAmount($item)
443  {
444  $totalAmount = $item->getBaseRowTotal()
445  - $item->getBaseDiscountAmount()
446  + $item->getBaseTaxAmount()
447  + $item->getBaseDiscountTaxCompensationAmount()
448  + $this->weeeHelper->getBaseRowWeeeTaxInclTax($item);
449 
450  return $totalAmount;
451  }
452 }
$orderItem
Definition: order.php:30
__construct(\Magento\Framework\View\Element\Template\Context $context, \Magento\Tax\Helper\Data $taxHelper, PriceCurrencyInterface $priceCurrency, \Magento\Weee\Helper\Data $weeeHelper, array $data=[])
Definition: Renderer.php:35