Skip to content

Commit

Permalink
Hotfix: Incorrect attribute localization (#4441)
Browse files Browse the repository at this point in the history
* fixes #4437

* php-cs

* changed tests

* reverted unrelated changes

* minor improvement
  • Loading branch information
sreichel authored Jan 5, 2025
1 parent 6bd652a commit d4901af
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 3 deletions.
8 changes: 5 additions & 3 deletions app/code/core/Mage/Catalog/Model/Resource/Eav/Attribute.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* @category Mage
* @package Mage_Catalog
* @copyright Copyright (c) 2006-2020 Magento, Inc. (https://www.magento.com)
* @copyright Copyright (c) 2019-2024 The OpenMage Contributors (https://www.openmage.org)
* @copyright Copyright (c) 2019-2025 The OpenMage Contributors (https://www.openmage.org)
* @license https://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
*/

Expand Down Expand Up @@ -215,15 +215,17 @@ public function isScopeStore()
/**
* Retrieve store id
*
* @return int
* @return int|null
*/
public function getStoreId()
{
$dataObject = $this->getDataObject();
if ($dataObject) {
return $dataObject->getStoreId();
}
return (int) $this->getData('store_id');

$storeId = $this->getDataByKey('store_id');
return is_null($storeId) ? null : (int) $storeId;
}

/**
Expand Down
64 changes: 64 additions & 0 deletions tests/unit/Mage/Catalog/Model/Resource/Eav/AttributeTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?php

/**
* OpenMage
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available at https://opensource.org/license/osl-3-0-php
*
* @category OpenMage
* @package OpenMage_Tests
* @copyright Copyright (c) 2025 The OpenMage Contributors (https://www.openmage.org)
* @license https://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
*/

declare(strict_types=1);

namespace OpenMage\Tests\Unit\Mage\Catalog\Model\Resource\Eav;

use Generator;
use Mage;
use Mage_Catalog_Model_Resource_Eav_Attribute;
use PHPUnit\Framework\TestCase;

class AttributeTest extends TestCase
{
public Mage_Catalog_Model_Resource_Eav_Attribute $subject;

public function setUp(): void
{
Mage::app();
$this->subject = Mage::getModel('catalog/resource_eav_attribute');
}

/**
* @dataProvider provideGetStoreId
* @group Mage_Catalog
* @group Mage_Catalog_Model
* @group Mage_Catalog_Model_Resource
*/
public function testGetStoreId($expectedResult, $withStoreId): void
{
if ($withStoreId) {
$this->subject->setStoreId($withStoreId);
}
$this->assertSame($expectedResult, $this->subject->getStoreId());
}

public function provideGetStoreId(): Generator
{
yield 'string' => [
1,
'1',
];
yield 'int' => [
1,
1,
];
yield 'no store id' => [
null,
null,
];
}
}

0 comments on commit d4901af

Please sign in to comment.