Skip to content

Commit 723ff52

Browse files
committed
Merge branch 'issue-35964' of github.com:rogerdz/magento2 into 2.4-develop-prs
2 parents 51f7724 + 3f4c7f0 commit 723ff52

File tree

8 files changed

+141
-10
lines changed

8 files changed

+141
-10
lines changed

app/code/Magento/Bundle/Block/Adminhtml/Sales/Order/Items/Renderer.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55
*/
66
namespace Magento\Bundle\Block\Adminhtml\Sales\Order\Items;
77

8+
use Magento\Catalog\Helper\Data as CatalogHelper;
89
use Magento\Catalog\Model\Product\Type\AbstractType;
9-
use Magento\Framework\Serialize\Serializer\Json;
1010
use Magento\Framework\App\ObjectManager;
11-
use Magento\Catalog\Helper\Data as CatalogHelper;
11+
use Magento\Framework\Serialize\Serializer\Json;
1212

1313
/**
1414
* Adminhtml sales order item renderer
@@ -19,7 +19,7 @@
1919
class Renderer extends \Magento\Sales\Block\Adminhtml\Items\Renderer\DefaultRenderer
2020
{
2121
/**
22-
* Serializer
22+
* Serializer interface instance.
2323
*
2424
* @var Json
2525
*/
@@ -248,7 +248,7 @@ public function getValueHtml($item)
248248
if (!$this->isShipmentSeparately($item)) {
249249
$attributes = $this->getSelectionAttributes($item);
250250
if ($attributes) {
251-
$result = sprintf('%d', $attributes['qty']) . ' x ' . $result;
251+
$result = (float) $attributes['qty'] . ' x ' . $result;
252252
}
253253
}
254254
if (!$this->isChildCalculated($item)) {

app/code/Magento/Bundle/Block/Adminhtml/Sales/Order/View/Items/Renderer.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55
*/
66
namespace Magento\Bundle\Block\Adminhtml\Sales\Order\View\Items;
77

8+
use Magento\Catalog\Helper\Data as CatalogHelper;
89
use Magento\Catalog\Model\Product\Type\AbstractType;
910
use Magento\Framework\App\ObjectManager;
1011
use Magento\Framework\Serialize\Serializer\Json;
11-
use Magento\Catalog\Helper\Data as CatalogHelper;
1212

1313
/**
1414
* Adminhtml sales order item renderer
@@ -203,7 +203,7 @@ public function getValueHtml($item)
203203
if (!$this->isShipmentSeparately($item)) {
204204
$attributes = $this->getSelectionAttributes($item);
205205
if ($attributes) {
206-
$result = sprintf('%d', $attributes['qty']) . ' x ' . $result;
206+
$result = (float) $attributes['qty'] . ' x ' . $result;
207207
}
208208
}
209209
if (!$this->isChildCalculated($item)) {

app/code/Magento/Bundle/Block/Sales/Order/Items/Renderer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ public function getSelectionAttributes($item)
150150
public function getValueHtml($item)
151151
{
152152
if ($attributes = $this->getSelectionAttributes($item)) {
153-
return sprintf('%d', $attributes['qty']) . ' x ' . $this->escapeHtml($item->getName()) . " "
153+
return (float) $attributes['qty'] . ' x ' . $this->escapeHtml($item->getName()) . " "
154154
. $this->getOrder()->formatPrice($attributes['price']);
155155
}
156156
return $this->escapeHtml($item->getName());

app/code/Magento/Bundle/Model/Sales/Order/Pdf/Items/AbstractItems.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
abstract class AbstractItems extends \Magento\Sales\Model\Order\Pdf\Items\AbstractItems
2424
{
2525
/**
26-
* Serializer
26+
* Serializer interface instance.
2727
*
2828
* @var Json
2929
*/
@@ -263,7 +263,8 @@ public function getValueHtml($item)
263263
if (!$this->isShipmentSeparately($item)) {
264264
$attributes = $this->getSelectionAttributes($item);
265265
if ($attributes) {
266-
$result = $this->filterManager->sprintf($attributes['qty'], ['format' => '%d']) . ' x ' . $result;
266+
$qty = $this->filterManager->sprintf($attributes['qty'], ['format' => '%f']);
267+
$result = (float) $qty . ' x ' . $result;
267268
}
268269
}
269270
if (!$this->isChildCalculated($item)) {

app/code/Magento/Bundle/Test/Unit/Block/Adminhtml/Sales/Order/Items/RendererTest.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,4 +310,31 @@ public function canShowPriceInfoDataProvider()
310310
[false, ['product_calculations' => 0], false],
311311
];
312312
}
313+
314+
/**
315+
* @dataProvider getValueHtmlWithoutShipmentSeparatelyDataProvider
316+
*/
317+
public function testGetValueHtmlWithoutShipmentSeparately($qty)
318+
{
319+
$model = $this->getMockBuilder(Renderer::class)
320+
->disableOriginalConstructor()
321+
->setMethods(['escapeHtml', 'isShipmentSeparately', 'getSelectionAttributes', 'isChildCalculated'])
322+
->getMock();
323+
$model->expects($this->any())->method('escapeHtml')->willReturn('Test');
324+
$model->expects($this->any())->method('isShipmentSeparately')->willReturn(false);
325+
$model->expects($this->any())->method('isChildCalculated')->willReturn(true);
326+
$model->expects($this->any())->method('getSelectionAttributes')->willReturn(['qty' => $qty]);
327+
$this->assertSame($qty . ' x Test', $model->getValueHtml($this->orderItem));
328+
}
329+
330+
/**
331+
* @return array
332+
*/
333+
public function getValueHtmlWithoutShipmentSeparatelyDataProvider()
334+
{
335+
return [
336+
[1],
337+
[1.5],
338+
];
339+
}
313340
}

