123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452 |
- <?php
- /**
- * Copyright © Magento, Inc. All rights reserved.
- * See COPYING.txt for license details.
- */
- namespace Magento\Weee\Block\Item\Price;
- use Magento\Framework\Pricing\PriceCurrencyInterface;
- use Magento\Sales\Model\Order\CreditMemo\Item as CreditMemoItem;
- use Magento\Sales\Model\Order\Invoice\Item as InvoiceItem;
- use Magento\Sales\Model\Order\Item as OrderItem;
- use Magento\Weee\Model\Tax as WeeeDisplayConfig;
- /**
- * Item price render block
- *
- * @api
- * @author Magento Core Team <core@magentocommerce.com>
- * @since 100.0.2
- */
- class Renderer extends \Magento\Tax\Block\Item\Price\Renderer
- {
- /**
- * @var \Magento\Weee\Helper\Data
- */
- protected $weeeHelper;
- /**
- * @param \Magento\Framework\View\Element\Template\Context $context
- * @param \Magento\Tax\Helper\Data $taxHelper
- * @param PriceCurrencyInterface $priceCurrency
- * @param \Magento\Weee\Helper\Data $weeeHelper
- * @param array $data
- */
- public function __construct(
- \Magento\Framework\View\Element\Template\Context $context,
- \Magento\Tax\Helper\Data $taxHelper,
- PriceCurrencyInterface $priceCurrency,
- \Magento\Weee\Helper\Data $weeeHelper,
- array $data = []
- ) {
- $this->weeeHelper = $weeeHelper;
- parent::__construct($context, $taxHelper, $priceCurrency, $data);
- $this->_isScopePrivate = true;
- }
- /**
- * Whether to display weee details together with price
- *
- * @return bool
- */
- public function displayPriceWithWeeeDetails()
- {
- if (!$this->weeeHelper->isEnabled($this->getStoreId())) {
- return false;
- }
- $displayWeeeDetails = $this->weeeHelper->typeOfDisplay(
- [WeeeDisplayConfig::DISPLAY_INCL_DESCR, WeeeDisplayConfig::DISPLAY_EXCL_DESCR_INCL],
- $this->getZone(),
- $this->getStoreId()
- );
- if (!$displayWeeeDetails) {
- return false;
- }
- if ($this->weeeHelper->getWeeeTaxAppliedAmount($this->getItem()) <= 0) {
- return false;
- }
- return true;
- }
- /**
- * Return the flag whether to include weee in the price
- *
- * @return bool|int
- */
- public function getIncludeWeeeFlag()
- {
- $includeWeee = $this->weeeHelper->typeOfDisplay(
- [WeeeDisplayConfig::DISPLAY_INCL_DESCR, WeeeDisplayConfig::DISPLAY_INCL],
- $this->getZone(),
- $this->getStoreId()
- );
- return $includeWeee;
- }
- /**
- * Get display price for unit price including tax. The Weee amount will be added to unit price including tax
- * depending on Weee display setting
- *
- * @return float
- */
- public function getUnitDisplayPriceInclTax()
- {
- $priceInclTax = $this->getItem()->getPriceInclTax();
- if (!$this->weeeHelper->isEnabled($this->getStoreId())) {
- return $priceInclTax;
- }
- if ($this->getIncludeWeeeFlag()) {
- return $priceInclTax + $this->weeeHelper->getWeeeTaxInclTax($this->getItem());
- }
- return $priceInclTax;
- }
- /**
- * Get base price for unit price including tax. The Weee amount will be added to unit price including tax
- * depending on Weee display setting
- *
- * @return float
- */
- public function getBaseUnitDisplayPriceInclTax()
- {
- $basePriceInclTax = $this->getItem()->getBasePriceInclTax();
- if (!$this->weeeHelper->isEnabled($this->getStoreId())) {
- return $basePriceInclTax;
- }
- if ($this->getIncludeWeeeFlag()) {
- return $basePriceInclTax + $this->weeeHelper->getBaseWeeeTaxInclTax($this->getItem());
- }
- return $basePriceInclTax;
- }
- /**
- * Get display price for row total including tax. The Weee amount will be added to row total including tax
- * depending on Weee display setting
- *
- * @return float
- */
- public function getRowDisplayPriceInclTax()
- {
- $rowTotalInclTax = $this->getItem()->getRowTotalInclTax();
- if (!$this->weeeHelper->isEnabled($this->getStoreId())) {
- return $rowTotalInclTax;
- }
- if ($this->getIncludeWeeeFlag()) {
- return $rowTotalInclTax + $this->weeeHelper->getRowWeeeTaxInclTax($this->getItem());
- }
- return $rowTotalInclTax;
- }
- /**
- * Get base price for row total including tax. The Weee amount will be added to row total including tax
- * depending on Weee display setting
- *
- * @return float
- */
- public function getBaseRowDisplayPriceInclTax()
- {
- $baseRowTotalInclTax = $this->getItem()->getBaseRowTotalInclTax();
- if (!$this->weeeHelper->isEnabled($this->getStoreId())) {
- return $baseRowTotalInclTax;
- }
- if ($this->getIncludeWeeeFlag()) {
- return $baseRowTotalInclTax + $this->weeeHelper->getBaseRowWeeeTaxInclTax($this->getItem());
- }
- return $baseRowTotalInclTax;
- }
- /**
- * Get display price for unit price excluding tax. The Weee amount will be added to unit price
- * depending on Weee display setting
- *
- * @return float
- */
- public function getUnitDisplayPriceExclTax()
- {
- $priceExclTax = $this->getItemDisplayPriceExclTax();
- if (!$this->weeeHelper->isEnabled($this->getStoreId())) {
- return $priceExclTax;
- }
- if ($this->getIncludeWeeeFlag()) {
- return $priceExclTax + $this->weeeHelper->getWeeeTaxAppliedAmount($this->getItem());
- }
- return $priceExclTax;
- }
- /**
- * Get base price for unit price excluding tax. The Weee amount will be added to unit price
- * depending on Weee display setting
- *
- * @return float
- */
- public function getBaseUnitDisplayPriceExclTax()
- {
- $orderItem = $this->getItem();
- if ($orderItem instanceof InvoiceItem || $orderItem instanceof CreditMemoItem) {
- $orderItem = $orderItem->getOrderItem();
- }
- $qty = $orderItem->getQtyOrdered();
- $basePriceExclTax = $orderItem->getBaseRowTotal() / $qty;
- if (!$this->weeeHelper->isEnabled($this->getStoreId())) {
- return $basePriceExclTax;
- }
- if ($this->getIncludeWeeeFlag()) {
- return $basePriceExclTax + $this->getItem()->getBaseWeeeTaxAppliedAmount();
- }
- return $basePriceExclTax;
- }
- /**
- * Get display price for row total excluding tax. The Weee amount will be added to row total
- * depending on Weee display setting
- *
- * @return float
- */
- public function getRowDisplayPriceExclTax()
- {
- $rowTotalExclTax = $this->getItem()->getRowTotal();
- if (!$this->weeeHelper->isEnabled($this->getStoreId())) {
- return $rowTotalExclTax;
- }
- if ($this->getIncludeWeeeFlag()) {
- return $rowTotalExclTax + $this->weeeHelper->getWeeeTaxAppliedRowAmount($this->getItem());
- }
- return $rowTotalExclTax;
- }
- /**
- * Get base price for row total excluding tax. The Weee amount will be added to row total
- * depending on Weee display setting
- *
- * @return float
- */
- public function getBaseRowDisplayPriceExclTax()
- {
- $baseRowTotalExclTax = $this->getItem()->getBaseRowTotal();
- if (!$this->weeeHelper->isEnabled($this->getStoreId())) {
- return $baseRowTotalExclTax;
- }
- if ($this->getIncludeWeeeFlag()) {
- return $baseRowTotalExclTax + $this->getItem()->getBaseWeeeTaxAppliedRowAmnt();
- }
- return $baseRowTotalExclTax;
- }
- /**
- * Get final unit display price including tax, this will add Weee amount to unit price include tax
- *
- * @return float
- */
- public function getFinalUnitDisplayPriceInclTax()
- {
- $priceInclTax = $this->getItem()->getPriceInclTax();
- if (!$this->weeeHelper->isEnabled($this->getStoreId())) {
- return $priceInclTax;
- }
- return $priceInclTax + $this->weeeHelper->getWeeeTaxInclTax($this->getItem());
- }
- /**
- * Get base final unit display price including tax, this will add Weee amount to unit price include tax
- *
- * @return float
- */
- public function getBaseFinalUnitDisplayPriceInclTax()
- {
- $basePriceInclTax = $this->getItem()->getBasePriceInclTax();
- if (!$this->weeeHelper->isEnabled($this->getStoreId())) {
- return $basePriceInclTax;
- }
- return $basePriceInclTax + $this->weeeHelper->getBaseWeeeTaxInclTax($this->getItem());
- }
- /**
- * Get final row display price including tax, this will add weee amount to rowTotalInclTax
- *
- * @return float
- */
- public function getFinalRowDisplayPriceInclTax()
- {
- $rowTotalInclTax = $this->getItem()->getRowTotalInclTax();
- if (!$this->weeeHelper->isEnabled($this->getStoreId())) {
- return $rowTotalInclTax;
- }
- return $rowTotalInclTax + $this->weeeHelper->getRowWeeeTaxInclTax($this->getItem());
- }
- /**
- * Get base final row display price including tax, this will add weee amount to rowTotalInclTax
- *
- * @return float
- */
- public function getBaseFinalRowDisplayPriceInclTax()
- {
- $baseRowTotalInclTax = $this->getItem()->getBaseRowTotalInclTax();
- if (!$this->weeeHelper->isEnabled($this->getStoreId())) {
- return $baseRowTotalInclTax;
- }
- return $baseRowTotalInclTax + $this->weeeHelper->getBaseRowWeeeTaxInclTax($this->getItem());
- }
- /**
- * Get final unit display price excluding tax
- *
- * @return float
- */
- public function getFinalUnitDisplayPriceExclTax()
- {
- $priceExclTax = $this->getItemDisplayPriceExclTax();
- if (!$this->weeeHelper->isEnabled($this->getStoreId())) {
- return $priceExclTax;
- }
- return $priceExclTax + $this->weeeHelper->getWeeeTaxAppliedAmount($this->getItem());
- }
- /**
- * Get base final unit display price excluding tax
- *
- * @return float
- */
- public function getBaseFinalUnitDisplayPriceExclTax()
- {
- $orderItem = $this->getItem();
- if ($orderItem instanceof InvoiceItem || $orderItem instanceof CreditMemoItem) {
- $orderItem = $orderItem->getOrderItem();
- }
- $qty = $orderItem->getQtyOrdered();
- $basePriceExclTax = $orderItem->getBaseRowTotal() / $qty;
- if (!$this->weeeHelper->isEnabled($this->getStoreId())) {
- return $basePriceExclTax;
- }
- return $basePriceExclTax + $this->getItem()->getBaseWeeeTaxAppliedAmount();
- }
- /**
- * Get final row display price excluding tax, this will add Weee amount to rowTotal
- *
- * @return float
- */
- public function getFinalRowDisplayPriceExclTax()
- {
- $rowTotalExclTax = $this->getItem()->getRowTotal();
- if (!$this->weeeHelper->isEnabled($this->getStoreId())) {
- return $rowTotalExclTax;
- }
- return $rowTotalExclTax + $this->weeeHelper->getWeeeTaxAppliedRowAmount($this->getItem());
- }
- /**
- * Get base final row display price excluding tax, this will add Weee amount to rowTotal
- *
- * @return float
- */
- public function getBaseFinalRowDisplayPriceExclTax()
- {
- $baseRowTotalExclTax = $this->getItem()->getBaseRowTotal();
- if (!$this->weeeHelper->isEnabled($this->getStoreId())) {
- return $baseRowTotalExclTax;
- }
- return $baseRowTotalExclTax + $this->getItem()->getBaseWeeeTaxAppliedRowAmnt();
- }
- /**
- * Whether to display final price that include Weee amounts
- *
- * @return bool
- */
- public function displayFinalPrice()
- {
- $flag = $this->weeeHelper->typeOfDisplay(
- WeeeDisplayConfig::DISPLAY_EXCL_DESCR_INCL,
- $this->getZone(),
- $this->getStoreId()
- );
- if (!$flag) {
- return false;
- }
- if ($this->weeeHelper->getWeeeTaxAppliedAmount($this->getItem()) <= 0) {
- return false;
- }
- return true;
- }
- /**
- * Return the total amount minus discount
- *
- * @param OrderItem|InvoiceItem|CreditMemoItem $item
- * @return mixed
- */
- public function getTotalAmount($item)
- {
- $totalAmount = $item->getRowTotal()
- - $item->getDiscountAmount()
- + $item->getTaxAmount()
- + $item->getDiscountTaxCompensationAmount()
- + $this->weeeHelper->getRowWeeeTaxInclTax($item);
- return $totalAmount;
- }
- /**
- * Return the total amount minus discount
- *
- * @param OrderItem|InvoiceItem|CreditMemoItem $item
- * @return mixed
- */
- public function getBaseTotalAmount($item)
- {
- $totalAmount = $item->getBaseRowTotal()
- - $item->getBaseDiscountAmount()
- + $item->getBaseTaxAmount()
- + $item->getBaseDiscountTaxCompensationAmount()
- + $this->weeeHelper->getBaseRowWeeeTaxInclTax($item);
- return $totalAmount;
- }
- }
|