Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 27 additions & 1 deletion src/DataProvider/Provider/Data/ProductProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -20,6 +22,8 @@
#[Package('fundamentals@after-sales')]
class ProductProvider extends AbstractProvider
{
private const BUNDLE_PRODUCT_TYPE = 'grouped_bundle';

/**
* @param EntityRepository<ProductCollection> $productRepo
*/
Expand Down Expand Up @@ -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, [
Expand Down Expand Up @@ -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;
}
}
23 changes: 23 additions & 0 deletions src/Profile/Shopware6/Converter/ProductConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -205,6 +206,8 @@ protected function convertData(array $data): ConvertStruct
);
}

$this->convertStatesToType($converted);

return new ConvertStruct($converted, null, $this->mainMapping['id'] ?? null);
}

Expand Down Expand Up @@ -235,4 +238,24 @@ private function checkDefaultCurrency(array &$source, string $key): void
$source[$key][] = $defaultPrice;
}
}

/**
* @param array<string, mixed> $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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,5 @@
'id' => 'd7e9ceac19a948abad07667419424b13',
],
],
'type' => 'physical',
];
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,5 @@
'id' => 'bfaf0c7366e6454fb7516ab47435b01a',
],
],
'type' => 'physical',
];
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,5 @@
'id' => 'd7e9ceac19a948abad07667419424b13',
],
],
'type' => 'physical',
];
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,5 @@
'id' => 'd7e9ceac19a948abad07667419424b13',
],
],
'type' => 'physical',
];
Original file line number Diff line number Diff line change
Expand Up @@ -139,4 +139,5 @@
],
'coverId' => 'bdeb106f47ab4255b2bd5f35d84cae7c',
'id' => 'fb2dbbee297c472c9e916b26952615ff',
'type' => 'physical',
];
Original file line number Diff line number Diff line change
Expand Up @@ -140,4 +140,5 @@
'coverId' => 'bdeb106f47ab4255b2bd5f35d84cae7c',
'deliveryTimeId' => 'bdeb106f47ab4255b2bd5f35d84cae7c',
'id' => 'fb2dbbee297c472c9e916b26952615ff',
'type' => 'physical',
];
1 change: 1 addition & 0 deletions tests/_fixtures/Shopware6/Product/07-Media/output.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,4 +83,5 @@
'coverId' => 'eb5483a9c77c4919b5d110e8d745a1cc',
'deliveryTimeId' => 'bdeb106f47ab4255b2bd5f35d84cae7c',
'id' => 'fb2dbbee297c472c9e916b26952615ff',
'type' => 'physical',
];
Original file line number Diff line number Diff line change
Expand Up @@ -209,4 +209,5 @@
'id' => 'd7e9ceac19a948abad07667419424b13',
],
],
'type' => 'physical',
];
Original file line number Diff line number Diff line change
Expand Up @@ -121,4 +121,5 @@
'coverId' => 'eb5483a9c77c4919b5d110e8d745a1cc',
'deliveryTimeId' => 'bdeb106f47ab4255b2bd5f35d84cae7c',
'id' => 'fb2dbbee297c472c9e916b26952615ff',
'type' => 'physical',
];