File tree Expand file tree Collapse file tree 2 files changed +38
-1
lines changed
Test/Unit/Ui/DataProvider/Product/Form/Modifier
Ui/DataProvider/Product/Form/Modifier Expand file tree Collapse file tree 2 files changed +38
-1
lines changed Original file line number Diff line number Diff line change @@ -24,7 +24,9 @@ protected function createModel()
24
24
25
25
public function testModifyData ()
26
26
{
27
- $ this ->assertSame ($ this ->getSampleData (), $ this ->getModel ()->modifyData ($ this ->getSampleData ()));
27
+ $ this ->productMock ->expects ($ this ->once ())->method ('getId ' )->willReturn (2051 );
28
+ $ actualResult = $ this ->getModel ()->modifyData ($ this ->getSampleData ());
29
+ $ this ->assertSame ("" , $ actualResult [2051 ]['product ' ]['media_gallery ' ]['images ' ][0 ]['label ' ]);
28
30
}
29
31
30
32
public function testModifyMeta ()
@@ -40,4 +42,24 @@ public function testModifyMeta()
40
42
41
43
$ this ->assertSame ([], $ this ->getModel ()->modifyMeta ($ meta ));
42
44
}
45
+
46
+ /**
47
+ * {@inheritdoc}
48
+ */
49
+ protected function getSampleData ()
50
+ {
51
+ return [
52
+ 2051 => [
53
+ 'product ' => [
54
+ 'media_gallery ' => [
55
+ 'images ' => [
56
+ [
57
+ 'label ' => null
58
+ ]
59
+ ]
60
+ ]
61
+ ]
62
+ ]
63
+ ];
64
+ }
43
65
}
Original file line number Diff line number Diff line change @@ -51,6 +51,21 @@ public function modifyMeta(array $meta)
51
51
*/
52
52
public function modifyData (array $ data )
53
53
{
54
+ /** @var \Magento\Catalog\Api\Data\ProductInterface $product */
55
+ $ product = $ this ->locator ->getProduct ();
56
+ $ modelId = $ product ->getId ();
57
+ if (
58
+ isset ($ data [$ modelId ][self ::DATA_SOURCE_DEFAULT ]['media_gallery ' ])
59
+ && !empty ($ data [$ modelId ][self ::DATA_SOURCE_DEFAULT ]['media_gallery ' ])
60
+ && !empty ($ data [$ modelId ][self ::DATA_SOURCE_DEFAULT ]['media_gallery ' ]['images ' ])
61
+ ) {
62
+ foreach ($ data [$ modelId ][self ::DATA_SOURCE_DEFAULT ]['media_gallery ' ]['images ' ] as $ index => $ image ) {
63
+ if (!isset ($ image ['label ' ])) {
64
+ $ data [$ modelId ][self ::DATA_SOURCE_DEFAULT ]['media_gallery ' ]['images ' ][$ index ]['label ' ] = "" ;
65
+ }
66
+ }
67
+ };
68
+
54
69
return $ data ;
55
70
}
56
71
}
You can’t perform that action at this time.
0 commit comments