|
1
|
|
|
<?php declare(strict_types=1); |
|
2
|
|
|
|
|
3
|
|
|
namespace Shopware\Storefront\Framework\Command; |
|
4
|
|
|
|
|
5
|
|
|
use Shopware\Core\Defaults; |
|
6
|
|
|
use Shopware\Core\Framework\Context; |
|
7
|
|
|
use Shopware\Core\Framework\DataAbstractionLayer\EntityRepository; |
|
8
|
|
|
use Shopware\Core\Framework\DataAbstractionLayer\Search\Criteria; |
|
9
|
|
|
use Shopware\Core\Framework\DataAbstractionLayer\Search\Filter\EqualsFilter; |
|
10
|
|
|
use Shopware\Core\Framework\Log\Package; |
|
11
|
|
|
use Shopware\Core\Maintenance\SalesChannel\Command\SalesChannelCreateCommand; |
|
12
|
|
|
use Shopware\Core\Maintenance\SalesChannel\Service\SalesChannelCreator; |
|
13
|
|
|
use Symfony\Component\Console\Attribute\AsCommand; |
|
14
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
15
|
|
|
use Symfony\Component\Console\Input\InputOption; |
|
16
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* @final |
|
20
|
|
|
*/ |
|
21
|
|
|
#[AsCommand( |
|
22
|
|
|
name: 'sales-channel:create:storefront', |
|
23
|
|
|
description: 'Creates a new storefront sales channel', |
|
24
|
|
|
)] |
|
25
|
|
|
#[Package('storefront')] |
|
26
|
|
|
class SalesChannelCreateStorefrontCommand extends SalesChannelCreateCommand |
|
27
|
|
|
{ |
|
28
|
|
|
/** |
|
29
|
|
|
* @internal |
|
30
|
|
|
*/ |
|
31
|
|
|
public function __construct( |
|
32
|
|
|
private readonly EntityRepository $snippetSetRepository, |
|
33
|
|
|
SalesChannelCreator $salesChannelCreator |
|
34
|
|
|
) { |
|
35
|
|
|
parent::__construct( |
|
36
|
|
|
$salesChannelCreator |
|
37
|
|
|
); |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
protected function configure(): void |
|
41
|
|
|
{ |
|
42
|
|
|
parent::configure(); |
|
43
|
|
|
|
|
44
|
|
|
$this |
|
45
|
|
|
->addOption('url', null, InputOption::VALUE_REQUIRED, 'App URL for storefront') |
|
46
|
|
|
->addOption('snippetSetId', null, InputOption::VALUE_REQUIRED, 'Default snippet set') |
|
47
|
|
|
->addOption('isoCode', null, InputOption::VALUE_REQUIRED, 'Snippet set iso code') |
|
48
|
|
|
; |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
protected function getTypeId(): string |
|
52
|
|
|
{ |
|
53
|
|
|
return Defaults::SALES_CHANNEL_TYPE_STOREFRONT; |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
protected function getSalesChannelConfiguration(InputInterface $input, OutputInterface $output): array |
|
57
|
|
|
{ |
|
58
|
|
|
$snippetSet = $input->getOption('snippetSetId') ?? $this->guessSnippetSetId($input->getOption('isoCode')); |
|
59
|
|
|
|
|
60
|
|
|
return [ |
|
61
|
|
|
'domains' => [ |
|
62
|
|
|
[ |
|
63
|
|
|
'url' => $input->getOption('url'), |
|
64
|
|
|
'languageId' => $input->getOption('languageId'), |
|
65
|
|
|
'snippetSetId' => $snippetSet, |
|
66
|
|
|
'currencyId' => $input->getOption('currencyId'), |
|
67
|
|
|
], |
|
68
|
|
|
], |
|
69
|
|
|
'navigationCategoryDepth' => 3, |
|
70
|
|
|
'name' => $input->getOption('name') ?? 'Storefront', |
|
71
|
|
|
]; |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
private function guessSnippetSetId(?string $isoCode = 'en-GB'): string |
|
75
|
|
|
{ |
|
76
|
|
|
$snippetSet = $this->getSnippetSetId($isoCode); |
|
77
|
|
|
|
|
78
|
|
|
if ($snippetSet === null) { |
|
79
|
|
|
$snippetSet = $this->getSnippetSetId(); |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
if ($snippetSet === null) { |
|
83
|
|
|
throw new \InvalidArgumentException(sprintf('Snippet set with isoCode %s cannot be found.', $isoCode)); |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
return $snippetSet; |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
private function getSnippetSetId(?string $isoCode = 'en-GB'): string|null |
|
90
|
|
|
{ |
|
91
|
|
|
$isoCode = $isoCode ?: 'en-GB'; |
|
92
|
|
|
$isoCode = str_replace('_', '-', $isoCode); |
|
93
|
|
|
$criteria = (new Criteria()) |
|
94
|
|
|
->setLimit(1) |
|
95
|
|
|
->addFilter(new EqualsFilter('iso', $isoCode)); |
|
96
|
|
|
|
|
97
|
|
|
return $this->snippetSetRepository->searchIds($criteria, Context::createDefaultContext())->firstId(); |
|
98
|
|
|
} |
|
99
|
|
|
} |
|
100
|
|
|
|