diff --git a/src/DataProvider/Provider/Data/ProductProvider.php b/src/DataProvider/Provider/Data/ProductProvider.php index 15f279c38..f244fa3ef 100644 --- a/src/DataProvider/Provider/Data/ProductProvider.php +++ b/src/DataProvider/Provider/Data/ProductProvider.php @@ -11,6 +11,8 @@ 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,6 +22,8 @@ #[Package('fundamentals@after-sales')] class ProductProvider extends AbstractProvider { + private const BUNDLE_PRODUCT_TYPE = 'grouped_bundle'; + /** * @param EntityRepository $productRepo */ @@ -55,6 +59,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 +118,27 @@ 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 + { + return $this->productRepo->getDefinition()->getField('type') !== null; } } diff --git a/src/Profile/Shopware6/Converter/ProductConverter.php b/src/Profile/Shopware6/Converter/ProductConverter.php index 60494ae22..748461494 100644 --- a/src/Profile/Shopware6/Converter/ProductConverter.php +++ b/src/Profile/Shopware6/Converter/ProductConverter.php @@ -7,6 +7,7 @@ namespace SwagMigrationAssistant\Profile\Shopware6\Converter; +use Shopware\Core\Content\Product\ProductDefinition; use Shopware\Core\Defaults; use Shopware\Core\Framework\Log\Package; use SwagMigrationAssistant\Migration\Converter\ConvertStruct; @@ -205,6 +206,8 @@ protected function convertData(array $data): ConvertStruct ); } + $this->convertStatesToType($converted); + return new ConvertStruct($converted, null, $this->mainMapping['id'] ?? null); } @@ -235,4 +238,24 @@ private function checkDefaultCurrency(array &$source, string $key): void $source[$key][] = $defaultPrice; } } + + /** + * @param array $converted + */ + private function convertStatesToType(array &$converted): void + { + if (isset($converted['type'])) { + return; + } + + if (isset($converted['states']) && \is_array($converted['states'])) { + $converted['type'] = \in_array('is-download', $converted['states'], true) + ? ProductDefinition::TYPE_DIGITAL + : ProductDefinition::TYPE_PHYSICAL; + + return; + } + + $converted['type'] = ProductDefinition::TYPE_PHYSICAL; + } } 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', ];