Skip to content

Commit aafb561

Browse files
ENGCOM-5662: getStoreValuesForForm($empty = false, $all = false) has bad logic (undefine variable) #24167
- Merge Pull Request #24167 from edenduong/magento2:2.3-refactor/get_store_for_form_refactor - Merged commits: 1. 9588fd2 2. f37da1e
2 parents 2bc471e + f37da1e commit aafb561

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

app/code/Magento/Store/Model/System/Store.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
7+
declare(strict_types=1);
8+
69
namespace Magento\Store\Model\System;
710

811
use Magento\Framework\Data\OptionSourceInterface;
@@ -118,6 +121,7 @@ public function getStoreValuesForForm($empty = false, $all = false)
118121
$options[] = ['label' => __('All Store Views'), 'value' => 0];
119122
}
120123

124+
// phpcs:ignore Magento2.Functions.DiscouragedFunction
121125
$nonEscapableNbspChar = html_entity_decode(' ', ENT_NOQUOTES, 'UTF-8');
122126

123127
foreach ($this->_websiteCollection as $website) {
@@ -126,7 +130,7 @@ public function getStoreValuesForForm($empty = false, $all = false)
126130
if ($website->getId() != $group->getWebsiteId()) {
127131
continue;
128132
}
129-
$groupShow = false;
133+
$values = [];
130134
foreach ($this->_storeCollection as $store) {
131135
if ($group->getId() != $store->getGroupId()) {
132136
continue;
@@ -135,16 +139,12 @@ public function getStoreValuesForForm($empty = false, $all = false)
135139
$options[] = ['label' => $website->getName(), 'value' => []];
136140
$websiteShow = true;
137141
}
138-
if (!$groupShow) {
139-
$groupShow = true;
140-
$values = [];
141-
}
142142
$values[] = [
143143
'label' => str_repeat($nonEscapableNbspChar, 4) . $store->getName(),
144144
'value' => $store->getId(),
145145
];
146146
}
147-
if ($groupShow) {
147+
if (!empty($values)) {
148148
$options[] = [
149149
'label' => str_repeat($nonEscapableNbspChar, 4) . $group->getName(),
150150
'value' => $values,
@@ -398,6 +398,7 @@ public function getStoreCollection()
398398

399399
/**
400400
* Load/Reload collection(s) by type
401+
*
401402
* Allowed types: website, group, store or null for all
402403
*
403404
* @param string $type

0 commit comments

Comments
 (0)