Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue-25968 - Added additional checking for returning needed variable… #26313

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion app/code/Magento/Sales/Model/Order/Item.php
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,8 @@ public function getStatus()
*
* @param string $statusId
* @return \Magento\Framework\Phrase
*
* phpcs:disable Magento2.Functions.StaticFunction
*/
public static function getStatusName($statusId)
{
Expand Down Expand Up @@ -422,6 +424,8 @@ public function cancel()
* Retrieve order item statuses array
*
* @return array
*
* phpcs:disable Magento2.Functions.StaticFunction
*/
public static function getStatuses()
{
Expand Down Expand Up @@ -1319,7 +1323,13 @@ public function getParentItemId()
*/
public function getPrice()
{
return $this->getData(OrderItemInterface::PRICE);
$price = $this->getData(OrderItemInterface::PRICE);

if ($price === null) {
return $price;
}

return (float) $price;
}

/**
Expand Down
30 changes: 24 additions & 6 deletions app/code/Magento/Sales/Test/Unit/Model/Order/ItemTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,11 @@
namespace Magento\Sales\Test\Unit\Model\Order;

use Magento\Framework\Serialize\Serializer\Json;
use Magento\Sales\Api\Data\OrderItemInterface;
use Magento\Sales\Model\ResourceModel\OrderFactory;
use \Magento\Sales\Model\Order;

/**
* Class ItemTest
*
* @package Magento\Sales\Model\Order
* Unit test for order item class.
*/
class ItemTest extends \PHPUnit\Framework\TestCase
{
Expand Down Expand Up @@ -72,7 +70,7 @@ public function testSetParentItem()
public function testGetPatentItem()
{
$item = $this->objectManager->getObject(\Magento\Sales\Model\Order\Item::class, []);
$this->model->setData(\Magento\Sales\Api\Data\OrderItemInterface::PARENT_ITEM, $item);
$this->model->setData(OrderItemInterface::PARENT_ITEM, $item);
$this->assertEquals($item, $this->model->getParentItem());
}

Expand Down Expand Up @@ -184,7 +182,7 @@ public function testGetOriginalPrice()
$this->assertEquals($price, $this->model->getOriginalPrice());

$originalPrice = 5.55;
$this->model->setData(\Magento\Sales\Api\Data\OrderItemInterface::ORIGINAL_PRICE, $originalPrice);
$this->model->setData(OrderItemInterface::ORIGINAL_PRICE, $originalPrice);
$this->assertEquals($originalPrice, $this->model->getOriginalPrice());
}

Expand Down Expand Up @@ -348,4 +346,24 @@ public function getItemQtyVariants()
]
];
}

/**
* Test getPrice() method returns float
*/
public function testGetPriceReturnsFloat()
{
$price = 9.99;
$this->model->setPrice($price);
$this->assertEquals($price, $this->model->getPrice());
}

/**
* Test getPrice() method returns null
*/
public function testGetPriceReturnsNull()
{
$nullablePrice = null;
$this->model->setData(OrderItemInterface::PRICE, $nullablePrice);
$this->assertEquals($nullablePrice, $this->model->getPrice());
}
}