app/code/Magento/Bundle/Test/Unit/Block/Adminhtml/Sales/Order/View/Items/RendererTest.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,4 +224,31 @@ public function canShowPriceInfoDataProvider()
224224
[false, ['product_calculations' => 0], false],
225225
];
226226
}
227+
228+
/**
229+
* @dataProvider getValueHtmlWithoutShipmentSeparatelyDataProvider
230+
*/
231+
public function testGetValueHtmlWithoutShipmentSeparately($qty)
232+
{
233+
$model = $this->getMockBuilder(Renderer::class)
234+
->disableOriginalConstructor()
235+
->setMethods(['escapeHtml', 'isShipmentSeparately', 'getSelectionAttributes', 'isChildCalculated'])
236+
->getMock();
237+
$model->expects($this->any())->method('escapeHtml')->willReturn('Test');
238+
$model->expects($this->any())->method('isShipmentSeparately')->willReturn(false);
239+
$model->expects($this->any())->method('isChildCalculated')->willReturn(true);
240+
$model->expects($this->any())->method('getSelectionAttributes')->willReturn(['qty' => $qty]);
241+
$this->assertSame($qty . ' x Test', $model->getValueHtml($this->orderItem));
242+
}
243+
244+
/**
245+
* @return array
246+
*/
247+
public function getValueHtmlWithoutShipmentSeparatelyDataProvider()
248+
{
249+
return [
250+
[1],
251+
[1.5],
252+
];
253+
}
227254
}

