Created
July 20, 2018 14:13
-
-
Save vbuck/fdc552f8bc6fa3434aa521684c242b0c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/app/code/Magento/Tax/Model/Sales/Total/Quote/CommonTaxCollector.php b/app/code/Magento/Tax/Model/Sales/Total/Quote/CommonTaxCollector.php | |
index ff31aa4ba90..b279408ba8e 100644 | |
--- a/app/code/Magento/Tax/Model/Sales/Total/Quote/CommonTaxCollector.php | |
+++ b/app/code/Magento/Tax/Model/Sales/Total/Quote/CommonTaxCollector.php | |
@@ -188,6 +188,7 @@ class CommonTaxCollector extends AbstractTotal | |
* @param bool $priceIncludesTax | |
* @param bool $useBaseCurrency | |
* @param string $parentCode | |
+ * @param bool $useOriginalPrice | |
* @return \Magento\Tax\Api\Data\QuoteDetailsItemInterface | |
*/ | |
public function mapItem( | |
@@ -195,12 +196,14 @@ class CommonTaxCollector extends AbstractTotal | |
AbstractItem $item, | |
$priceIncludesTax, | |
$useBaseCurrency, | |
- $parentCode = null | |
+ $parentCode = null, | |
+ $useOriginalPrice = false | |
) { | |
if (!$item->getTaxCalculationItemId()) { | |
$sequence = 'sequence-' . $this->getNextIncrement(); | |
$item->setTaxCalculationItemId($sequence); | |
} | |
+ | |
/** @var \Magento\Tax\Api\Data\QuoteDetailsItemInterface $itemDataObject */ | |
$itemDataObject = $itemDataObjectFactory->create(); | |
$itemDataObject->setCode($item->getTaxCalculationItemId()) | |
@@ -215,13 +218,13 @@ class CommonTaxCollector extends AbstractTotal | |
if ($useBaseCurrency) { | |
if (!$item->getBaseTaxCalculationPrice()) { | |
- $item->setBaseTaxCalculationPrice($item->getBaseCalculationPriceOriginal()); | |
+ $item->setBaseTaxCalculationPrice($this->getBaseTaxCalculationPrice($item, $useOriginalPrice)); | |
} | |
$itemDataObject->setUnitPrice($item->getBaseTaxCalculationPrice()) | |
->setDiscountAmount($item->getBaseDiscountAmount()); | |
} else { | |
if (!$item->getTaxCalculationPrice()) { | |
- $item->setTaxCalculationPrice($item->getCalculationPriceOriginal()); | |
+ $item->setTaxCalculationPrice($this->getTaxCalculationPrice($item, $useOriginalPrice)); | |
} | |
$itemDataObject->setUnitPrice($item->getTaxCalculationPrice()) | |
->setDiscountAmount($item->getDiscountAmount()); | |
@@ -285,14 +288,16 @@ class CommonTaxCollector extends AbstractTotal | |
* Add quote items | |
* | |
* @param ShippingAssignmentInterface $shippingAssignment | |
- * @param bool $useBaseCurrency | |
* @param bool $priceIncludesTax | |
+ * @param bool $useBaseCurrency | |
+ * @param bool $useOriginalPrice | |
* @return \Magento\Tax\Api\Data\QuoteDetailsItemInterface[] | |
*/ | |
public function mapItems( | |
ShippingAssignmentInterface $shippingAssignment, | |
$priceIncludesTax, | |
- $useBaseCurrency | |
+ $useBaseCurrency, | |
+ $useOriginalPrice = null | |
) { | |
$items = $shippingAssignment->getItems(); | |
if (!count($items)) { | |
@@ -308,7 +313,13 @@ class CommonTaxCollector extends AbstractTotal | |
} | |
if ($item->getHasChildren() && $item->isChildrenCalculated()) { | |
- $parentItemDataObject = $this->mapItem($itemDataObjectFactory, $item, $priceIncludesTax, $useBaseCurrency); | |
+ $parentItemDataObject = $this->mapItem( | |
+ $itemDataObjectFactory, | |
+ $item, | |
+ $priceIncludesTax, | |
+ $useBaseCurrency, | |
+ $useOriginalPrice | |
+ ); | |
$itemDataObjects[] = $parentItemDataObject; | |
foreach ($item->getChildren() as $child) { | |
$childItemDataObject = $this->mapItem( | |
@@ -316,7 +327,8 @@ class CommonTaxCollector extends AbstractTotal | |
$child, | |
$priceIncludesTax, | |
$useBaseCurrency, | |
- $parentItemDataObject->getCode() | |
+ $parentItemDataObject->getCode(), | |
+ $useOriginalPrice | |
); | |
$itemDataObjects[] = $childItemDataObject; | |
$extraTaxableItems = $this->mapItemExtraTaxables( | |
@@ -328,7 +340,14 @@ class CommonTaxCollector extends AbstractTotal | |
$itemDataObjects = array_merge($itemDataObjects, $extraTaxableItems); | |
} | |
} else { | |
- $itemDataObject = $this->mapItem($itemDataObjectFactory, $item, $priceIncludesTax, $useBaseCurrency); | |
+ $itemDataObject = $this->mapItem( | |
+ $itemDataObjectFactory, | |
+ $item, | |
+ $priceIncludesTax, | |
+ $useBaseCurrency, | |
+ null, | |
+ $useOriginalPrice | |
+ ); | |
$itemDataObjects[] = $itemDataObject; | |
$extraTaxableItems = $this->mapItemExtraTaxables( | |
$itemDataObjectFactory, | |
@@ -407,6 +426,30 @@ class CommonTaxCollector extends AbstractTotal | |
return null; | |
} | |
+ /** | |
+ * Determine the base tax calculation price according to tax configuration. | |
+ * | |
+ * @param AbstractItem $item | |
+ * @param bool $useOriginalPrice | |
+ * @return float | |
+ */ | |
+ protected function getBaseTaxCalculationPrice(AbstractItem $item, $useOriginalPrice = false) | |
+ { | |
+ return $useOriginalPrice ? $item->getBaseOriginalPrice() : $item->getBaseCalculationPriceOriginal(); | |
+ } | |
+ | |
+ /** | |
+ * Determine the tax calculation price according to tax configuration. | |
+ * | |
+ * @param AbstractItem $item | |
+ * @param bool $useOriginalPrice | |
+ * @return float | |
+ */ | |
+ protected function getTaxCalculationPrice(AbstractItem $item, $useOriginalPrice = false) | |
+ { | |
+ return $useOriginalPrice ? $item->getOriginalPrice() : $item->getCalculationPriceOriginal(); | |
+ } | |
+ | |
/** | |
* Populate QuoteDetails object from quote address object | |
* | |
@@ -531,7 +574,7 @@ class CommonTaxCollector extends AbstractTotal | |
$total->setSubtotalInclTax($subtotalInclTax); | |
$total->setBaseSubtotalTotalInclTax($baseSubtotalInclTax); | |
$total->setBaseSubtotalInclTax($baseSubtotalInclTax); | |
- $shippingAssignment->getShipping()->getAddress()->setBaseSubtotalTotalInclTax($baseSubtotalInclTax); | |
+ $shippingAssignment->getShipping()->getAddress()->setBaseSubtotalTotalInclTax($baseSubtotalInclTax);; | |
return $this; | |
} | |
diff --git a/app/code/Magento/Tax/Model/Sales/Total/Quote/Subtotal.php b/app/code/Magento/Tax/Model/Sales/Total/Quote/Subtotal.php | |
index e60926b96fe..7f54a13d826 100644 | |
--- a/app/code/Magento/Tax/Model/Sales/Total/Quote/Subtotal.php | |
+++ b/app/code/Magento/Tax/Model/Sales/Total/Quote/Subtotal.php | |
@@ -9,11 +9,53 @@ | |
*/ | |
namespace Magento\Tax\Model\Sales\Total\Quote; | |
+use Magento\Customer\Api\Data\AddressInterfaceFactory as CustomerAddressFactory; | |
+use Magento\Customer\Api\Data\RegionInterfaceFactory as CustomerAddressRegionFactory; | |
use Magento\Quote\Model\Quote\Address; | |
use Magento\Quote\Api\Data\ShippingAssignmentInterface; | |
class Subtotal extends CommonTaxCollector | |
{ | |
+ /** | |
+ * Tax module helper | |
+ * | |
+ * @var \Magento\Tax\Helper\Data | |
+ */ | |
+ protected $_taxData; | |
+ | |
+ /** | |
+ * @param \Magento\Tax\Model\Config $taxConfig | |
+ * @param \Magento\Tax\Api\TaxCalculationInterface $taxCalculationService | |
+ * @param \Magento\Tax\Api\Data\QuoteDetailsInterfaceFactory $quoteDetailsDataObjectFactory | |
+ * @param \Magento\Tax\Api\Data\QuoteDetailsItemInterfaceFactory $quoteDetailsItemDataObjectFactory | |
+ * @param \Magento\Tax\Api\Data\TaxClassKeyInterfaceFactory $taxClassKeyDataObjectFactory | |
+ * @param CustomerAddressFactory $customerAddressFactory | |
+ * @param CustomerAddressRegionFactory $customerAddressRegionFactory | |
+ * @param \Magento\Tax\Helper\Data $taxData | |
+ */ | |
+ public function __construct( | |
+ \Magento\Tax\Model\Config $taxConfig, | |
+ \Magento\Tax\Api\TaxCalculationInterface $taxCalculationService, | |
+ \Magento\Tax\Api\Data\QuoteDetailsInterfaceFactory $quoteDetailsDataObjectFactory, | |
+ \Magento\Tax\Api\Data\QuoteDetailsItemInterfaceFactory $quoteDetailsItemDataObjectFactory, | |
+ \Magento\Tax\Api\Data\TaxClassKeyInterfaceFactory $taxClassKeyDataObjectFactory, | |
+ CustomerAddressFactory $customerAddressFactory, | |
+ CustomerAddressRegionFactory $customerAddressRegionFactory, | |
+ \Magento\Tax\Helper\Data $taxData | |
+ ) { | |
+ $this->_taxData = $taxData; | |
+ | |
+ parent::__construct( | |
+ $taxConfig, | |
+ $taxCalculationService, | |
+ $quoteDetailsDataObjectFactory, | |
+ $quoteDetailsItemDataObjectFactory, | |
+ $taxClassKeyDataObjectFactory, | |
+ $customerAddressFactory, | |
+ $customerAddressRegionFactory | |
+ ); | |
+ } | |
+ | |
/** | |
* Calculate tax on product items. The result will be used to determine shipping | |
* and discount later. | |
@@ -35,14 +77,25 @@ class Subtotal extends CommonTaxCollector | |
$store = $quote->getStore(); | |
$priceIncludesTax = $this->_config->priceIncludesTax($store); | |
+ $useOriginalPrice = $this->_taxData->applyTaxOnOriginalPrice(); | |
//Setup taxable items | |
- $itemDataObjects = $this->mapItems($shippingAssignment, $priceIncludesTax, false); | |
+ $itemDataObjects = $this->mapItems( | |
+ $shippingAssignment, | |
+ $priceIncludesTax, | |
+ false, | |
+ $useOriginalPrice | |
+ ); | |
$quoteDetails = $this->prepareQuoteDetails($shippingAssignment, $itemDataObjects); | |
$taxDetails = $this->taxCalculationService | |
->calculateTax($quoteDetails, $store->getStoreId()); | |
- $itemDataObjects = $this->mapItems($shippingAssignment, $priceIncludesTax, true); | |
+ $itemDataObjects = $this->mapItems( | |
+ $shippingAssignment, | |
+ $priceIncludesTax, | |
+ true, | |
+ $useOriginalPrice | |
+ ); | |
$baseQuoteDetails = $this->prepareQuoteDetails($shippingAssignment, $itemDataObjects); | |
$baseTaxDetails = $this->taxCalculationService | |
->calculateTax($baseQuoteDetails, $store->getStoreId()); | |
diff --git a/app/code/Magento/Tax/Model/Sales/Total/Quote/Tax.php b/app/code/Magento/Tax/Model/Sales/Total/Quote/Tax.php | |
index 4aea7ab4c5a..d52f00b7b86 100755 | |
--- a/app/code/Magento/Tax/Model/Sales/Total/Quote/Tax.php | |
+++ b/app/code/Magento/Tax/Model/Sales/Total/Quote/Tax.php | |
@@ -184,7 +184,8 @@ class Tax extends CommonTaxCollector | |
$address = $shippingAssignment->getShipping()->getAddress(); | |
//Setup taxable items | |
$priceIncludesTax = $this->_config->priceIncludesTax($address->getQuote()->getStore()); | |
- $itemDataObjects = $this->mapItems($shippingAssignment, $priceIncludesTax, $useBaseCurrency); | |
+ $useOriginalPrice = $this->_taxData->applyTaxOnOriginalPrice(); | |
+ $itemDataObjects = $this->mapItems($shippingAssignment, $priceIncludesTax, $useBaseCurrency, $useOriginalPrice); | |
//Add shipping | |
$shippingDataObject = $this->getShippingDataObject($shippingAssignment, $total, $useBaseCurrency); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment