Skip to content

Commit d292ac3

Browse files
Merge pull request #2948 from coreshop/upmerge/4.1_5.0
[UPMERGE] 4.1 -> 5.0
2 parents 4d1203b + 4d48e3e commit d292ac3

File tree

12 files changed

+380
-36
lines changed

12 files changed

+380
-36
lines changed

.github/workflows/cla-check.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,6 @@ jobs:
2525
path-to-signatures: 'signatures/version1/cla.json'
2626
path-to-document: 'https://github.com/coreshop/coreshop/blob/4.0/CLA.md'
2727
branch: "main"
28-
allowlist: user1,bot*
28+
allowlist: user1,bot*,Copilot
2929
remote-organization-name: "coreshop"
3030
remote-repository-name: "cla"

CHANGELOG-4.1.x.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
## 4.1.9
2+
* Fix Injection in CustomerTransformerController by @dpfaffenbauer in https://github.com/coreshop/CoreShop/pull/2945
3+
14
## 4.1.8
25
* [Messenger] dispatch `FailedMessageDetailsEvent` to allow customization of failed message details generation by @jdreesen in https://github.com/coreshop/CoreShop/pull/2911
36
* [Messenger] wrap failed message details info modal data in `<pre>` tags by @jdreesen in https://github.com/coreshop/CoreShop/pull/2910

docs/03_Bundles/Menu_Bundle.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,14 +75,14 @@ public function registerBundlesToCollection(BundleCollection $collection)
7575

7676
```javascript
7777
new coreshop.menu.coreshop.my_menu();
78-
79-
pimcore.eventDispatcher.registerTarget('coreshopMenuOpen', new (Class.create({
80-
coreshopMenuOpen: function(type, item) {
78+
79+
document.addEventListener(coreshop.events.menu.open, (e) => {
80+
var item = e.detail.item;
81+
8182
if (item.id === 'my-menu-item') {
8283
alert('My Menu Item has been clicked');
8384
}
84-
}
85-
85+
});
8686
```
8787

8888

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# Setup States Command
2+
3+
CoreShop provides a CLI command to create states/regions for countries after the initial installation.
4+
5+
By default, CoreShop only creates states for Austria (AT) during installation. Use this command to add states for additional countries.
6+
7+
## Usage
8+
9+
```bash
10+
# Setup states for a single country
11+
php bin/console coreshop:setup:states DE
12+
13+
# Setup states for multiple countries
14+
php bin/console coreshop:setup:states DE,US,FR
15+
16+
# Setup states and activate the country if not already active
17+
php bin/console coreshop:setup:states DE --activate-country
18+
19+
# Verbose output to see individual states being created
20+
php bin/console coreshop:setup:states DE -v
21+
```
22+
23+
## Arguments
24+
25+
| Argument | Description |
26+
|----------|-------------|
27+
| countries | Comma-separated list of country ISO codes (e.g., DE,US,FR) |
28+
29+
## Options
30+
31+
| Option | Description |
32+
|--------|-------------|
33+
| --activate-country | Also activate the country if not already active |
34+
35+
## Prerequisites
36+
37+
Before running this command, ensure that:
38+
39+
1. CoreShop is installed (`coreshop:install` has been run)
40+
2. The country fixtures have been loaded (countries exist in the database)
41+
42+
## How It Works
43+
44+
The command:
45+
46+
1. Looks up each specified country in the database by ISO code
47+
2. Loads the country's divisions (states/regions) from the Rinvex country data library
48+
3. Creates states for each division that doesn't already exist
49+
4. Optionally activates the country if `--activate-country` is specified
50+
51+
## Example Output
52+
53+
```
54+
CoreShop States Setup
55+
=====================
56+
57+
Setting up states for countries: DE
58+
59+
Processing country: DE
60+
-----------------------
61+
62+
[OK] Countries processed: 1
63+
States created: 16
64+
States skipped (already exist): 0
65+
Countries activated: 0
66+
```
Lines changed: 182 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,182 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/*
6+
* CoreShop
7+
*
8+
* This source file is available under two different licenses:
9+
* - GNU General Public License version 3 (GPLv3)
10+
* - CoreShop Commercial License (CCL)
11+
* Full copyright and license information is available in
12+
* LICENSE.md which is distributed with this source code.
13+
*
14+
* @copyright Copyright (c) CoreShop GmbH (https://www.coreshop.com)
15+
* @license https://www.coreshop.com/license GPLv3 and CCL
16+
*
17+
*/
18+
19+
namespace CoreShop\Bundle\CoreBundle\Command;
20+
21+
use CoreShop\Component\Address\Model\StateInterface;
22+
use CoreShop\Component\Address\Repository\CountryRepositoryInterface;
23+
use CoreShop\Component\Resource\Factory\FactoryInterface;
24+
use CoreShop\Component\Resource\Repository\RepositoryInterface;
25+
use Doctrine\ORM\EntityManagerInterface;
26+
use Pimcore\Tool;
27+
use Rinvex\Country\CountryLoader;
28+
use Symfony\Component\Console\Command\Command;
29+
use Symfony\Component\Console\Input\InputArgument;
30+
use Symfony\Component\Console\Input\InputInterface;
31+
use Symfony\Component\Console\Input\InputOption;
32+
use Symfony\Component\Console\Output\OutputInterface;
33+
use Symfony\Component\Console\Style\SymfonyStyle;
34+
35+
final class SetupStatesCommand extends Command
36+
{
37+
public function __construct(
38+
private CountryRepositoryInterface $countryRepository,
39+
private RepositoryInterface $stateRepository,
40+
private FactoryInterface $stateFactory,
41+
private EntityManagerInterface $entityManager,
42+
) {
43+
parent::__construct();
44+
}
45+
46+
protected function configure(): void
47+
{
48+
$this
49+
->setName('coreshop:setup:states')
50+
->setDescription('Create states/regions for specified countries.')
51+
->addArgument(
52+
'countries',
53+
InputArgument::REQUIRED,
54+
'Comma-separated list of country ISO codes (e.g., DE,US,FR)',
55+
)
56+
->addOption(
57+
'activate-country',
58+
null,
59+
InputOption::VALUE_NONE,
60+
'Also activate the country if not already active',
61+
)
62+
->setHelp(
63+
<<<EOT
64+
The <info>%command.name%</info> command creates states/regions for specified countries.
65+
66+
Examples:
67+
<info>php bin/console %command.name% DE</info>
68+
<info>php bin/console %command.name% DE,US,FR</info>
69+
<info>php bin/console %command.name% DE --activate-country</info>
70+
EOT
71+
)
72+
;
73+
}
74+
75+
protected function execute(InputInterface $input, OutputInterface $output): int
76+
{
77+
$io = new SymfonyStyle($input, $output);
78+
79+
$countriesArg = $input->getArgument('countries');
80+
$activateCountry = $input->getOption('activate-country');
81+
$countryCodes = array_map('strtoupper', array_map('trim', explode(',', $countriesArg)));
82+
83+
$languages = Tool::getValidLanguages();
84+
85+
$io->title('CoreShop States Setup');
86+
$io->writeln(sprintf('Setting up states for countries: <info>%s</info>', implode(', ', $countryCodes)));
87+
88+
$createdStates = 0;
89+
$skippedStates = 0;
90+
$countriesProcessed = 0;
91+
$activatedCountries = 0;
92+
93+
foreach ($countryCodes as $countryCode) {
94+
$io->section(sprintf('Processing country: %s', $countryCode));
95+
96+
// Check if country exists in database
97+
$country = $this->countryRepository->findByCode($countryCode);
98+
if ($country === null) {
99+
$io->warning(sprintf('Country with code "%s" not found in database. Run fixtures first or install CoreShop.', $countryCode));
100+
101+
continue;
102+
}
103+
104+
// Load country data from Rinvex
105+
try {
106+
$rinvexCountry = CountryLoader::country($countryCode);
107+
} catch (\Exception $e) {
108+
$io->warning(sprintf('Country data not found for code "%s" in Rinvex data: %s', $countryCode, $e->getMessage()));
109+
110+
continue;
111+
}
112+
113+
// Activate country if requested
114+
if ($activateCountry && !$country->getActive()) {
115+
$country->setActive(true);
116+
$this->entityManager->persist($country);
117+
$activatedCountries++;
118+
$io->writeln(sprintf(' <comment>Activated country: %s</comment>', $countryCode));
119+
}
120+
121+
// Get divisions (states/regions)
122+
$divisions = $rinvexCountry->getDivisions();
123+
124+
if (!is_array($divisions) || empty($divisions)) {
125+
$io->writeln(sprintf(' <comment>No divisions/states found for %s</comment>', $countryCode));
126+
$countriesProcessed++;
127+
128+
continue;
129+
}
130+
131+
foreach ($divisions as $isoCode => $division) {
132+
if (!$division['name']) {
133+
continue;
134+
}
135+
136+
// Check if state already exists
137+
$existingState = $this->stateRepository->findOneBy([
138+
'isoCode' => $isoCode,
139+
'country' => $country,
140+
]);
141+
142+
if ($existingState !== null) {
143+
$skippedStates++;
144+
$io->writeln(sprintf(' <comment>Skipping existing state: %s (%s)</comment>', $division['name'], $isoCode), OutputInterface::VERBOSITY_VERBOSE);
145+
146+
continue;
147+
}
148+
149+
/**
150+
* @var StateInterface $state
151+
*/
152+
$state = $this->stateFactory->createNew();
153+
154+
foreach ($languages as $lang) {
155+
$state->setName($division['name'], $lang);
156+
}
157+
158+
$state->setIsoCode($isoCode);
159+
$state->setCountry($country);
160+
$state->setActive(true);
161+
162+
$this->entityManager->persist($state);
163+
$createdStates++;
164+
165+
$io->writeln(sprintf(' <info>Created state: %s (%s)</info>', $division['name'], $isoCode), OutputInterface::VERBOSITY_VERBOSE);
166+
}
167+
168+
$countriesProcessed++;
169+
}
170+
171+
$this->entityManager->flush();
172+
173+
$io->success([
174+
sprintf('Countries processed: %d', $countriesProcessed),
175+
sprintf('States created: %d', $createdStates),
176+
sprintf('States skipped (already exist): %d', $skippedStates),
177+
sprintf('Countries activated: %d', $activatedCountries),
178+
]);
179+
180+
return Command::SUCCESS;
181+
}
182+
}

src/CoreShop/Bundle/CoreBundle/Resources/config/services/commands.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,12 @@ services:
5050
tags:
5151
- { name: console.command, command: coreshop:migration:generate }
5252

53+
CoreShop\Bundle\CoreBundle\Command\SetupStatesCommand:
54+
arguments:
55+
- '@coreshop.repository.country'
56+
- '@coreshop.repository.state'
57+
- '@coreshop.factory.state'
58+
- '@doctrine.orm.entity_manager'
59+
tags:
60+
- { name: console.command, command: coreshop:setup:states }
61+

0 commit comments

Comments
 (0)