app/code/Magento/Bundle/Test/Unit/Block/Sales/Order/Items/RendererTest.php

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,4 +286,41 @@ public function canShowPriceInfoDataProvider()
286286
[false, ['product_calculations' => 0], false],
287287
];
288288
}
289+
290+
/**
291+
* @dataProvider getValueHtmlWithAttributesDataProvider
292+
*/
293+
public function testGetValueHtmlWithAttributes($qty)
294+
{
295+
$price = 100;
296+
$orderModel = $this->getMockBuilder(\Magento\Sales\Model\Order::class)
297+
->disableOriginalConstructor()
298+
->onlyMethods(['formatPrice'])
299+
->getMock();
300+
$orderModel->expects($this->any())->method('formatPrice')->willReturn($price);
301+
302+
$model = $this->getMockBuilder(Renderer::class)
303+
->disableOriginalConstructor()
304+
->setMethods(['getOrder', 'getSelectionAttributes', 'escapeHtml'])
305+
->getMock();
306+
$model->expects($this->any())->method('escapeHtml')->willReturn('Test');
307+
$model->expects($this->any())->method('getOrder')->willReturn($orderModel);
308+
$model->expects($this->any())->method('getSelectionAttributes')
309+
->willReturn([
310+
'qty' => $qty ,
311+
'price' => $price,
312+
]);
313+
$this->assertSame($qty . ' x Test ' . $price, $model->getValueHtml($this->orderItem));
314+
}
315+
316+
/**
317+
* @return array
318+
*/
319+
public function getValueHtmlWithAttributesDataProvider()
320+
{
321+
return [
322+
[1],
323+
[1.5],
324+
];
325+
}
289326
}

app/code/Magento/Bundle/Test/Unit/Model/Sales/Order/Pdf/Items/AbstractItemsTest.php

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
namespace Magento\Bundle\Test\Unit\Model\Sales\Order\Pdf\Items;
99

1010
use Magento\Bundle\Model\Sales\Order\Pdf\Items\Shipment;
11+
use Magento\Framework\Filter\FilterManager;
1112
use Magento\Framework\Serialize\Serializer\Json;
1213
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
1314
use Magento\Sales\Model\Order\Creditmemo;
@@ -33,20 +34,30 @@ class AbstractItemsTest extends TestCase
3334
*/
3435
private $orderItemMock;
3536

37+
/**
38+
* @var FilterManager|MockObject
39+
*/
40+
private $filterManagerMock;
41+
3642
protected function setUp(): void
3743
{
3844
$this->orderItemMock = $this->getMockBuilder(Item::class)
3945
->addMethods(['getOrderItem', 'getOrderItemId'])
4046
->onlyMethods(['getProductOptions', 'getParentItem', 'getId'])
4147
->disableOriginalConstructor()
4248
->getMock();
49+
$this->filterManagerMock = $this->getMockBuilder(FilterManager::class)
50+
->disableOriginalConstructor()
51+
->setMethods(['stripTags', 'sprintf'])
52+
->getMock();
4353

4454
$objectManager = new ObjectManager($this);
4555
$this->serializerMock = $this->createMock(Json::class);
4656
$this->model = $objectManager->getObject(
4757
Shipment::class,
4858
[
49-
'serializer' => $this->serializerMock
59+
'serializer' => $this->serializerMock,
60+
'filterManager' => $this->filterManagerMock,
5061
]
5162
);
5263
}
@@ -358,4 +369,32 @@ public function canShowPriceInfoDataProvider()
358369
[false, ['product_calculations' => 0], false],
359370
];
360371
}
372+
373+
/**
374+
* @dataProvider getValueHtmlWithoutShipmentSeparatelyDataProvider
375+
*/
376+
public function testGetValueHtmlWithoutShipmentSeparately($qty)
377+
{
378+
$this->filterManagerMock->expects($this->any())->method('stripTags')->willReturn('Test');
379+
$this->filterManagerMock->expects($this->any())->method('sprintf')->willReturn($qty);
380+
$this->orderItemMock->expects($this->any())->method('getProductOptions')
381+
->willReturn([
382+
'shipment_type' => 1,
383+
'bundle_selection_attributes' => [],
384+
]);
385+
$this->serializerMock->expects($this->any())->method('unserialize')
386+
->willReturn(['qty' => $qty]);
387+
$this->assertSame($qty . ' x Test', $this->model->getValueHtml($this->orderItemMock));
388+
}
389+
390+
/**
391+
* @return array
392+
*/
393+
public function getValueHtmlWithoutShipmentSeparatelyDataProvider()
394+
{
395+
return [
396+
[1],
397+
[1.5],
398+
];
399+
}
361400
}

0 commit comments

Comments
 (0)