From 8deae776b1037d07635424513e470dbb4bafaec7 Mon Sep 17 00:00:00 2001 From: tamvt Date: Mon, 12 Jan 2026 17:35:13 +0700 Subject: [PATCH 1/2] feat: Compatible with migration assistant --- .../Provider/Data/ProductProvider.php | 39 +++- src/DependencyInjection/dataProvider.xml | 1 + src/DependencyInjection/shopware6.xml | 1 + .../Shopware6/Converter/ProductConverter.php | 55 ++++++ .../Converter/ProductConverterTest.php | 5 +- .../Converter/ProductConverterUnitTest.php | 177 ++++++++++++++++++ 6 files changed, 276 insertions(+), 2 deletions(-) create mode 100644 tests/Profile/Shopware6/Converter/ProductConverterUnitTest.php diff --git a/src/DataProvider/Provider/Data/ProductProvider.php b/src/DataProvider/Provider/Data/ProductProvider.php index 15f279c38..b775cca93 100644 --- a/src/DataProvider/Provider/Data/ProductProvider.php +++ b/src/DataProvider/Provider/Data/ProductProvider.php @@ -7,10 +7,13 @@ namespace SwagMigrationAssistant\DataProvider\Provider\Data; +use Doctrine\DBAL\Connection; use Shopware\Core\Content\Product\ProductCollection; use Shopware\Core\Framework\Context; use Shopware\Core\Framework\DataAbstractionLayer\EntityRepository; use Shopware\Core\Framework\DataAbstractionLayer\Search\Criteria; +use Shopware\Core\Framework\DataAbstractionLayer\Search\Filter\EqualsFilter; +use Shopware\Core\Framework\DataAbstractionLayer\Search\Filter\NotFilter; use Shopware\Core\Framework\DataAbstractionLayer\Search\Sorting\FieldSorting; use Shopware\Core\Framework\Log\Package; use SwagMigrationAssistant\Migration\DataSelection\DefaultEntities; @@ -20,12 +23,17 @@ #[Package('fundamentals@after-sales')] class ProductProvider extends AbstractProvider { + private const BUNDLE_PRODUCT_TYPE = 'grouped_bundle'; + + private ?bool $hasTypeColumn = null; + /** * @param EntityRepository $productRepo */ public function __construct( private readonly EntityRepository $productRepo, private readonly RouterInterface $router, + private readonly Connection $connection, ) { } @@ -55,6 +63,7 @@ public function getProvidedData(int $limit, int $offset, Context $context): arra new FieldSorting('parentId'), // get 'NULL' parentIds first new FieldSorting('id') ); + $this->addBundleExclusionFilter($criteria); $result = $this->productRepo->search($criteria, $context); $cleanResult = $this->cleanupSearchResult($result, [ @@ -113,6 +122,34 @@ public function getProvidedData(int $limit, int $offset, Context $context): arra public function getProvidedTotal(Context $context): int { - return $this->readTotalFromRepo($this->productRepo, $context); + $criteria = new Criteria(); + $this->addBundleExclusionFilter($criteria); + + return $this->readTotalFromRepo($this->productRepo, $context, $criteria); + } + + private function addBundleExclusionFilter(Criteria $criteria): void + { + if (!$this->hasTypeColumn()) { + return; + } + + $criteria->addFilter( + new NotFilter(NotFilter::CONNECTION_AND, [ + new EqualsFilter('type', self::BUNDLE_PRODUCT_TYPE), + ]) + ); + } + + private function hasTypeColumn(): bool + { + if ($this->hasTypeColumn !== null) { + return $this->hasTypeColumn; + } + + $columns = $this->connection->createSchemaManager()->listTableColumns('product'); + $this->hasTypeColumn = isset($columns['type']); + + return $this->hasTypeColumn; } } diff --git a/src/DependencyInjection/dataProvider.xml b/src/DependencyInjection/dataProvider.xml index 664bee350..82e830529 100644 --- a/src/DependencyInjection/dataProvider.xml +++ b/src/DependencyInjection/dataProvider.xml @@ -71,6 +71,7 @@ + diff --git a/src/DependencyInjection/shopware6.xml b/src/DependencyInjection/shopware6.xml index a5f3e65ba..79c2781ab 100644 --- a/src/DependencyInjection/shopware6.xml +++ b/src/DependencyInjection/shopware6.xml @@ -115,6 +115,7 @@ + diff --git a/src/Profile/Shopware6/Converter/ProductConverter.php b/src/Profile/Shopware6/Converter/ProductConverter.php index 60494ae22..58c01b895 100644 --- a/src/Profile/Shopware6/Converter/ProductConverter.php +++ b/src/Profile/Shopware6/Converter/ProductConverter.php @@ -7,10 +7,16 @@ namespace SwagMigrationAssistant\Profile\Shopware6\Converter; +use Doctrine\DBAL\Connection; +use Shopware\Core\Content\Product\ProductDefinition; +use Shopware\Core\Content\Product\State; use Shopware\Core\Defaults; use Shopware\Core\Framework\Log\Package; use SwagMigrationAssistant\Migration\Converter\ConvertStruct; use SwagMigrationAssistant\Migration\DataSelection\DefaultEntities; +use SwagMigrationAssistant\Migration\Logging\LoggingServiceInterface; +use SwagMigrationAssistant\Migration\Mapping\MappingServiceInterface; +use SwagMigrationAssistant\Migration\Media\MediaFileServiceInterface; use SwagMigrationAssistant\Migration\MigrationContextInterface; use SwagMigrationAssistant\Profile\Shopware6\DataSelection\DataSet\ProductDataSet; use SwagMigrationAssistant\Profile\Shopware6\Shopware6MajorProfile; @@ -20,6 +26,17 @@ class ProductConverter extends ShopwareMediaConverter { private ?string $sourceDefaultCurrencyUuid; + private ?bool $hasTypeColumn = null; + + public function __construct( + MappingServiceInterface $mappingService, + LoggingServiceInterface $loggingService, + MediaFileServiceInterface $mediaFileService, + private readonly Connection $connection, + ) { + parent::__construct($mappingService, $loggingService, $mediaFileService); + } + public function supports(MigrationContextInterface $migrationContext): bool { return $migrationContext->getProfile()->getName() === Shopware6MajorProfile::PROFILE_NAME @@ -205,6 +222,8 @@ protected function convertData(array $data): ConvertStruct ); } + $this->convertStatesToType($converted); + return new ConvertStruct($converted, null, $this->mainMapping['id'] ?? null); } @@ -235,4 +254,40 @@ private function checkDefaultCurrency(array &$source, string $key): void $source[$key][] = $defaultPrice; } } + + /** + * @param array $converted + */ + private function convertStatesToType(array &$converted): void + { + if (!$this->hasTypeColumn()) { + return; + } + + if (isset($converted['type'])) { + return; + } + + if (isset($converted['states']) && \is_array($converted['states'])) { + $converted['type'] = \in_array(State::IS_DOWNLOAD, $converted['states'], true) + ? ProductDefinition::TYPE_DIGITAL + : ProductDefinition::TYPE_PHYSICAL; + + return; + } + + $converted['type'] = ProductDefinition::TYPE_PHYSICAL; + } + + private function hasTypeColumn(): bool + { + if ($this->hasTypeColumn !== null) { + return $this->hasTypeColumn; + } + + $columns = $this->connection->createSchemaManager()->listTableColumns('product'); + $this->hasTypeColumn = isset($columns['type']); + + return $this->hasTypeColumn; + } } diff --git a/tests/Profile/Shopware6/Converter/ProductConverterTest.php b/tests/Profile/Shopware6/Converter/ProductConverterTest.php index 7b1d41b91..8cae06417 100644 --- a/tests/Profile/Shopware6/Converter/ProductConverterTest.php +++ b/tests/Profile/Shopware6/Converter/ProductConverterTest.php @@ -7,6 +7,7 @@ namespace SwagMigrationAssistant\Test\Profile\Shopware6\Converter; +use Doctrine\DBAL\Connection; use Shopware\Core\Framework\Log\Package; use SwagMigrationAssistant\Migration\Converter\ConverterInterface; use SwagMigrationAssistant\Migration\DataSelection\DataSet\DataSet; @@ -25,7 +26,9 @@ protected function createConverter( MediaFileServiceInterface $mediaFileService, ?array $mappingArray = [], ): ConverterInterface { - return new ProductConverter($mappingService, $loggingService, $mediaFileService); + $connection = static::getContainer()->get(Connection::class); + + return new ProductConverter($mappingService, $loggingService, $mediaFileService, $connection); } protected function createDataSet(): DataSet diff --git a/tests/Profile/Shopware6/Converter/ProductConverterUnitTest.php b/tests/Profile/Shopware6/Converter/ProductConverterUnitTest.php new file mode 100644 index 000000000..bad940c44 --- /dev/null +++ b/tests/Profile/Shopware6/Converter/ProductConverterUnitTest.php @@ -0,0 +1,177 @@ + + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace SwagMigrationAssistant\Test\Profile\Shopware6\Converter; + +use Doctrine\DBAL\Connection; +use Doctrine\DBAL\Schema\AbstractSchemaManager; +use Doctrine\DBAL\Schema\Column; +use Doctrine\DBAL\Types\StringType; +use PHPUnit\Framework\TestCase; +use Shopware\Core\Content\Product\ProductDefinition; +use Shopware\Core\Framework\Context; +use Shopware\Core\Framework\Log\Package; +use Shopware\Core\Framework\Uuid\Uuid; +use SwagMigrationAssistant\Migration\Connection\SwagMigrationConnectionEntity; +use SwagMigrationAssistant\Migration\MigrationContext; +use SwagMigrationAssistant\Profile\Shopware6\Converter\ProductConverter; +use SwagMigrationAssistant\Profile\Shopware6\DataSelection\DataSet\ProductDataSet; +use SwagMigrationAssistant\Profile\Shopware6\Shopware6MajorProfile; +use SwagMigrationAssistant\Test\Mock\Migration\Logging\DummyLoggingService; +use SwagMigrationAssistant\Test\Mock\Migration\Mapping\Dummy6MappingService; +use SwagMigrationAssistant\Test\Mock\Migration\Media\DummyMediaFileService; + +#[Package('fundamentals@after-sales')] +class ProductConverterUnitTest extends TestCase +{ + public function testConvertStatesToTypeWithDownloadState(): void + { + $converter = $this->createConverterWithTypeColumn(true); + $context = Context::createDefaultContext(); + $migrationContext = $this->createMigrationContext(); + + $input = [ + 'id' => Uuid::randomHex(), + 'productNumber' => 'TEST-001', + 'stock' => 10, + 'states' => ['is-download'], + 'name' => 'Digital Product', + ]; + + $result = $converter->convert($input, $context, $migrationContext); + $converted = $result->getConverted(); + + static::assertNotNull($converted); + static::assertArrayHasKey('type', $converted); + static::assertSame(ProductDefinition::TYPE_DIGITAL, $converted['type']); + } + + public function testConvertStatesToTypeWithPhysicalState(): void + { + $converter = $this->createConverterWithTypeColumn(true); + $context = Context::createDefaultContext(); + $migrationContext = $this->createMigrationContext(); + + $input = [ + 'id' => Uuid::randomHex(), + 'productNumber' => 'TEST-002', + 'stock' => 10, + 'states' => ['is-physical'], + 'name' => 'Physical Product', + ]; + + $result = $converter->convert($input, $context, $migrationContext); + $converted = $result->getConverted(); + + static::assertNotNull($converted); + static::assertArrayHasKey('type', $converted); + static::assertSame(ProductDefinition::TYPE_PHYSICAL, $converted['type']); + } + + public function testConvertPreservesExistingType(): void + { + $converter = $this->createConverterWithTypeColumn(true); + $context = Context::createDefaultContext(); + $migrationContext = $this->createMigrationContext(); + + $input = [ + 'id' => Uuid::randomHex(), + 'productNumber' => 'TEST-003', + 'stock' => 10, + 'type' => 'digital', + 'name' => 'Product With Type', + ]; + + $result = $converter->convert($input, $context, $migrationContext); + $converted = $result->getConverted(); + + static::assertNotNull($converted); + static::assertArrayHasKey('type', $converted); + static::assertSame('digital', $converted['type']); + } + + public function testConvertDefaultsToPhysicalType(): void + { + $converter = $this->createConverterWithTypeColumn(true); + $context = Context::createDefaultContext(); + $migrationContext = $this->createMigrationContext(); + + $input = [ + 'id' => Uuid::randomHex(), + 'productNumber' => 'TEST-004', + 'stock' => 10, + 'name' => 'Product Without Type Or States', + ]; + + $result = $converter->convert($input, $context, $migrationContext); + $converted = $result->getConverted(); + + static::assertNotNull($converted); + static::assertArrayHasKey('type', $converted); + static::assertSame(ProductDefinition::TYPE_PHYSICAL, $converted['type']); + } + + public function testConvertDoesNotSetTypeWhenColumnDoesNotExist(): void + { + $converter = $this->createConverterWithTypeColumn(false); + $context = Context::createDefaultContext(); + $migrationContext = $this->createMigrationContext(); + + $input = [ + 'id' => Uuid::randomHex(), + 'productNumber' => 'TEST-005', + 'stock' => 10, + 'states' => ['is-download'], + 'name' => 'Product On Old Database', + ]; + + $result = $converter->convert($input, $context, $migrationContext); + $converted = $result->getConverted(); + + static::assertNotNull($converted); + static::assertArrayNotHasKey('type', $converted); + } + + private function createConverterWithTypeColumn(bool $hasTypeColumn): ProductConverter + { + $schemaManager = $this->createMock(AbstractSchemaManager::class); + + if ($hasTypeColumn) { + $schemaManager->method('listTableColumns')->willReturn([ + 'type' => new Column('type', new StringType()), + ]); + } else { + $schemaManager->method('listTableColumns')->willReturn([]); + } + + $connection = $this->createMock(Connection::class); + $connection->method('createSchemaManager')->willReturn($schemaManager); + + return new ProductConverter( + new Dummy6MappingService(), + new DummyLoggingService(), + new DummyMediaFileService(), + $connection + ); + } + + private function createMigrationContext(): MigrationContext + { + $connection = new SwagMigrationConnectionEntity(); + $connection->setId(Uuid::randomHex()); + $connection->setProfileName(Shopware6MajorProfile::PROFILE_NAME); + + return new MigrationContext( + new Shopware6MajorProfile('6.5'), + $connection, + Uuid::randomHex(), + new ProductDataSet(), + 0, + 250 + ); + } +} From 0d4d57bfb9d5f09c84ea3cf45e348fd2c7940cfe Mon Sep 17 00:00:00 2001 From: tamvt Date: Tue, 13 Jan 2026 10:35:11 +0700 Subject: [PATCH 2/2] fix: Fix tests --- .../Provider/Data/ProductProvider.php | 13 +- src/DependencyInjection/dataProvider.xml | 1 - src/DependencyInjection/shopware6.xml | 1 - .../Shopware6/Converter/ProductConverter.php | 34 +--- .../Converter/ProductConverterTest.php | 5 +- .../Converter/ProductConverterUnitTest.php | 177 ------------------ .../Product/01-HappyCaseContainer/output.php | 1 + .../Product/02-HappyCaseVariant/output.php | 1 + .../03-MissingManufacturerMapping/output.php | 1 + .../04-StripUnmigrateableData/output.php | 1 + .../Product/05-AdvancedPrices/output.php | 1 + .../Product/06-DeliveryTimes/output.php | 1 + .../Shopware6/Product/07-Media/output.php | 1 + .../output.php | 1 + .../output.php | 1 + 15 files changed, 12 insertions(+), 228 deletions(-) delete mode 100644 tests/Profile/Shopware6/Converter/ProductConverterUnitTest.php diff --git a/src/DataProvider/Provider/Data/ProductProvider.php b/src/DataProvider/Provider/Data/ProductProvider.php index b775cca93..f244fa3ef 100644 --- a/src/DataProvider/Provider/Data/ProductProvider.php +++ b/src/DataProvider/Provider/Data/ProductProvider.php @@ -7,7 +7,6 @@ namespace SwagMigrationAssistant\DataProvider\Provider\Data; -use Doctrine\DBAL\Connection; use Shopware\Core\Content\Product\ProductCollection; use Shopware\Core\Framework\Context; use Shopware\Core\Framework\DataAbstractionLayer\EntityRepository; @@ -25,15 +24,12 @@ class ProductProvider extends AbstractProvider { private const BUNDLE_PRODUCT_TYPE = 'grouped_bundle'; - private ?bool $hasTypeColumn = null; - /** * @param EntityRepository $productRepo */ public function __construct( private readonly EntityRepository $productRepo, private readonly RouterInterface $router, - private readonly Connection $connection, ) { } @@ -143,13 +139,6 @@ private function addBundleExclusionFilter(Criteria $criteria): void private function hasTypeColumn(): bool { - if ($this->hasTypeColumn !== null) { - return $this->hasTypeColumn; - } - - $columns = $this->connection->createSchemaManager()->listTableColumns('product'); - $this->hasTypeColumn = isset($columns['type']); - - return $this->hasTypeColumn; + return $this->productRepo->getDefinition()->getField('type') !== null; } } diff --git a/src/DependencyInjection/dataProvider.xml b/src/DependencyInjection/dataProvider.xml index 82e830529..664bee350 100644 --- a/src/DependencyInjection/dataProvider.xml +++ b/src/DependencyInjection/dataProvider.xml @@ -71,7 +71,6 @@ - diff --git a/src/DependencyInjection/shopware6.xml b/src/DependencyInjection/shopware6.xml index 79c2781ab..a5f3e65ba 100644 --- a/src/DependencyInjection/shopware6.xml +++ b/src/DependencyInjection/shopware6.xml @@ -115,7 +115,6 @@ - diff --git a/src/Profile/Shopware6/Converter/ProductConverter.php b/src/Profile/Shopware6/Converter/ProductConverter.php index 58c01b895..748461494 100644 --- a/src/Profile/Shopware6/Converter/ProductConverter.php +++ b/src/Profile/Shopware6/Converter/ProductConverter.php @@ -7,16 +7,11 @@ namespace SwagMigrationAssistant\Profile\Shopware6\Converter; -use Doctrine\DBAL\Connection; use Shopware\Core\Content\Product\ProductDefinition; -use Shopware\Core\Content\Product\State; use Shopware\Core\Defaults; use Shopware\Core\Framework\Log\Package; use SwagMigrationAssistant\Migration\Converter\ConvertStruct; use SwagMigrationAssistant\Migration\DataSelection\DefaultEntities; -use SwagMigrationAssistant\Migration\Logging\LoggingServiceInterface; -use SwagMigrationAssistant\Migration\Mapping\MappingServiceInterface; -use SwagMigrationAssistant\Migration\Media\MediaFileServiceInterface; use SwagMigrationAssistant\Migration\MigrationContextInterface; use SwagMigrationAssistant\Profile\Shopware6\DataSelection\DataSet\ProductDataSet; use SwagMigrationAssistant\Profile\Shopware6\Shopware6MajorProfile; @@ -26,17 +21,6 @@ class ProductConverter extends ShopwareMediaConverter { private ?string $sourceDefaultCurrencyUuid; - private ?bool $hasTypeColumn = null; - - public function __construct( - MappingServiceInterface $mappingService, - LoggingServiceInterface $loggingService, - MediaFileServiceInterface $mediaFileService, - private readonly Connection $connection, - ) { - parent::__construct($mappingService, $loggingService, $mediaFileService); - } - public function supports(MigrationContextInterface $migrationContext): bool { return $migrationContext->getProfile()->getName() === Shopware6MajorProfile::PROFILE_NAME @@ -260,16 +244,12 @@ private function checkDefaultCurrency(array &$source, string $key): void */ private function convertStatesToType(array &$converted): void { - if (!$this->hasTypeColumn()) { - return; - } - if (isset($converted['type'])) { return; } if (isset($converted['states']) && \is_array($converted['states'])) { - $converted['type'] = \in_array(State::IS_DOWNLOAD, $converted['states'], true) + $converted['type'] = \in_array('is-download', $converted['states'], true) ? ProductDefinition::TYPE_DIGITAL : ProductDefinition::TYPE_PHYSICAL; @@ -278,16 +258,4 @@ private function convertStatesToType(array &$converted): void $converted['type'] = ProductDefinition::TYPE_PHYSICAL; } - - private function hasTypeColumn(): bool - { - if ($this->hasTypeColumn !== null) { - return $this->hasTypeColumn; - } - - $columns = $this->connection->createSchemaManager()->listTableColumns('product'); - $this->hasTypeColumn = isset($columns['type']); - - return $this->hasTypeColumn; - } } diff --git a/tests/Profile/Shopware6/Converter/ProductConverterTest.php b/tests/Profile/Shopware6/Converter/ProductConverterTest.php index 8cae06417..7b1d41b91 100644 --- a/tests/Profile/Shopware6/Converter/ProductConverterTest.php +++ b/tests/Profile/Shopware6/Converter/ProductConverterTest.php @@ -7,7 +7,6 @@ namespace SwagMigrationAssistant\Test\Profile\Shopware6\Converter; -use Doctrine\DBAL\Connection; use Shopware\Core\Framework\Log\Package; use SwagMigrationAssistant\Migration\Converter\ConverterInterface; use SwagMigrationAssistant\Migration\DataSelection\DataSet\DataSet; @@ -26,9 +25,7 @@ protected function createConverter( MediaFileServiceInterface $mediaFileService, ?array $mappingArray = [], ): ConverterInterface { - $connection = static::getContainer()->get(Connection::class); - - return new ProductConverter($mappingService, $loggingService, $mediaFileService, $connection); + return new ProductConverter($mappingService, $loggingService, $mediaFileService); } protected function createDataSet(): DataSet diff --git a/tests/Profile/Shopware6/Converter/ProductConverterUnitTest.php b/tests/Profile/Shopware6/Converter/ProductConverterUnitTest.php deleted file mode 100644 index bad940c44..000000000 --- a/tests/Profile/Shopware6/Converter/ProductConverterUnitTest.php +++ /dev/null @@ -1,177 +0,0 @@ - - * For the full copyright and license information, please view the LICENSE - * file that was distributed with this source code. - */ - -namespace SwagMigrationAssistant\Test\Profile\Shopware6\Converter; - -use Doctrine\DBAL\Connection; -use Doctrine\DBAL\Schema\AbstractSchemaManager; -use Doctrine\DBAL\Schema\Column; -use Doctrine\DBAL\Types\StringType; -use PHPUnit\Framework\TestCase; -use Shopware\Core\Content\Product\ProductDefinition; -use Shopware\Core\Framework\Context; -use Shopware\Core\Framework\Log\Package; -use Shopware\Core\Framework\Uuid\Uuid; -use SwagMigrationAssistant\Migration\Connection\SwagMigrationConnectionEntity; -use SwagMigrationAssistant\Migration\MigrationContext; -use SwagMigrationAssistant\Profile\Shopware6\Converter\ProductConverter; -use SwagMigrationAssistant\Profile\Shopware6\DataSelection\DataSet\ProductDataSet; -use SwagMigrationAssistant\Profile\Shopware6\Shopware6MajorProfile; -use SwagMigrationAssistant\Test\Mock\Migration\Logging\DummyLoggingService; -use SwagMigrationAssistant\Test\Mock\Migration\Mapping\Dummy6MappingService; -use SwagMigrationAssistant\Test\Mock\Migration\Media\DummyMediaFileService; - -#[Package('fundamentals@after-sales')] -class ProductConverterUnitTest extends TestCase -{ - public function testConvertStatesToTypeWithDownloadState(): void - { - $converter = $this->createConverterWithTypeColumn(true); - $context = Context::createDefaultContext(); - $migrationContext = $this->createMigrationContext(); - - $input = [ - 'id' => Uuid::randomHex(), - 'productNumber' => 'TEST-001', - 'stock' => 10, - 'states' => ['is-download'], - 'name' => 'Digital Product', - ]; - - $result = $converter->convert($input, $context, $migrationContext); - $converted = $result->getConverted(); - - static::assertNotNull($converted); - static::assertArrayHasKey('type', $converted); - static::assertSame(ProductDefinition::TYPE_DIGITAL, $converted['type']); - } - - public function testConvertStatesToTypeWithPhysicalState(): void - { - $converter = $this->createConverterWithTypeColumn(true); - $context = Context::createDefaultContext(); - $migrationContext = $this->createMigrationContext(); - - $input = [ - 'id' => Uuid::randomHex(), - 'productNumber' => 'TEST-002', - 'stock' => 10, - 'states' => ['is-physical'], - 'name' => 'Physical Product', - ]; - - $result = $converter->convert($input, $context, $migrationContext); - $converted = $result->getConverted(); - - static::assertNotNull($converted); - static::assertArrayHasKey('type', $converted); - static::assertSame(ProductDefinition::TYPE_PHYSICAL, $converted['type']); - } - - public function testConvertPreservesExistingType(): void - { - $converter = $this->createConverterWithTypeColumn(true); - $context = Context::createDefaultContext(); - $migrationContext = $this->createMigrationContext(); - - $input = [ - 'id' => Uuid::randomHex(), - 'productNumber' => 'TEST-003', - 'stock' => 10, - 'type' => 'digital', - 'name' => 'Product With Type', - ]; - - $result = $converter->convert($input, $context, $migrationContext); - $converted = $result->getConverted(); - - static::assertNotNull($converted); - static::assertArrayHasKey('type', $converted); - static::assertSame('digital', $converted['type']); - } - - public function testConvertDefaultsToPhysicalType(): void - { - $converter = $this->createConverterWithTypeColumn(true); - $context = Context::createDefaultContext(); - $migrationContext = $this->createMigrationContext(); - - $input = [ - 'id' => Uuid::randomHex(), - 'productNumber' => 'TEST-004', - 'stock' => 10, - 'name' => 'Product Without Type Or States', - ]; - - $result = $converter->convert($input, $context, $migrationContext); - $converted = $result->getConverted(); - - static::assertNotNull($converted); - static::assertArrayHasKey('type', $converted); - static::assertSame(ProductDefinition::TYPE_PHYSICAL, $converted['type']); - } - - public function testConvertDoesNotSetTypeWhenColumnDoesNotExist(): void - { - $converter = $this->createConverterWithTypeColumn(false); - $context = Context::createDefaultContext(); - $migrationContext = $this->createMigrationContext(); - - $input = [ - 'id' => Uuid::randomHex(), - 'productNumber' => 'TEST-005', - 'stock' => 10, - 'states' => ['is-download'], - 'name' => 'Product On Old Database', - ]; - - $result = $converter->convert($input, $context, $migrationContext); - $converted = $result->getConverted(); - - static::assertNotNull($converted); - static::assertArrayNotHasKey('type', $converted); - } - - private function createConverterWithTypeColumn(bool $hasTypeColumn): ProductConverter - { - $schemaManager = $this->createMock(AbstractSchemaManager::class); - - if ($hasTypeColumn) { - $schemaManager->method('listTableColumns')->willReturn([ - 'type' => new Column('type', new StringType()), - ]); - } else { - $schemaManager->method('listTableColumns')->willReturn([]); - } - - $connection = $this->createMock(Connection::class); - $connection->method('createSchemaManager')->willReturn($schemaManager); - - return new ProductConverter( - new Dummy6MappingService(), - new DummyLoggingService(), - new DummyMediaFileService(), - $connection - ); - } - - private function createMigrationContext(): MigrationContext - { - $connection = new SwagMigrationConnectionEntity(); - $connection->setId(Uuid::randomHex()); - $connection->setProfileName(Shopware6MajorProfile::PROFILE_NAME); - - return new MigrationContext( - new Shopware6MajorProfile('6.5'), - $connection, - Uuid::randomHex(), - new ProductDataSet(), - 0, - 250 - ); - } -} diff --git a/tests/_fixtures/Shopware6/Product/01-HappyCaseContainer/output.php b/tests/_fixtures/Shopware6/Product/01-HappyCaseContainer/output.php index f2d2a1061..3cdea7302 100644 --- a/tests/_fixtures/Shopware6/Product/01-HappyCaseContainer/output.php +++ b/tests/_fixtures/Shopware6/Product/01-HappyCaseContainer/output.php @@ -56,4 +56,5 @@ 'id' => 'd7e9ceac19a948abad07667419424b13', ], ], + 'type' => 'physical', ]; diff --git a/tests/_fixtures/Shopware6/Product/02-HappyCaseVariant/output.php b/tests/_fixtures/Shopware6/Product/02-HappyCaseVariant/output.php index 9524f34b1..41c1353d1 100644 --- a/tests/_fixtures/Shopware6/Product/02-HappyCaseVariant/output.php +++ b/tests/_fixtures/Shopware6/Product/02-HappyCaseVariant/output.php @@ -22,4 +22,5 @@ 'id' => 'bfaf0c7366e6454fb7516ab47435b01a', ], ], + 'type' => 'physical', ]; diff --git a/tests/_fixtures/Shopware6/Product/03-MissingManufacturerMapping/output.php b/tests/_fixtures/Shopware6/Product/03-MissingManufacturerMapping/output.php index dc71522c5..24fa92547 100644 --- a/tests/_fixtures/Shopware6/Product/03-MissingManufacturerMapping/output.php +++ b/tests/_fixtures/Shopware6/Product/03-MissingManufacturerMapping/output.php @@ -55,4 +55,5 @@ 'id' => 'd7e9ceac19a948abad07667419424b13', ], ], + 'type' => 'physical', ]; diff --git a/tests/_fixtures/Shopware6/Product/04-StripUnmigrateableData/output.php b/tests/_fixtures/Shopware6/Product/04-StripUnmigrateableData/output.php index 99881960a..f758739e1 100644 --- a/tests/_fixtures/Shopware6/Product/04-StripUnmigrateableData/output.php +++ b/tests/_fixtures/Shopware6/Product/04-StripUnmigrateableData/output.php @@ -57,4 +57,5 @@ 'id' => 'd7e9ceac19a948abad07667419424b13', ], ], + 'type' => 'physical', ]; diff --git a/tests/_fixtures/Shopware6/Product/05-AdvancedPrices/output.php b/tests/_fixtures/Shopware6/Product/05-AdvancedPrices/output.php index 60f53daaf..d1824b9c5 100644 --- a/tests/_fixtures/Shopware6/Product/05-AdvancedPrices/output.php +++ b/tests/_fixtures/Shopware6/Product/05-AdvancedPrices/output.php @@ -139,4 +139,5 @@ ], 'coverId' => 'bdeb106f47ab4255b2bd5f35d84cae7c', 'id' => 'fb2dbbee297c472c9e916b26952615ff', + 'type' => 'physical', ]; diff --git a/tests/_fixtures/Shopware6/Product/06-DeliveryTimes/output.php b/tests/_fixtures/Shopware6/Product/06-DeliveryTimes/output.php index b934b0764..ab2403e38 100644 --- a/tests/_fixtures/Shopware6/Product/06-DeliveryTimes/output.php +++ b/tests/_fixtures/Shopware6/Product/06-DeliveryTimes/output.php @@ -140,4 +140,5 @@ 'coverId' => 'bdeb106f47ab4255b2bd5f35d84cae7c', 'deliveryTimeId' => 'bdeb106f47ab4255b2bd5f35d84cae7c', 'id' => 'fb2dbbee297c472c9e916b26952615ff', + 'type' => 'physical', ]; diff --git a/tests/_fixtures/Shopware6/Product/07-Media/output.php b/tests/_fixtures/Shopware6/Product/07-Media/output.php index 455769093..8776a39f4 100644 --- a/tests/_fixtures/Shopware6/Product/07-Media/output.php +++ b/tests/_fixtures/Shopware6/Product/07-Media/output.php @@ -83,4 +83,5 @@ 'coverId' => 'eb5483a9c77c4919b5d110e8d745a1cc', 'deliveryTimeId' => 'bdeb106f47ab4255b2bd5f35d84cae7c', 'id' => 'fb2dbbee297c472c9e916b26952615ff', + 'type' => 'physical', ]; diff --git a/tests/_fixtures/Shopware6/Product/08-MigrateWithoutDefaultCurrency/output.php b/tests/_fixtures/Shopware6/Product/08-MigrateWithoutDefaultCurrency/output.php index 43d425779..9b87fed4c 100644 --- a/tests/_fixtures/Shopware6/Product/08-MigrateWithoutDefaultCurrency/output.php +++ b/tests/_fixtures/Shopware6/Product/08-MigrateWithoutDefaultCurrency/output.php @@ -209,4 +209,5 @@ 'id' => 'd7e9ceac19a948abad07667419424b13', ], ], + 'type' => 'physical', ]; diff --git a/tests/_fixtures/Shopware6/Product/09-MigrateWithConfiguratorSettings/output.php b/tests/_fixtures/Shopware6/Product/09-MigrateWithConfiguratorSettings/output.php index 37bb6fc03..165f24869 100644 --- a/tests/_fixtures/Shopware6/Product/09-MigrateWithConfiguratorSettings/output.php +++ b/tests/_fixtures/Shopware6/Product/09-MigrateWithConfiguratorSettings/output.php @@ -121,4 +121,5 @@ 'coverId' => 'eb5483a9c77c4919b5d110e8d745a1cc', 'deliveryTimeId' => 'bdeb106f47ab4255b2bd5f35d84cae7c', 'id' => 'fb2dbbee297c472c9e916b26952615ff', + 'type' => 'physical', ];