diff --git a/Adapter/TaxonCategoryAdapter.php b/Adapter/TaxonCategoryAdapter.php index 6aab188..ec10fc0 100644 --- a/Adapter/TaxonCategoryAdapter.php +++ b/Adapter/TaxonCategoryAdapter.php @@ -13,6 +13,7 @@ namespace Sulu\Bundle\SyliusConsumerBundle\Adapter; +use Doctrine\ORM\EntityManagerInterface; use Sulu\Bundle\CategoryBundle\Entity\CategoryInterface; use Sulu\Bundle\CategoryBundle\Entity\CategoryRepositoryInterface; use Sulu\Bundle\CategoryBundle\Entity\CategoryTranslationInterface; @@ -38,19 +39,30 @@ class TaxonCategoryAdapter implements TaxonAdapterInterface */ private $categoryTranslationRepository; + /** + * @var EntityManagerInterface + */ + private $entityManager; + public function __construct( TaxonCategoryBridgeRepositoryInterface $taxonCategoryBridgeRepository, CategoryRepositoryInterface $categoryRepository, - CategoryTranslationRepositoryInterface $categoryTranslationRepository + CategoryTranslationRepositoryInterface $categoryTranslationRepository, + EntityManagerInterface $entityManager ) { $this->taxonCategoryBridgeRepository = $taxonCategoryBridgeRepository; $this->categoryRepository = $categoryRepository; $this->categoryTranslationRepository = $categoryTranslationRepository; + $this->entityManager = $entityManager; } public function synchronize(TaxonPayload $payload): void { $this->handlePayload($payload); + + // Needed to use categories in other adapters + // (e.g. category pages with a smart-content filtered by the sylius category) + $this->entityManager->flush(); } private function handlePayload(TaxonPayload $payload, ?CategoryInterface $parent = null): void diff --git a/Payload/ProductPayload.php b/Payload/ProductPayload.php index acef621..98de92c 100644 --- a/Payload/ProductPayload.php +++ b/Payload/ProductPayload.php @@ -44,9 +44,9 @@ public function isEnabled(): bool return $this->payload->getBoolValue('enabled'); } - public function getMainTaxonId(): int + public function getMainTaxonId(): ?int { - return $this->payload->getIntValue('mainTaxonId'); + return $this->payload->getNullableIntValue('mainTaxonId'); } /** diff --git a/Resources/config/taxon_category_adapter.xml b/Resources/config/taxon_category_adapter.xml index dfdc81e..fbd44b6 100644 --- a/Resources/config/taxon_category_adapter.xml +++ b/Resources/config/taxon_category_adapter.xml @@ -9,6 +9,7 @@ + diff --git a/Tests/Application/config/config.yml b/Tests/Application/config/config.yml index bbdb349..dd256d3 100644 --- a/Tests/Application/config/config.yml +++ b/Tests/Application/config/config.yml @@ -2,14 +2,6 @@ doctrine: dbal: url: '%env(resolve:DATABASE_URL)%' - orm: - mappings: - gedmo_tree: - type: xml - prefix: Gedmo\Tree\Entity - dir: "%kernel.project_dir%/../../vendor/gedmo/doctrine-extensions/lib/Gedmo/Tree/Entity" - alias: GedmoTree - is_bundle: false framework: router: diff --git a/Tests/Functional/Adapter/TaxonCategoryAdapterTest.php b/Tests/Functional/Adapter/TaxonCategoryAdapterTest.php index f19e088..aecc166 100644 --- a/Tests/Functional/Adapter/TaxonCategoryAdapterTest.php +++ b/Tests/Functional/Adapter/TaxonCategoryAdapterTest.php @@ -38,7 +38,9 @@ public function testSynchronize(): void $taxonPayload = new TaxonPayload(1, MockSyliusData::TAXON); $adapter->synchronize($taxonPayload); - $this->getEntityManager()->flush(); + + // Adapter flushed the entity-manager - by clearing it we can check if that works correctly + $this->getEntityManager()->clear(); $bridge1 = $this->getEntityManager()->find(TaxonCategoryBridge::class, 1); $bridge2 = $this->getEntityManager()->find(TaxonCategoryBridge::class, 2);