Skip to content

Commit 0b7a99d

Browse files
author
a.chorniy
committed
Issue-25968 - Added additional checking for returning needed variable type
1 parent 1ad65a3 commit 0b7a99d

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

app/code/Magento/Sales/Model/Order/Item.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1319,7 +1319,13 @@ public function getParentItemId()
13191319
*/
13201320
public function getPrice()
13211321
{
1322-
return $this->getData(OrderItemInterface::PRICE);
1322+
$price = $this->getData(OrderItemInterface::PRICE);
1323+
1324+
if ($price === null) {
1325+
return $price;
1326+
}
1327+
1328+
return (float) $price;
13231329
}
13241330

13251331
/**

app/code/Magento/Sales/Test/Unit/Model/Order/ItemTest.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,4 +348,22 @@ public function getItemQtyVariants()
348348
]
349349
];
350350
}
351+
352+
/**
353+
* Test getPrice() method
354+
*/
355+
public function testGetPrice()
356+
{
357+
$price = 9.99;
358+
$this->model->setPrice($price);
359+
$this->assertEquals($price, $this->model->getPrice());
360+
361+
$newPrice = 5.53;
362+
$this->model->setData(\Magento\Sales\Api\Data\OrderItemInterface::PRICE, $newPrice);
363+
$this->assertEquals($newPrice, $this->model->getPrice());
364+
365+
$nullablePrice = null;
366+
$this->model->setPrice($nullablePrice);
367+
$this->assertEquals($nullablePrice, $this->model->getPrice());
368+
}
351369
}

0 commit comments

Comments
 (0)