-
Notifications
You must be signed in to change notification settings - Fork 9.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ENGCOM-4258: [BugFix] Fix area for image placeholder in graphql respo…
…nse. #364
- Loading branch information
Showing
4 changed files
with
162 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
app/code/Magento/CatalogGraphQl/Model/Resolver/Products/DataProvider/Image/Placeholder.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Magento\CatalogGraphQl\Model\Resolver\Products\DataProvider\Image; | ||
|
||
use Magento\Catalog\Model\View\Asset\PlaceholderFactory; | ||
use Magento\Framework\View\Asset\Repository as AssetRepository; | ||
|
||
/** | ||
* Image Placeholder provider | ||
*/ | ||
class Placeholder | ||
{ | ||
/** | ||
* @var PlaceholderFactory | ||
*/ | ||
private $placeholderFactory; | ||
|
||
/** | ||
* @var AssetRepository | ||
*/ | ||
private $assetRepository; | ||
|
||
/** | ||
* @param PlaceholderFactory $placeholderFactory | ||
* @param AssetRepository $assetRepository | ||
*/ | ||
public function __construct( | ||
PlaceholderFactory $placeholderFactory, | ||
AssetRepository $assetRepository | ||
) { | ||
$this->placeholderFactory = $placeholderFactory; | ||
$this->assetRepository = $assetRepository; | ||
} | ||
|
||
/** | ||
* Get placeholder | ||
* | ||
* @param string $imageType | ||
* @return string | ||
*/ | ||
public function getPlaceholder(string $imageType): string | ||
{ | ||
$imageAsset = $this->placeholderFactory->create(['type' => $imageType]); | ||
|
||
// check if placeholder defined in config | ||
if ($imageAsset->getFilePath()) { | ||
return $imageAsset->getUrl(); | ||
} | ||
|
||
return $this->assetRepository->getUrl( | ||
"Magento_Catalog::images/product/placeholder/{$imageType}.jpg" | ||
); | ||
} | ||
} |
71 changes: 71 additions & 0 deletions
71
...e/Magento/CatalogGraphQl/Model/Resolver/Products/DataProvider/Image/Placeholder/Theme.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
<?php | ||
/** | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
declare(strict_types=1); | ||
|
||
namespace Magento\CatalogGraphQl\Model\Resolver\Products\DataProvider\Image\Placeholder; | ||
|
||
use Magento\Framework\App\Config\ScopeConfigInterface; | ||
use Magento\Framework\View\Design\Theme\ThemeProviderInterface; | ||
use Magento\Store\Model\StoreManagerInterface; | ||
|
||
/** | ||
* Theme provider | ||
*/ | ||
class Theme | ||
{ | ||
/** | ||
* @var ScopeConfigInterface | ||
*/ | ||
private $scopeConfig; | ||
|
||
/** | ||
* @var StoreManagerInterface | ||
*/ | ||
private $storeManager; | ||
|
||
/** | ||
* @var ThemeProviderInterface | ||
*/ | ||
private $themeProvider; | ||
|
||
/** | ||
* @param ScopeConfigInterface $scopeConfig | ||
* @param StoreManagerInterface $storeManager | ||
* @param ThemeProviderInterface $themeProvider | ||
*/ | ||
public function __construct( | ||
ScopeConfigInterface $scopeConfig, | ||
StoreManagerInterface $storeManager, | ||
ThemeProviderInterface $themeProvider | ||
) { | ||
$this->scopeConfig = $scopeConfig; | ||
$this->storeManager = $storeManager; | ||
$this->themeProvider = $themeProvider; | ||
} | ||
|
||
/** | ||
* Get theme model | ||
* | ||
* @return array | ||
* @throws \Magento\Framework\Exception\NoSuchEntityException | ||
*/ | ||
public function getThemeData(): array | ||
{ | ||
$themeId = $this->scopeConfig->getValue( | ||
\Magento\Framework\View\DesignInterface::XML_PATH_THEME_ID, | ||
\Magento\Store\Model\ScopeInterface::SCOPE_STORE, | ||
$this->storeManager->getStore()->getId() | ||
); | ||
|
||
/** @var $theme \Magento\Framework\View\Design\ThemeInterface */ | ||
$theme = $this->themeProvider->getThemeById($themeId); | ||
|
||
$data = $theme->getData(); | ||
$data['themeModel'] = $theme; | ||
|
||
return $data; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters