Skip to content

Commit 1d6a8bb

Browse files
authored
Hotfix: core_store.store_id can be null (#4330)
* fix - store entity id null * variable name [skip ci] * added test * test [skip ci] * change * test [skip ci]
1 parent ca4f321 commit 1d6a8bb

File tree

5 files changed

+66
-30
lines changed

5 files changed

+66
-30
lines changed

.phpstan.dist.baseline.neon

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -690,11 +690,6 @@ parameters:
690690
count: 1
691691
path: app/code/core/Mage/Adminhtml/Model/Sales/Order/Create.php
692692

693-
-
694-
message: "#^Parameter \\#3 \\$storeId of method Mage_Customer_Model_Customer\\:\\:sendNewAccountEmail\\(\\) expects string, int given\\.$#"
695-
count: 1
696-
path: app/code/core/Mage/Adminhtml/Model/Sales/Order/Create.php
697-
698693
-
699694
message: "#^Variable \\$billingAddress might not be defined\\.$#"
700695
count: 2
@@ -2460,11 +2455,6 @@ parameters:
24602455
count: 1
24612456
path: app/code/core/Mage/Catalog/Model/Resource/Product.php
24622457

2463-
-
2464-
message: "#^Parameter \\#1 \\$expression of class Zend_Db_Expr constructor expects string, int given\\.$#"
2465-
count: 2
2466-
path: app/code/core/Mage/Catalog/Model/Resource/Product.php
2467-
24682458
-
24692459
message: "#^Method Mage_Catalog_Model_Resource_Product_Attribute_Backend_Media\\:\\:insertGallery\\(\\) should return int but returns string\\.$#"
24702460
count: 1
@@ -3115,11 +3105,6 @@ parameters:
31153105
count: 1
31163106
path: app/code/core/Mage/Checkout/Model/Type/Onepage.php
31173107

3118-
-
3119-
message: "#^Parameter \\#3 \\$storeId of method Mage_Customer_Model_Customer\\:\\:sendNewAccountEmail\\(\\) expects string, int given\\.$#"
3120-
count: 2
3121-
path: app/code/core/Mage/Checkout/Model/Type/Onepage.php
3122-
31233108
-
31243109
message: "#^Property Mage_Checkout_Model_Type_Onepage\\:\\:\\$_quote \\(Mage_Sales_Model_Quote\\) on left side of \\?\\? is not nullable\\.$#"
31253110
count: 1
@@ -3960,11 +3945,6 @@ parameters:
39603945
count: 1
39613946
path: app/code/core/Mage/Customer/Model/Session.php
39623947

3963-
-
3964-
message: "#^Parameter \\#3 \\$storeId of method Mage_Customer_Model_Customer\\:\\:sendNewAccountEmail\\(\\) expects string, int given\\.$#"
3965-
count: 3
3966-
path: app/code/core/Mage/Customer/controllers/AccountController.php
3967-
39683948
-
39693949
message: "#^Method Mage_Dataflow_Model_Batch\\:\\:setParams\\(\\) should return Mage_Dataflow_Model_Batch_Abstract but returns \\$this\\(Mage_Dataflow_Model_Batch\\)\\.$#"
39703950
count: 1
@@ -5140,11 +5120,6 @@ parameters:
51405120
count: 1
51415121
path: app/code/core/Mage/Paypal/Model/Express/Checkout.php
51425122

5143-
-
5144-
message: "#^Parameter \\#3 \\$storeId of method Mage_Customer_Model_Customer\\:\\:sendNewAccountEmail\\(\\) expects string, int given\\.$#"
5145-
count: 2
5146-
path: app/code/core/Mage/Paypal/Model/Express/Checkout.php
5147-
51485123
-
51495124
message: "#^Variable \\$shippingAddress might not be defined\\.$#"
51505125
count: 1

app/code/core/Mage/Catalog/Model/Resource/Product.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,7 @@ public function refreshEnabledIndex($store = null, $product = null)
397397

398398
$selectFields = [
399399
't_v_default.entity_id',
400-
new Zend_Db_Expr($storeId),
400+
new Zend_Db_Expr((string)$storeId),
401401
$adapter->getCheckSql('t_v.value_id > 0', 't_v.value', 't_v_default.value'),
402402
];
403403

@@ -426,7 +426,7 @@ public function refreshEnabledIndex($store = null, $product = null)
426426

427427
$selectFields = [
428428
new Zend_Db_Expr($productId),
429-
new Zend_Db_Expr($storeId),
429+
new Zend_Db_Expr((string)$storeId),
430430
$adapter->getCheckSql('t_v.value_id > 0', 't_v.value', 't_v_default.value')
431431
];
432432

app/code/core/Mage/Core/Model/Store.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -699,11 +699,12 @@ public function getStoreInUrl()
699699
/**
700700
* Get store identifier
701701
*
702-
* @return int
702+
* @return int|null
703703
*/
704704
public function getId()
705705
{
706-
return (int)$this->_getData('store_id');
706+
$storeId = $this->_getData('store_id');
707+
return is_null($storeId) ? null : (int)$storeId;
707708
}
708709

709710
/**

app/code/core/Mage/Customer/Model/Customer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -717,7 +717,7 @@ public function isAddressPrimary(Mage_Customer_Model_Address $address)
717717
*
718718
* @param string $type
719719
* @param string $backUrl
720-
* @param string $storeId
720+
* @param string|int $storeId
721721
* @param string $password
722722
* @throws Mage_Core_Exception
723723
* @return $this
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
<?php
2+
3+
/**
4+
* OpenMage
5+
*
6+
* This source file is subject to the Open Software License (OSL 3.0)
7+
* that is bundled with this package in the file LICENSE.txt.
8+
* It is also available at https://opensource.org/license/osl-3-0-php
9+
*
10+
* @category OpenMage
11+
* @package OpenMage_Tests
12+
* @copyright Copyright (c) 2024 The OpenMage Contributors (https://www.openmage.org)
13+
* @license https://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
14+
*/
15+
16+
declare(strict_types=1);
17+
18+
namespace OpenMage\Tests\Unit\Mage\Core\Model;
19+
20+
use Generator;
21+
use Mage;
22+
use Mage_Core_Model_Store;
23+
use PHPUnit\Framework\TestCase;
24+
25+
class StoreTest extends TestCase
26+
{
27+
public Mage_Core_Model_Store $subject;
28+
29+
public function setUp(): void
30+
{
31+
Mage::app();
32+
$this->subject = Mage::getModel('core/store');
33+
}
34+
35+
/**
36+
* @covers Mage_Core_Model_Store::getId()
37+
* @dataProvider provideGetId
38+
* @group Mage_Core
39+
* @group Mage_Core_Model
40+
*/
41+
public function testGetId(?int $expectedResult, ?string $withStore): void
42+
{
43+
if ($withStore) {
44+
$this->subject->setData('store_id', $withStore);
45+
}
46+
$this->assertSame($expectedResult, $this->subject->getId());
47+
}
48+
49+
public function provideGetId(): Generator
50+
{
51+
yield 'store id' => [
52+
1,
53+
'1',
54+
];
55+
yield 'no store id' => [
56+
null,
57+
null,
58+
];
59+
}
60+
}

0 commit comments

Comments
 (0)