Skip to content

Commit 89fb372

Browse files
MAGETWO-95809: Item row total display incorrect value in API response
- Stabilize for working webapi test
1 parent a0f675d commit 89fb372

File tree

4 files changed

+49
-19
lines changed

4 files changed

+49
-19
lines changed

app/code/Magento/Sales/Plugin/DataObjectProcessor.php renamed to app/code/Magento/Sales/Model/Order/Webapi/ChangeOutputArray.php

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,15 @@
55
*/
66
declare(strict_types=1);
77

8-
namespace Magento\Sales\Plugin;
8+
namespace Magento\Sales\Model\Order\Webapi;
99

10-
use Magento\Framework\Reflection\DataObjectProcessor as Subject;
1110
use Magento\Sales\Api\Data\OrderItemInterface;
12-
use Magento\Sales\Model\Order\Item as OrderItem;
1311
use Magento\Sales\Block\Adminhtml\Items\Column\DefaultColumn;
1412

1513
/**
1614
* Class for changing row total in response.
1715
*/
18-
class DataObjectProcessor
16+
class ChangeOutputArray
1917
{
2018
/**
2119
* @var DefaultColumn
@@ -34,21 +32,16 @@ public function __construct(
3432
/**
3533
* Changing row total for webapi order item response.
3634
*
37-
* @param Subject $subject
35+
* @param OrderItemInterface $dataObject
3836
* @param array $result
39-
* @param mixed $dataObject
4037
* @return array
41-
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
4238
*/
43-
public function afterBuildOutputDataArray(
44-
Subject $subject,
45-
$result,
46-
$dataObject
47-
) {
48-
if ($dataObject instanceof OrderItem) {
49-
$result[OrderItemInterface::ROW_TOTAL] = $this->priceRenderer->getTotalAmount($dataObject);
50-
$result[OrderItemInterface::BASE_ROW_TOTAL] = $this->priceRenderer->getBaseTotalAmount($dataObject);
51-
}
39+
public function execute(
40+
OrderItemInterface $dataObject,
41+
array $result
42+
): array {
43+
$result[OrderItemInterface::ROW_TOTAL] = $this->priceRenderer->getTotalAmount($dataObject);
44+
$result[OrderItemInterface::BASE_ROW_TOTAL] = $this->priceRenderer->getBaseTotalAmount($dataObject);
5245

5346
return $result;
5447
}

app/code/Magento/Sales/etc/webapi_rest/di.xml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@
1616
<plugin name="convert_blob_to_string" type="Magento\Sales\Plugin\ShippingLabelConverter" />
1717
</type>
1818
<type name="Magento\Framework\Reflection\DataObjectProcessor">
19-
<plugin name="change_row_total" type="Magento\Sales\Plugin\DataObjectProcessor" />
19+
<arguments>
20+
<argument name="processors" xsi:type="array">
21+
<item name="\Magento\Sales\Model\Order\Item" xsi:type="object">Magento\Sales\Model\Order\Webapi\ChangeOutputArray\Proxy</item>
22+
</argument>
23+
</arguments>
2024
</type>
2125
</config>

app/code/Magento/Sales/etc/webapi_soap/di.xml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@
1616
<plugin name="convert_blob_to_string" type="Magento\Sales\Plugin\ShippingLabelConverter" />
1717
</type>
1818
<type name="Magento\Framework\Reflection\DataObjectProcessor">
19-
<plugin name="change_row_total" type="Magento\Sales\Plugin\DataObjectProcessor" />
19+
<arguments>
20+
<argument name="processors" xsi:type="array">
21+
<item name="\Magento\Sales\Model\Order\Item" xsi:type="object">Magento\Sales\Model\Order\Webapi\ChangeOutputArray\Proxy</item>
22+
</argument>
23+
</arguments>
2024
</type>
2125
</config>

lib/internal/Magento/Framework/Reflection/DataObjectProcessor.php

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,25 +40,33 @@ class DataObjectProcessor
4040
*/
4141
private $customAttributesProcessor;
4242

43+
/**
44+
* @var array
45+
*/
46+
private $processors;
47+
4348
/**
4449
* @param MethodsMap $methodsMapProcessor
4550
* @param TypeCaster $typeCaster
4651
* @param FieldNamer $fieldNamer
4752
* @param CustomAttributesProcessor $customAttributesProcessor
4853
* @param ExtensionAttributesProcessor $extensionAttributesProcessor
54+
* @param array $processors
4955
*/
5056
public function __construct(
5157
MethodsMap $methodsMapProcessor,
5258
TypeCaster $typeCaster,
5359
FieldNamer $fieldNamer,
5460
CustomAttributesProcessor $customAttributesProcessor,
55-
ExtensionAttributesProcessor $extensionAttributesProcessor
61+
ExtensionAttributesProcessor $extensionAttributesProcessor,
62+
array $processors = []
5663
) {
5764
$this->methodsMapProcessor = $methodsMapProcessor;
5865
$this->typeCaster = $typeCaster;
5966
$this->fieldNamer = $fieldNamer;
6067
$this->extensionAttributesProcessor = $extensionAttributesProcessor;
6168
$this->customAttributesProcessor = $customAttributesProcessor;
69+
$this->processors = $processors;
6270
}
6371

6472
/**
@@ -121,6 +129,27 @@ public function buildOutputDataArray($dataObject, $dataObjectType)
121129

122130
$outputData[$key] = $value;
123131
}
132+
133+
$outputData = $this->changeOutputArray($dataObject, $outputData);
134+
135+
return $outputData;
136+
}
137+
138+
/**
139+
* Change output array if needed.
140+
*
141+
* @param mixed $dataObject
142+
* @param array $outputData
143+
* @return array
144+
*/
145+
private function changeOutputArray($dataObject, array $outputData): array
146+
{
147+
foreach ($this->processors as $dataObjectClassName => $processor) {
148+
if ($dataObject instanceof $dataObjectClassName) {
149+
$outputData = $processor->execute($dataObject, $outputData);
150+
}
151+
}
152+
124153
return $outputData;
125154
}
126155
}

0 commit comments

Comments
 (0)