Skip to content

Commit 3c24dc9

Browse files
author
Manasa Potluri
committed
MAGETWO-34068: Incorrect tax details and amounts in frontend and backend order
- Added custom attributes to order interface - Removed obsolete code
1 parent 67e627b commit 3c24dc9

File tree

4 files changed

+55
-18
lines changed

4 files changed

+55
-18
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?xml version="1.0"?>
2+
<!--
3+
/**
4+
* Copyright © 2015 Magento. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/Api/etc/data_object.xsd">
9+
<custom_attributes for="Magento\Sales\Api\Data\OrderInterface">
10+
<attribute code="applied_taxes" type="Magento\Tax\Api\Data\OrderTaxDetailsAppliedTaxInterface[]" />
11+
<attribute code="item_applied_taxes" type="Magento\Tax\Api\Data\OrderTaxDetailsItemInterface[]" />
12+
<attribute code="converting_from_quote" type="boolean" />
13+
</custom_attributes>
14+
</config>

app/code/Magento/Tax/Model/Observer.php

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -131,14 +131,22 @@ public function salesEventOrderAfterSave(\Magento\Framework\Event\Observer $obse
131131
return;
132132
}
133133

134-
$getTaxesForItems = $order->getItemAppliedTaxes();
135-
$taxes = $order->getAppliedTaxes();
134+
$taxesAttr = $order->getCustomAttribute('applied_taxes');
135+
if (is_null($taxesAttr) || !is_array($taxesAttr->getValue())) {
136+
$taxes = [];
137+
} else {
138+
$taxes = $taxesAttr->getValue();
139+
}
136140

137-
$ratesIdQuoteItemId = [];
138-
if (!is_array($getTaxesForItems)) {
141+
$getTaxesForItemsAttr = $order->getCustomAttribute('item_applied_taxes');
142+
if (is_null($getTaxesForItemsAttr) || !is_array($getTaxesForItemsAttr->getValue())) {
139143
$getTaxesForItems = [];
144+
} else {
145+
$getTaxesForItems = $getTaxesForItemsAttr->getValue();
140146
}
141-
foreach ($getTaxesForItems as $quoteItemId => $taxesArray) {
147+
148+
$ratesIdQuoteItemId = [];
149+
foreach ($getTaxesForItems as $taxesArray) {
142150
foreach ($taxesArray as $rates) {
143151
if (count($rates['rates']) == 1) {
144152
$ratesIdQuoteItemId[$rates['id']][] = [
@@ -171,20 +179,12 @@ public function salesEventOrderAfterSave(\Magento\Framework\Event\Observer $obse
171179
];
172180
$percentSum += $rate['percent'];
173181
}
174-
175-
if ($percentDelta != $percentSum) {
176-
$delta = $percentDelta - $percentSum;
177-
foreach ($ratesIdQuoteItemId[$rates['id']] as &$rateTax) {
178-
if ($rateTax['id'] == $quoteItemId) {
179-
$rateTax['percent'] = $rateTax['percent'] / $percentSum * $delta + $rateTax['percent'];
180-
}
181-
}
182-
}
183182
}
184183
}
185184
}
186185

187-
foreach ($taxes as $id => $row) {
186+
foreach ($taxes as $row) {
187+
$id = $row['id'];
188188
foreach ($row['rates'] as $tax) {
189189
if (is_null($row['percent'])) {
190190
$baseRealAmount = $row['base_amount'];

app/code/Magento/Tax/Model/Quote/ToOrderConverter.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,21 +39,22 @@ public function afterConvert(QuoteAddressToOrder $subject, OrderInterface $order
3939
{
4040
/** @var \Magento\Sales\Model\Order $order */
4141
$taxes = $this->quoteAddress->getAppliedTaxes();
42+
$customAttributes = $order->getCustomAttributes();
4243
if (is_array($taxes)) {
4344
if (is_array($order->getAppliedTaxes())) {
4445
$taxes = array_merge($order->getAppliedTaxes(), $taxes);
4546
}
46-
$order->setAppliedTaxes($taxes);
47-
$order->setConvertingFromQuote(true);
47+
$customAttributes = array_merge($customAttributes, ['applied_taxes' => $taxes], ['converting_from_quote' => true]);
4848
}
4949

5050
$itemAppliedTaxes = $this->quoteAddress->getItemsAppliedTaxes();
5151
if (is_array($itemAppliedTaxes)) {
5252
if (is_array($order->getItemAppliedTaxes())) {
5353
$itemAppliedTaxes = array_merge($order->getItemAppliedTaxes(), $itemAppliedTaxes);
5454
}
55-
$order->setItemAppliedTaxes($itemAppliedTaxes);
55+
$customAttributes = array_merge($customAttributes, ['item_applied_taxes' => $itemAppliedTaxes]);
5656
}
57+
$order->setData('custom_attributes', $customAttributes);
5758
return $order;
5859
}
5960
}

app/code/Magento/Tax/etc/fieldset.xml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,5 +42,27 @@
4242
<aspect name="to_cm_item" />
4343
</field>
4444
</fieldset>
45+
<fieldset id="quote_convert_address">
46+
<field name="subtotal_incl_tax">
47+
<aspect name="to_order" />
48+
</field>
49+
<field name="base_subtotal_incl_tax">
50+
<aspect name="to_order" />
51+
</field>
52+
</fieldset>
53+
<fieldset id="quote_convert_item">
54+
<field name="price_incl_tax">
55+
<aspect name="to_order_item" />
56+
</field>
57+
<field name="base_price_incl_tax">
58+
<aspect name="to_order_item" />
59+
</field>
60+
<field name="row_total_incl_tax">
61+
<aspect name="to_order_item" />
62+
</field>
63+
<field name="base_row_total_incl_tax">
64+
<aspect name="to_order_item" />
65+
</field>
66+
</fieldset>
4567
</scope>
4668
</config>

0 commit comments

Comments
 (0)