Skip to content

Commit 1efad79

Browse files
authored
Merge pull request #2 from lbanka/fix-scope-id-validation
Fix scope_id validation when using default scope
2 parents 518819c + 2937507 commit 1efad79

File tree

3 files changed

+14
-10
lines changed

3 files changed

+14
-10
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
66

77
## [Unreleased]
88

9+
## [1.0.2] - 20 June 2023
10+
### Fixed
11+
- Fix scope_id validation when using default scope #2 @lbanka
12+
913
## [1.0.1] - 17 June 2023
1014
### Added
1115
- Allow to use scope codes #1 @lbanka

Console/Command/ThemeChangeCommand.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
8484
$themeName = trim($input->getArgument('theme_name'));
8585
$themeId = $this->getThemeId($themeName);
8686

87-
if (!$themeId > 0) {
87+
if (is_null($themeId)) {
8888
$output->writeln('<error>Not a valid theme: ' . $themeName . '</error>');
8989
return Command::FAILURE;
9090
}
@@ -111,8 +111,8 @@ protected function execute(InputInterface $input, OutputInterface $output): int
111111
}
112112
}
113113

114-
if (!$scopeId > 0) {
115-
$output->writeln('<error>Not a valid scopeId: ' . $scopeId . '</error>');
114+
if (is_null($scopeId)) {
115+
$output->writeln('<error>Not a valid scope_id</error>');
116116
return Command::FAILURE;
117117
}
118118

@@ -126,24 +126,24 @@ protected function execute(InputInterface $input, OutputInterface $output): int
126126
return Command::SUCCESS;
127127
}
128128

129-
private function getThemeId(string $themeName): int
129+
private function getThemeId(string $themeName): ?int
130130
{
131131
$themeModel = $this->themeFactory->create();
132132
$this->themeResourceModel->load($themeModel, $themeName, 'theme_path');
133-
return (int)$themeModel->getId();
133+
return $themeModel->getId() ? (int)$themeModel->getId() : null;
134134
}
135135

136-
private function getWebsiteId(string $scopeId): int
136+
private function getWebsiteId(string $scopeId): ?int
137137
{
138138
$websiteModel = $this->websiteFactory->create();
139139
$this->websiteResourceModel->load($websiteModel, $scopeId, 'code');
140-
return (int)$websiteModel->getId();
140+
return $websiteModel->getId() ? (int)$websiteModel->getId() : null;
141141
}
142142

143-
private function getStoreId(string $scopeId): int
143+
private function getStoreId(string $scopeId): ?int
144144
{
145145
$storeModel = $this->storeFactory->create();
146146
$this->storeResourceModel->load($storeModel, $scopeId, 'code');
147-
return (int)$storeModel->getId();
147+
return $storeModel->getId() ? (int)$storeModel->getId() : null;
148148
}
149149
}

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "yireo/magento2-theme-commands",
3-
"version": "1.0.1",
3+
"version": "1.0.2",
44
"license": "OSL-3.0",
55
"description": "CLI commands to manipulate themes",
66
"type": "magento2-module",

0 commit comments

Comments
 (0)