Description
Preconditions and environment
Tested on
- 2.4.8
- 2.4.7
- PHP 8.2
- PHP 8.3
Steps to reproduce
- Deploy vanilla magento and install sample data.
- Run the following test code in the root which demonstrates the problem by getting the status of the product (enabled/disabled) and printing the return type of the getStatus() call.
use Magento\Framework\App\Bootstrap;
use Magento\Catalog\Api\ProductRepositoryInterface;
require __DIR__ . '/app/bootstrap.php';
$productRepository = Bootstrap::create(BP, $_SERVER)
->getObjectManager()
->create(ProductRepositoryInterface::class);
$product = $productRepository->get("24-MB01");
$status = $product->getStatus();
echo "Return type of getStatus() is : " . gettype($status) . PHP_EOL;
return;
Expected result
Return type of getStatus() is : int
Actual result
Return type of getStatus() is : string
Additional information
The Status Product Attribute is defined in core Magento as an integer.
When products are created, the Attribute "status" is stored in the catalog_product_entity_int
table confirming it is typed as integer.
The Magento ProductInterface defines the call getStatus() as returning an int or null.
magento2/app/code/Magento/Catalog/Api/Data/ProductInterface.php
Lines 133 to 138 in c8ba4ab
Yet calls to $product->getStatus() return a string.
The same thing happens when retrieving float values, for example $product->getPrice() returns a string despite the Interface mandating float or null.
magento2/app/code/Magento/Catalog/Api/Data/ProductInterface.php
Lines 118 to 123 in c8ba4ab
EDIT : I'm willing to concede on getPrice as Price is stored as a DECIMAL type in MySQL which is a fixed precision string representation of a floating point number, and not a float.
Release note
No response
Triage and priority
- Severity: S0 - Affects critical data or functionality and leaves users without workaround.
- Severity: S1 - Affects critical data or functionality and forces users to employ a workaround.
- Severity: S2 - Affects non-critical data or functionality and forces users to employ a workaround.
- Severity: S3 - Affects non-critical data or functionality and does not force users to employ a workaround.
- Severity: S4 - Affects aesthetics, professional look and feel, “quality” or “usability”.
Metadata
Metadata
Assignees
Labels
Type
Projects
Status