-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Get default localized catalog #ESPP-218
- Loading branch information
Showing
24 changed files
with
506 additions
and
206 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace DoctrineMigrations; | ||
|
||
use Doctrine\DBAL\Schema\Schema; | ||
use Doctrine\Migrations\AbstractMigration; | ||
|
||
/** | ||
* Auto-generated Migration: Please modify to your needs! | ||
*/ | ||
final class Version20220408122945 extends AbstractMigration | ||
{ | ||
public function getDescription(): string | ||
{ | ||
return ''; | ||
} | ||
|
||
public function up(Schema $schema): void | ||
{ | ||
// this up() migration is auto-generated, please modify it to your needs | ||
$this->addSql('ALTER TABLE localized_catalog ADD is_default BOOLEAN DEFAULT \'false\' NOT NULL'); | ||
} | ||
|
||
public function down(Schema $schema): void | ||
{ | ||
// this down() migration is auto-generated, please modify it to your needs | ||
$this->addSql('ALTER TABLE localized_catalog DROP is_default'); | ||
} | ||
} |
68 changes: 68 additions & 0 deletions
68
api/src/Elasticsuite/Standard/src/Catalog/DataPersister/LocalizedCatalogDataPersister.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
<?php | ||
/** | ||
* DISCLAIMER | ||
* | ||
* Do not edit or add to this file if you wish to upgrade Smile ElasticSuite to newer | ||
* versions in the future. | ||
* | ||
* @package Elasticsuite | ||
* @author ElasticSuite Team <elasticsuite@smile.fr> | ||
* @copyright 2022 Smile | ||
* @license Licensed to Smile-SA. All rights reserved. No warranty, explicit or implicit, provided. | ||
* Unauthorized copying of this file, via any medium, is strictly prohibited. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Elasticsuite\Catalog\DataPersister; | ||
|
||
use ApiPlatform\Core\DataPersister\DataPersisterInterface; | ||
use Doctrine\ORM\EntityManagerInterface; | ||
use Elasticsuite\Catalog\Model\LocalizedCatalog; | ||
use Elasticsuite\Catalog\Repository\LocalizedCatalogRepository; | ||
|
||
class LocalizedCatalogDataPersister implements DataPersisterInterface | ||
{ | ||
public function __construct( | ||
private EntityManagerInterface $entityManager, | ||
private LocalizedCatalogRepository $localizedCatalogRepository | ||
) { | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
public function supports($data): bool | ||
{ | ||
return $data instanceof LocalizedCatalog; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
* | ||
* @param LocalizedCatalog $data | ||
* | ||
* @return LocalizedCatalog | ||
*/ | ||
public function persist($data) | ||
{ | ||
if ($data->isDefault()) { | ||
$this->localizedCatalogRepository->unsetDefaultLocalizedCatalog(); | ||
} | ||
$this->entityManager->persist($data); | ||
$this->entityManager->flush(); | ||
|
||
return $data; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
* | ||
* @param LocalizedCatalog $data | ||
*/ | ||
public function remove($data) | ||
{ | ||
$this->entityManager->remove($data); | ||
$this->entityManager->flush(); | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
api/src/Elasticsuite/Standard/src/Catalog/Exception/NoCatalogException.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
/** | ||
* DISCLAIMER | ||
* | ||
* Do not edit or add to this file if you wish to upgrade Smile ElasticSuite to newer | ||
* versions in the future. | ||
* | ||
* @package Elasticsuite | ||
* @author ElasticSuite Team <elasticsuite@smile.fr> | ||
* @copyright 2022 Smile | ||
* @license Licensed to Smile-SA. All rights reserved. No warranty, explicit or implicit, provided. | ||
* Unauthorized copying of this file, via any medium, is strictly prohibited. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Elasticsuite\Catalog\Exception; | ||
|
||
use ApiPlatform\Core\Exception\ExceptionInterface; | ||
|
||
class NoCatalogException extends \LogicException implements ExceptionInterface | ||
{ | ||
public function __construct( | ||
string $message = 'No localized catalog found', | ||
int $code = 0, | ||
?\Throwable $previous = null | ||
) { | ||
parent::__construct($message, $code, $previous); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
api/src/Elasticsuite/Standard/src/Catalog/Resources/config/test/services.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
services: | ||
Elasticsuite\Catalog\Service\DefaultCatalogProviderTest: | ||
alias: Elasticsuite\Catalog\Service\DefaultCatalogProvider | ||
public: true |
42 changes: 42 additions & 0 deletions
42
api/src/Elasticsuite/Standard/src/Catalog/Service/DefaultCatalogProvider.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<?php | ||
/** | ||
* DISCLAIMER | ||
* | ||
* Do not edit or add to this file if you wish to upgrade Smile ElasticSuite to newer | ||
* versions in the future. | ||
* | ||
* @package Elasticsuite | ||
* @author ElasticSuite Team <elasticsuite@smile.fr> | ||
* @copyright 2022 Smile | ||
* @license Licensed to Smile-SA. All rights reserved. No warranty, explicit or implicit, provided. | ||
* Unauthorized copying of this file, via any medium, is strictly prohibited. | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Elasticsuite\Catalog\Service; | ||
|
||
use Elasticsuite\Catalog\Exception\NoCatalogException; | ||
use Elasticsuite\Catalog\Model\LocalizedCatalog; | ||
use Elasticsuite\Catalog\Repository\LocalizedCatalogRepository; | ||
|
||
class DefaultCatalogProvider | ||
{ | ||
/** | ||
* @param LocalizedCatalogRepository $localizedCatalogRepository | ||
*/ | ||
public function __construct( | ||
private LocalizedCatalogRepository $localizedCatalogRepository | ||
) { | ||
} | ||
|
||
public function getDefaultLocalizedCatalog(): LocalizedCatalog | ||
{ | ||
$catalog = $this->localizedCatalogRepository->findOneBy([], ['isDefault' => 'DESC', 'id' => 'ASC']); | ||
if (null === $catalog) { | ||
throw new NoCatalogException(); | ||
} | ||
|
||
return $catalog; | ||
} | ||
} |
Oops, something went wrong.