|
29 | 29 | use Magento\ImportExport\Model\Import;
|
30 | 30 | use Magento\ImportExport\Model\Import\Source\Csv;
|
31 | 31 | use Magento\Store\Model\Store;
|
| 32 | +use Magento\Store\Model\StoreManagerInterface; |
32 | 33 | use Magento\UrlRewrite\Model\ResourceModel\UrlRewriteCollection;
|
33 | 34 | use Psr\Log\LoggerInterface;
|
34 | 35 | use Magento\TestFramework\Helper\Bootstrap as BootstrapHelper;
|
@@ -386,14 +387,14 @@ public function testSaveCustomOptions(string $importFile, string $sku, int $expe
|
386 | 387 | public function testSaveCustomOptionsWithMultipleStoreViews()
|
387 | 388 | {
|
388 | 389 | $objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
|
389 |
| - /** @var \Magento\Store\Model\StoreManagerInterface $storeManager */ |
390 |
| - $storeManager = $objectManager->get(\Magento\Store\Model\StoreManagerInterface::class); |
| 390 | + /** @var StoreManagerInterface $storeManager */ |
| 391 | + $storeManager = $objectManager->get(StoreManagerInterface::class); |
391 | 392 | $storeCodes = [
|
392 | 393 | 'admin',
|
393 | 394 | 'default',
|
394 | 395 | 'secondstore',
|
395 | 396 | ];
|
396 |
| - /** @var \Magento\Store\Model\StoreManagerInterface $storeManager */ |
| 397 | + /** @var StoreManagerInterface $storeManager */ |
397 | 398 | $importFile = 'product_with_custom_options_and_multiple_store_views.csv';
|
398 | 399 | $sku = 'simple';
|
399 | 400 | $pathToFile = __DIR__ . '/_files/' . $importFile;
|
@@ -1187,7 +1188,7 @@ public function testProductsWithMultipleStores()
|
1187 | 1188 | $product->load($id);
|
1188 | 1189 | $this->assertEquals('1', $product->getHasOptions());
|
1189 | 1190 |
|
1190 |
| - $objectManager->get(\Magento\Store\Model\StoreManagerInterface::class)->setCurrentStore('fixturestore'); |
| 1191 | + $objectManager->get(StoreManagerInterface::class)->setCurrentStore('fixturestore'); |
1191 | 1192 |
|
1192 | 1193 | /** @var \Magento\Catalog\Model\Product $simpleProduct */
|
1193 | 1194 | $simpleProduct = $objectManager->create(\Magento\Catalog\Model\Product::class);
|
@@ -2246,13 +2247,20 @@ function ($output, $error) {
|
2246 | 2247 | * Load product by given product sku
|
2247 | 2248 | *
|
2248 | 2249 | * @param string $sku
|
| 2250 | + * @param mixed $store |
2249 | 2251 | * @return \Magento\Catalog\Model\Product
|
2250 | 2252 | */
|
2251 |
| - private function getProductBySku($sku) |
| 2253 | + private function getProductBySku($sku, $store = null) |
2252 | 2254 | {
|
2253 | 2255 | $resource = $this->objectManager->get(\Magento\Catalog\Model\ResourceModel\Product::class);
|
2254 | 2256 | $productId = $resource->getIdBySku($sku);
|
2255 | 2257 | $product = $this->objectManager->create(\Magento\Catalog\Model\Product::class);
|
| 2258 | + if ($store) { |
| 2259 | + /** @var StoreManagerInterface $storeManager */ |
| 2260 | + $storeManager = $this->objectManager->get(StoreManagerInterface::class); |
| 2261 | + $store = $storeManager->getStore($store); |
| 2262 | + $product->setStoreId($store->getId()); |
| 2263 | + } |
2256 | 2264 | $product->load($productId);
|
2257 | 2265 |
|
2258 | 2266 | return $product;
|
@@ -2773,4 +2781,56 @@ public function testProductBaseImageAfterImport()
|
2773 | 2781 | $productAfterImport = $this->getProductBySku('simple_new');
|
2774 | 2782 | $this->assertNotEquals('/no/exists/image/magento_image.jpg', $productAfterImport->getData('image'));
|
2775 | 2783 | }
|
| 2784 | + |
| 2785 | + /** |
| 2786 | + * Tests that images are hidden only for a store view in "store_view_code". |
| 2787 | + * |
| 2788 | + * @magentoDataFixture mediaImportImageFixture |
| 2789 | + * @magentoDataFixture Magento/Store/_files/core_fixturestore.php |
| 2790 | + * @magentoDataFixture Magento/Catalog/_files/product_with_image.php |
| 2791 | + */ |
| 2792 | + public function testHideImageForStoreView() |
| 2793 | + { |
| 2794 | + $expectedImageFile = '/m/a/magento_image.jpg'; |
| 2795 | + $secondStoreCode = 'fixturestore'; |
| 2796 | + $productSku = 'simple'; |
| 2797 | + $this->importDataForMediaTest('import_hide_image_for_storeview.csv'); |
| 2798 | + $product = $this->getProductBySku($productSku); |
| 2799 | + $imageItems = $product->getMediaGalleryImages()->getItems(); |
| 2800 | + $this->assertCount(1, $imageItems); |
| 2801 | + $imageItem = array_shift($imageItems); |
| 2802 | + $this->assertEquals($expectedImageFile, $imageItem->getFile()); |
| 2803 | + $product = $this->getProductBySku($productSku, $secondStoreCode); |
| 2804 | + $imageItems = $product->getMediaGalleryImages()->getItems(); |
| 2805 | + $this->assertCount(0, $imageItems); |
| 2806 | + } |
| 2807 | + |
| 2808 | + /** |
| 2809 | + * Test that images labels are updated only for a store view in "store_view_code". |
| 2810 | + * |
| 2811 | + * @magentoDataFixture mediaImportImageFixture |
| 2812 | + * @magentoDataFixture Magento/Store/_files/core_fixturestore.php |
| 2813 | + * @magentoDataFixture Magento/Catalog/_files/product_with_image.php |
| 2814 | + */ |
| 2815 | + public function testChangeImageLabelForStoreView() |
| 2816 | + { |
| 2817 | + $expectedImageFile = '/m/a/magento_image.jpg'; |
| 2818 | + $expectedLabelForDefaultStoreView = 'Image Alt Text'; |
| 2819 | + $expectedLabelForSecondStoreView = 'Magento Logo'; |
| 2820 | + $secondStoreCode = 'fixturestore'; |
| 2821 | + $productSku = 'simple'; |
| 2822 | + $this->importDataForMediaTest('import_change_image_label_for_storeview.csv'); |
| 2823 | + $product = $this->getProductBySku($productSku); |
| 2824 | + $imageItems = $product->getMediaGalleryImages()->getItems(); |
| 2825 | + $this->assertCount(1, $imageItems); |
| 2826 | + $imageItem = array_shift($imageItems); |
| 2827 | + $this->assertEquals($expectedImageFile, $imageItem->getFile()); |
| 2828 | + $this->assertEquals($expectedLabelForDefaultStoreView, $imageItem->getLabel()); |
| 2829 | + $product = $this->getProductBySku($productSku, $secondStoreCode); |
| 2830 | + $imageItems = $product->getMediaGalleryImages()->getItems(); |
| 2831 | + $this->assertCount(1, $imageItems); |
| 2832 | + $imageItem = array_shift($imageItems); |
| 2833 | + $this->assertEquals($expectedImageFile, $imageItem->getFile()); |
| 2834 | + $this->assertEquals($expectedLabelForSecondStoreView, $imageItem->getLabel()); |
| 2835 | + } |
2776 | 2836 | }
|
0 commit comments