Skip to content

Commit 139a89f

Browse files
Add product reviews (#4747)
2 parents e437e1b + 16da33a commit 139a89f

2 files changed

Lines changed: 139 additions & 0 deletions

File tree

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Shopsys\Cli\Config\Section;
6+
7+
use Override;
8+
use Shopsys\Cli\Config\DomainConfigSectionInterface;
9+
use Symfony\Component\Console\Style\SymfonyStyle;
10+
11+
class ProductReviewsSection implements DomainConfigSectionInterface
12+
{
13+
public bool $enabled = true;
14+
15+
/**
16+
* {@inheritdoc}
17+
*/
18+
#[Override]
19+
public static function getKey(): string
20+
{
21+
return 'product_reviews';
22+
}
23+
24+
/**
25+
* {@inheritdoc}
26+
*/
27+
#[Override]
28+
public function collectInteractive(SymfonyStyle $io, int $domainId): void
29+
{
30+
$io->section(sprintf('Product Reviews Settings for Domain %d', $domainId));
31+
32+
$this->enabled = $io->confirm('Enable product reviews?', $this->enabled);
33+
}
34+
35+
/**
36+
* {@inheritdoc}
37+
*/
38+
#[Override]
39+
public function fromArray(array $data): void
40+
{
41+
$this->enabled = (bool)($data['enabled'] ?? $this->enabled);
42+
}
43+
44+
/**
45+
* {@inheritdoc}
46+
*/
47+
#[Override]
48+
public function validate(): void
49+
{
50+
// No specific validation needed for boolean values
51+
}
52+
53+
/**
54+
* {@inheritdoc}
55+
*/
56+
#[Override]
57+
public function toArray(): array
58+
{
59+
return [
60+
'enabled' => $this->enabled,
61+
];
62+
}
63+
}
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Shopsys\Cli\Worker\Backend;
6+
7+
use Override;
8+
use Shopsys\Cli\Config\CoreProjectConfig;
9+
use Shopsys\Cli\Config\Section\ProductReviewsSection;
10+
use Shopsys\Cli\Model\YamlHandler;
11+
use Shopsys\Cli\Worker\AbstractWorker;
12+
use Shopsys\Cli\Worker\WorkerResult;
13+
14+
final class ProductReviewsConfigWorker extends AbstractWorker
15+
{
16+
private const string FILE_PATH = 'app/config/packages/shopsys_framework.yaml';
17+
18+
public function __construct(
19+
private readonly YamlHandler $yamlHandler,
20+
) {
21+
}
22+
23+
/**
24+
* {@inheritdoc}
25+
*/
26+
#[Override]
27+
public function getDescription(): string
28+
{
29+
return 'Updates product reviews enabled_domain_ids in shopsys_framework.yaml';
30+
}
31+
32+
/**
33+
* {@inheritdoc}
34+
*/
35+
#[Override]
36+
public function getPriority(): int
37+
{
38+
return 760;
39+
}
40+
41+
/**
42+
* {@inheritdoc}
43+
*/
44+
#[Override]
45+
public function execute(CoreProjectConfig $config, string $projectPath): WorkerResult
46+
{
47+
$filePath = $projectPath . '/' . self::FILE_PATH;
48+
49+
$data = $this->yamlHandler->readYaml($filePath);
50+
51+
$data['shopsys_framework']['product']['reviews']['enabled_domain_ids'] = $this->getEnabledDomainIds($config);
52+
53+
$this->yamlHandler->writeYaml($filePath, $data, 6);
54+
55+
return WorkerResult::success(
56+
'Updated shopsys_framework.yaml',
57+
filesModified: [self::FILE_PATH],
58+
);
59+
}
60+
61+
/**
62+
* @return array<int>
63+
*/
64+
private function getEnabledDomainIds(CoreProjectConfig $config): array
65+
{
66+
$enabledDomainIds = [];
67+
68+
foreach ($config->domains as $domain) {
69+
if ($domain->getConfigSection(ProductReviewsSection::class)->enabled) {
70+
$enabledDomainIds[] = $domain->id;
71+
}
72+
}
73+
74+
return $enabledDomainIds;
75+
}
76+
}

0 commit comments

Comments
 (0)