|
7 | 7 |
|
8 | 8 | use Magento\Catalog\Api\Data\ProductExtensionInterfaceFactory; |
9 | 9 | use Magento\Catalog\Api\ProductRepositoryInterface; |
10 | | -use Magento\Catalog\Model\ProductFactory; |
11 | 10 | use Magento\TestFramework\Helper\Bootstrap; |
12 | 11 | use Magento\TestFramework\Workaround\Override\Fixture\Resolver; |
13 | 12 |
|
|
21 | 20 | $objectManager = Bootstrap::getObjectManager(); |
22 | 21 | /** @var ProductRepositoryInterface $productRepository */ |
23 | 22 | $productRepository = $objectManager->get(ProductRepositoryInterface::class); |
| 23 | +$configurableProduct = $productRepository->get('configurable'); |
| 24 | +$children = $configurableProduct->getTypeInstance()->getUsedProducts($configurableProduct); |
24 | 25 | $images = ['magento_image.jpg', 'magento_small_image.jpg', 'magento_thumbnail.jpg']; |
25 | | -foreach (range(1, 3) as $index) { |
26 | | - $product = $productRepository->get('simple_option_' . $index); |
27 | | - $product->setImage('/m/a/' . $images[$index - 1]) |
28 | | - ->setSmallImage('/m/a/' . $images[$index - 1]) |
29 | | - ->setThumbnail('/m/a/' . $images[$index - 1]) |
| 26 | +foreach ($children as $index => $product) { |
| 27 | + $product->setImage('/m/a/' . $images[$index]) |
| 28 | + ->setSmallImage('/m/a/' . $images[$index]) |
| 29 | + ->setThumbnail('/m/a/' . $images[$index]) |
30 | 30 | ->setData('media_gallery', ['images' => [ |
31 | 31 | [ |
32 | | - 'file' => '/m/a/' . $images[$index - 1], |
| 32 | + 'file' => '/m/a/' . $images[$index], |
33 | 33 | 'position' => 1, |
34 | 34 | 'label' => 'Image Alt Text', |
35 | 35 | 'disabled' => 0, |
|
0 commit comments