Skip to content

Commit 6724a91

Browse files
MC-23743: [2.3.1] Updating Youtube video via API causes data to be lost.
1 parent 5a9fcab commit 6724a91

File tree

2 files changed

+100
-1
lines changed

2 files changed

+100
-1
lines changed

app/code/Magento/Catalog/Model/ProductRepository/MediaGalleryProcessor.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,15 @@ private function processEntries(ProductInterface $product, array $newEntries, ar
224224
$this->processNewMediaGalleryEntry($product, $newEntry);
225225

226226
$finalGallery = $product->getData('media_gallery');
227-
$newEntryId = key(array_diff_key($product->getData('media_gallery')['images'], $entriesById));
227+
228+
$entryIds = array_keys(
229+
array_diff_key(
230+
$product->getData('media_gallery')['images'],
231+
$entriesById
232+
)
233+
);
234+
$newEntryId = array_pop($entryIds);
235+
228236
$newEntry = array_replace_recursive($newEntry, $finalGallery['images'][$newEntryId]);
229237
$entriesById[$newEntryId] = $newEntry;
230238
$finalGallery['images'][$newEntryId] = $newEntry;

dev/tests/api-functional/testsuite/Magento/Catalog/Api/ProductRepositoryInterfaceTest.php

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,97 @@ public function testCreate($product)
381381
$this->deleteProduct($product[ProductInterface::SKU]);
382382
}
383383

384+
/**
385+
* Media gallery entries with external videos
386+
*
387+
* @return array
388+
*/
389+
public function externalVideoDataProvider(): array
390+
{
391+
return [
392+
[
393+
[
394+
[
395+
'media_type' => 'external-video',
396+
'disabled' => false,
397+
'label' => 'Test Video Created',
398+
'types' => [],
399+
'position' => 1,
400+
'content' => [
401+
'type' => 'image/png',
402+
'name' => 'thumbnail.png',
403+
'base64_encoded_data' => 'iVBORw0KGgoAAAANSUhEUgAAAP8AAADGCAMAAAAqo6adAAAAA1BMVEUAAP79f'
404+
. '+LBAAAASElEQVR4nO3BMQEAAADCoPVPbQwfoAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'
405+
. 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAA+BsYAAAF7hZJ0AAAAAElFTkSuQmCC',
406+
],
407+
'extension_attributes' => [
408+
'video_content' => [
409+
'media_type' => 'external-video',
410+
'video_provider' => 'youtube',
411+
'video_url' => 'https://www.youtube.com/',
412+
'video_title' => 'Video title',
413+
'video_description' => 'Video description',
414+
'video_metadata' => 'Video meta',
415+
],
416+
],
417+
]
418+
]
419+
],
420+
[
421+
[
422+
[
423+
'media_type' => 'external-video',
424+
'disabled' => false,
425+
'label' => 'Test Video Updated',
426+
'types' => [],
427+
'position' => 1,
428+
'content' => [
429+
'type' => 'image/png',
430+
'name' => 'thumbnail.png',
431+
'base64_encoded_data' => 'iVBORw0KGgoAAAANSUhEUgAAAP8AAADGCAMAAAAqo6adAAAAA1BMVEUAAP79f'
432+
. '+LBAAAASElEQVR4nO3BMQEAAADCoPVPbQwfoAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA'
433+
. 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAA+BsYAAAF7hZJ0AAAAAElFTkSuQmCC',
434+
],
435+
'extension_attributes' => [
436+
'video_content' => [
437+
'media_type' => 'external-video',
438+
'video_provider' => 'vimeo',
439+
'video_url' => 'https://www.vimeo.com/',
440+
'video_title' => 'Video title',
441+
'video_description' => 'Video description',
442+
'video_metadata' => 'Video meta',
443+
],
444+
],
445+
]
446+
]
447+
]
448+
];
449+
}
450+
451+
/**
452+
* Test create/ update product with external video media gallery entry
453+
*
454+
* @dataProvider externalVideoDataProvider
455+
* @param array $mediaGalleryData
456+
*/
457+
public function testCreateWithExternalVideo(array $mediaGalleryData)
458+
{
459+
$simpleProductBaseData = $this->getSimpleProductData(
460+
[
461+
ProductInterface::NAME => 'Product With Ext. Video',
462+
ProductInterface::SKU => 'prod-with-ext-video'
463+
]
464+
);
465+
466+
$simpleProductBaseData['media_gallery_entries'] = $mediaGalleryData;
467+
468+
$response = $this->saveProduct($simpleProductBaseData);
469+
$this->assertEquals(
470+
$simpleProductBaseData['media_gallery_entries'][0]['extension_attributes'],
471+
$response["media_gallery_entries"][0]["extension_attributes"]
472+
);
473+
}
474+
384475
/**
385476
* @param array $fixtureProduct
386477
*

0 commit comments

Comments
 (0)