@@ -31,6 +31,13 @@ class Curl extends AbstractCurl implements CatalogProductSimpleInterface
31
31
*/
32
32
protected $ fields ;
33
33
34
+ /**
35
+ * Temporary media path.
36
+ *
37
+ * @var string
38
+ */
39
+ protected $ mediaPathTmp = '/pub/media/tmp/catalog/product/ ' ;
40
+
34
41
/**
35
42
* Product website.
36
43
*
@@ -288,6 +295,10 @@ public function prepareData(FixtureInterface $fixture)
288
295
$ this ->prepareCustomOptionsData ();
289
296
$ this ->prepareAutosetting ();
290
297
$ this ->prepareCustomAttributes ();
298
+ if (isset ($ this ->fields ['product ' ]['media_gallery ' ])) {
299
+ $ this ->fields ['product ' ]['media_gallery ' ]
300
+ = $ this ->prepareMediaGallery ($ this ->fields ['product ' ]['media_gallery ' ]);
301
+ }
291
302
292
303
$ this ->fields ['product ' ] = $ this ->replaceMappingData ($ this ->fields ['product ' ]);
293
304
return $ this ->fields ;
@@ -352,7 +363,20 @@ protected function prepareIsVirtual()
352
363
*/
353
364
protected function prepareAttributeSet ()
354
365
{
355
- if ($ this ->fixture ->hasData ('attribute_set_id ' )) {
366
+ if (
367
+ $ this ->fixture ->hasData ('attribute_set_id ' )
368
+ && !empty ($ this ->fixture ->getDataFieldConfig ('attribute_set_id ' )['source ' ])
369
+ && $ this ->fixture ->getDataFieldConfig ('attribute_set_id ' )['source ' ]->getAttributeSet ()
370
+ ) {
371
+ $ this ->fields ['product ' ]['attribute_set_id ' ] = $ this ->fixture
372
+ ->getDataFieldConfig ('attribute_set_id ' )['source ' ]
373
+ ->getAttributeSet ()
374
+ ->getAttributeSetId ();
375
+ } else if (
376
+ $ this ->fixture ->hasData ('attribute_set_id ' )
377
+ && !empty ($ this ->fixture ->getDataFieldConfig ('attribute_set_id ' )['source ' ])
378
+ && $ this ->fixture ->getDataFieldConfig ('attribute_set_id ' )['source ' ]->getAttributeSet ()
379
+ ) {
356
380
$ this ->fields ['product ' ]['attribute_set_id ' ] = $ this ->fixture
357
381
->getDataFieldConfig ('attribute_set_id ' )['source ' ]
358
382
->getAttributeSet ()
@@ -420,13 +444,14 @@ protected function prepareCategory()
420
444
protected function prepareWebsites ()
421
445
{
422
446
if (!empty ($ this ->fields ['product ' ]['website_ids ' ])) {
447
+ unset($ this ->fields ['product ' ]['website_ids ' ]);
423
448
foreach ($ this ->fixture ->getDataFieldConfig ('website_ids ' )['source ' ]->getWebsites () as $ key => $ website ) {
424
- $ this ->fields ['product ' ]['extension_attributes ' ][ ' website_ids ' ][$ key ] = $ website ->getWebsiteId ();
449
+ $ this ->fields ['product ' ]['website_ids ' ][$ key ] = $ website ->getWebsiteId ();
425
450
}
426
451
} else {
427
452
$ website = \Magento \Mtf \ObjectManagerFactory::getObjectManager ()
428
453
->create (\Magento \Store \Test \Fixture \Website::class, ['dataset ' => 'default ' ]);
429
- $ this ->fields ['product ' ]['extension_attributes ' ][ ' website_ids ' ][] = $ website ->getWebsiteId ();
454
+ $ this ->fields ['product ' ]['website_ids ' ][] = $ website ->getWebsiteId ();
430
455
}
431
456
}
432
457
@@ -615,4 +640,49 @@ protected function prepareFpt()
615
640
unset($ this ->fields ['product ' ]['fpt ' ]);
616
641
}
617
642
}
643
+
644
+ /**
645
+ * Create test image file.
646
+ *
647
+ * @param string $filename
648
+ * @return array
649
+ */
650
+ protected function prepareMediaGallery ($ filename )
651
+ {
652
+ $ filePath = $ this ->getFullPath ($ filename );
653
+
654
+ if (!file_exists ($ filePath )) {
655
+ $ image = imagecreate (300 , 200 );
656
+ $ colorYellow = imagecolorallocate ($ image , 255 , 255 , 0 );
657
+ imagefilledrectangle ($ image , 50 , 50 , 250 , 150 , $ colorYellow );
658
+ $ directory = dirname ($ filePath );
659
+ if (!file_exists ($ directory )) {
660
+ mkdir ($ directory , 0777 , true );
661
+ }
662
+ imagejpeg ($ image , $ filePath );
663
+ imagedestroy ($ image );
664
+ }
665
+
666
+ return [
667
+ 'images ' => [
668
+ 0 => [
669
+ 'position ' => 1 ,
670
+ 'file ' => $ filename ,
671
+ 'disabled ' => 0 ,
672
+ 'label ' => $ filename ,
673
+ ],
674
+ ],
675
+ ];
676
+ }
677
+
678
+ /**
679
+ * Gets full path based on filename.
680
+ *
681
+ * @param string $filename
682
+ * @return string
683
+ */
684
+ private function getFullPath ($ filename )
685
+ {
686
+ return BP . $ this ->mediaPathTmp . $ filename ;
687
+ }
618
688
}
0 commit comments