Skip to content

Commit f41eb3e

Browse files
committed
Use current store id instead of admin store id
1 parent ca13aa8 commit f41eb3e

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

app/code/Magento/CatalogGraphQl/Model/Resolver/Product/SmallImageUrl.php

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
use Magento\Framework\GraphQl\Query\Resolver\ValueFactory;
1818
use Magento\Framework\GraphQl\Query\ResolverInterface;
1919
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
20-
use Magento\Store\Model\Store;
20+
use Magento\Store\Model\StoreManagerInterface;
2121

2222
/**
2323
* Returns product's small image. If the small image is not set, returns a placeholder
@@ -44,22 +44,30 @@ class SmallImageUrl implements ResolverInterface
4444
*/
4545
private $valueFactory;
4646

47+
/**
48+
* @var StoreManagerInterface
49+
*/
50+
private $storeManager;
51+
4752
/**
4853
* @param ValueFactory $valueFactory
4954
* @param CatalogImageHelper $catalogImageHelper
5055
* @param AreaList $areaList
5156
* @param GalleryResourceFactory $galleryResourceFactory
57+
* @param StoreManagerInterface $storeManager
5258
*/
5359
public function __construct(
5460
ValueFactory $valueFactory,
5561
CatalogImageHelper $catalogImageHelper,
5662
AreaList $areaList,
57-
GalleryResourceFactory $galleryResourceFactory
63+
GalleryResourceFactory $galleryResourceFactory,
64+
StoreManagerInterface $storeManager
5865
) {
5966
$this->valueFactory = $valueFactory;
6067
$this->catalogImageHelper = $catalogImageHelper;
6168
$this->areaList = $areaList;
6269
$this->galleryResourceFactory = $galleryResourceFactory;
70+
$this->storeManager = $storeManager;
6371
}
6472

6573
/**
@@ -84,7 +92,8 @@ public function resolve(
8492
/* If small_image is not loaded for product, need to load it separately */
8593
if (!$product->getSmallImage()) {
8694
$galleryResource = $this->galleryResourceFactory->create();
87-
$productImages = $galleryResource->getProductImages($product, [Store::DEFAULT_STORE_ID]);
95+
$currentStoreId =$this->storeManager->getStore()->getId();
96+
$productImages = $galleryResource->getProductImages($product, [$currentStoreId]);
8897
$productSmallImage = $this->getSmallImageFromGallery($productImages);
8998
$product->setSmallImage($productSmallImage);
9099
}

0 commit comments

Comments
 (0)