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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# [NEXT]
- Fixes errors when downloading media.
- Fixes errors when migrating category images.

# 13.0.0

- Compatibility with Migration Assistant version 18.
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG_de-DE.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# [NEXT]
- Behebt Fehler beim Herunterladen von Medien.
- Behebt Fehler bei der Migration von Kategoriebildern.

# 13.0.0

- Kompatibilität mit Migration Assistant Version 18.
Expand Down
17 changes: 16 additions & 1 deletion src/Profile/Magento/Converter/CategoryConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@
#[Package('fundamentals@after-sales')]
abstract class CategoryConverter extends MagentoConverter
Comment thread
DennisGarding marked this conversation as resolved.
{
private const DIRECTORY_SEPARATOR = '/';

private const CATEGORY_MEDIA_PATH = 'media/catalog/category/';

protected string $connectionId;

protected Context $context;
Expand Down Expand Up @@ -384,7 +388,7 @@ protected function getCategoryMedia(string $path): array
[
'runId' => $this->runId,
'entity' => MediaDataSet::getEntity(),
'uri' => '/media/catalog/category/' . $path,
'uri' => $this->createMediaUri($path),
'fileName' => $categoryMedia['id'],
'fileSize' => 0,
'mediaId' => $categoryMedia['id'],
Expand All @@ -406,4 +410,15 @@ private function parentIsRoot(array $data, ?array $rootCategoryMapping): bool

return true;
}

private function createMediaUri(string $path): string
{
$normalizedPath = \ltrim($path, self::DIRECTORY_SEPARATOR);

if (\str_starts_with($normalizedPath, self::CATEGORY_MEDIA_PATH)) {
return self::DIRECTORY_SEPARATOR . $normalizedPath;
}

return self::DIRECTORY_SEPARATOR . self::CATEGORY_MEDIA_PATH . $normalizedPath;
}
}
53 changes: 48 additions & 5 deletions tests/Profile/Magento2/Converter/Magento2CategoryConverterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

namespace Swag\MigrationMagento\Test\Profile\Magento2\Converter;

use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
use Shopware\Core\Framework\Context;
use Shopware\Core\Framework\Log\Package;
Expand Down Expand Up @@ -76,9 +77,11 @@ class Magento2CategoryConverterTest extends TestCase

private string $defaultLanguageUuid;

private DummyMediaFileService $mediaFileService;

protected function setUp(): void
{
$mediaFileService = new DummyMediaFileService();
$this->mediaFileService = new DummyMediaFileService();
$mappingService = new DummyMagentoMappingService();
$this->loggingService = new DummyLoggingService();

Expand Down Expand Up @@ -163,10 +166,10 @@ protected function setUp(): void
$defaultCmsPageLookup = $this->getContainer()->get(DefaultCmsPageLookup::class);
$languageLookup = $this->getContainer()->get(LanguageLookup::class);

$this->categoryConverter20 = new Magento20CategoryConverter($mappingService, $this->loggingService, $mediaFileService, $mediaFolderLookup, $lowestRootCategoryLookup, $defaultCmsPageLookup, $languageLookup);
$this->categoryConverter21 = new Magento21CategoryConverter($mappingService, $this->loggingService, $mediaFileService, $mediaFolderLookup, $lowestRootCategoryLookup, $defaultCmsPageLookup, $languageLookup);
$this->categoryConverter22 = new Magento22CategoryConverter($mappingService, $this->loggingService, $mediaFileService, $mediaFolderLookup, $lowestRootCategoryLookup, $defaultCmsPageLookup, $languageLookup);
$this->categoryConverter23 = new Magento23CategoryConverter($mappingService, $this->loggingService, $mediaFileService, $mediaFolderLookup, $lowestRootCategoryLookup, $defaultCmsPageLookup, $languageLookup);
$this->categoryConverter20 = new Magento20CategoryConverter($mappingService, $this->loggingService, $this->mediaFileService, $mediaFolderLookup, $lowestRootCategoryLookup, $defaultCmsPageLookup, $languageLookup);
$this->categoryConverter21 = new Magento21CategoryConverter($mappingService, $this->loggingService, $this->mediaFileService, $mediaFolderLookup, $lowestRootCategoryLookup, $defaultCmsPageLookup, $languageLookup);
$this->categoryConverter22 = new Magento22CategoryConverter($mappingService, $this->loggingService, $this->mediaFileService, $mediaFolderLookup, $lowestRootCategoryLookup, $defaultCmsPageLookup, $languageLookup);
$this->categoryConverter23 = new Magento23CategoryConverter($mappingService, $this->loggingService, $this->mediaFileService, $mediaFolderLookup, $lowestRootCategoryLookup, $defaultCmsPageLookup, $languageLookup);
}

public function testSupports(): void
Expand Down Expand Up @@ -224,6 +227,46 @@ public function testConvert20(): void
);
}

#[DataProvider('categoryImagePathProvider')]
public function testConvertCategoryImagePath(string $sourcePath, string $expectedUri): void
{
$categoryData = require __DIR__ . '/../../../_fixtures/category_data.php';
$categoryData[1]['image'] = $sourcePath;

$this->mediaFileService->resetMediaFileArray();
$this->categoryConverter20->convert(
$categoryData[1],
Context::createDefaultContext(),
$this->migrationContext20
);

$mediaFiles = $this->mediaFileService->getMediaFileArray();

static::assertCount(1, $mediaFiles);
static::assertSame($expectedUri, $mediaFiles[0]['uri']);
}

/**
* @return iterable<string, array{sourcePath: string, expectedUri: string}>
*/
public static function categoryImagePathProvider(): iterable
{
yield 'bare category image filename' => [
'sourcePath' => 'example.jpg',
'expectedUri' => '/media/catalog/category/example.jpg',
];

yield 'category image with existing media prefix' => [
'sourcePath' => '/media/catalog/category/example.jpg',
'expectedUri' => '/media/catalog/category/example.jpg',
];

yield 'category image with existing media prefix without leading slash' => [
'sourcePath' => 'media/catalog/category/example.jpg',
'expectedUri' => '/media/catalog/category/example.jpg',
];
}

public function testConvert21(): void
{
$categoryData = require __DIR__ . '/../../../_fixtures/category_data.php';
Expand Down