Skip to content

Commit

Permalink
StoreDataFixture now creates stores on second domain only if second d…
Browse files Browse the repository at this point in the history
…omain exists
  • Loading branch information
TomasLudvik committed Oct 16, 2023
1 parent f42fa34 commit be9e06a
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions app/src/DataFixtures/Demo/StoreDataFixture.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use Doctrine\Persistence\ObjectManager;
use Shopsys\FrameworkBundle\Component\DataFixture\AbstractReferenceFixture;
use Shopsys\FrameworkBundle\Component\Domain\Domain;
use Shopsys\FrameworkBundle\Component\Domain\Exception\InvalidDomainIdException;
use Shopsys\FrameworkBundle\Component\FileUpload\ImageUploadDataFactory;
use Shopsys\FrameworkBundle\Component\Translation\Translator;

Expand Down Expand Up @@ -86,9 +87,15 @@ public function load(ObjectManager $manager)
private function getDemoData(): array
{
$firstDomainConfig = $this->domain->getDomainConfigById(Domain::FIRST_DOMAIN_ID);
$secondDomainConfig = $this->domain->getDomainConfigById(Domain::SECOND_DOMAIN_ID);

return [
try {
$secondDomainConfig = $this->domain->getDomainConfigById(Domain::SECOND_DOMAIN_ID);
$isSecondDomainAvailable = true;
} catch (InvalidDomainIdException) {
$isSecondDomainAvailable = false;
}

$stores = [
[
self::ATTR_NAME => 'Ostrava',
self::ATTR_IS_DEFAULT => true,
Expand Down Expand Up @@ -121,7 +128,11 @@ private function getDemoData(): array
self::ATTR_LOCATION_LATITUDE => '50.0346875',
self::ATTR_LOCATION_LONGITUDE => '15.7707169',
self::ATTR_IMAGE => $this->imageUploadDataFactory->create(),
], [
],
];

if ($isSecondDomainAvailable) {
$stores[] = [
self::ATTR_NAME => 'Žilina',
self::ATTR_IS_DEFAULT => false,
self::ATTR_IS_ENABLED_BY_DOMAIN => self::ENABLED_SECOND_DOMAIN,
Expand All @@ -137,8 +148,10 @@ private function getDemoData(): array
self::ATTR_LOCATION_LATITUDE => '49.2030444',
self::ATTR_LOCATION_LONGITUDE => '18.7499042',
self::ATTR_IMAGE => $this->imageUploadDataFactory->create(),
],
];
];
}

return $stores;
}

/**
Expand Down

0 comments on commit be9e06a

Please sign in to comment.