Skip to content

Commit 3380da8

Browse files
author
cspruiell
committed
MAGETWO-69397: Hidden product images are not hidden from category listing or product view
- support custom placeholder images
1 parent 5d1590c commit 3380da8

File tree

2 files changed

+20
-8
lines changed

2 files changed

+20
-8
lines changed

app/code/Magento/Catalog/Block/Product/View/Gallery.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,9 +122,9 @@ public function getGalleryImagesJson()
122122
}
123123
if (empty($imagesItems)) {
124124
$imagesItems[] = [
125-
'thumb' => $this->getImage($this->getProduct(), 'product_thumbnail_image')->getImageUrl(),
126-
'img' => $this->getImage($this->getProduct(), 'product_base_image')->getImageUrl(),
127-
'full' => $this->getImage($this->getProduct(), 'product_page_image_large')->getImageUrl(),
125+
'thumb' => $this->_imageHelper->getDefaultPlaceholderUrl('thumbnail'),
126+
'img' => $this->_imageHelper->getDefaultPlaceholderUrl('image'),
127+
'full' => $this->_imageHelper->getDefaultPlaceholderUrl('image'),
128128
'caption' => '',
129129
'position' => '0',
130130
'isMain' => true,

app/code/Magento/Catalog/Helper/Image.php

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
namespace Magento\Catalog\Helper;
77

88
use Magento\Framework\App\Helper\AbstractHelper;
9+
use Magento\Framework\App\ObjectManager;
910

1011
/**
1112
* Catalog image helper
@@ -126,22 +127,31 @@ class Image extends AbstractHelper
126127
*/
127128
protected $attributes = [];
128129

130+
/**
131+
* @var \Magento\Catalog\Model\View\Asset\PlaceholderFactory
132+
*/
133+
private $viewAssetPlaceholderFactory;
134+
129135
/**
130136
* @param \Magento\Framework\App\Helper\Context $context
131137
* @param \Magento\Catalog\Model\Product\ImageFactory $productImageFactory
132138
* @param \Magento\Framework\View\Asset\Repository $assetRepo
133139
* @param \Magento\Framework\View\ConfigInterface $viewConfig
140+
* @param \Magento\Catalog\Model\View\Asset\PlaceholderFactory $placeholderFactory
134141
*/
135142
public function __construct(
136143
\Magento\Framework\App\Helper\Context $context,
137144
\Magento\Catalog\Model\Product\ImageFactory $productImageFactory,
138145
\Magento\Framework\View\Asset\Repository $assetRepo,
139-
\Magento\Framework\View\ConfigInterface $viewConfig
146+
\Magento\Framework\View\ConfigInterface $viewConfig,
147+
\Magento\Catalog\Model\View\Asset\PlaceholderFactory $placeholderFactory = null
140148
) {
141149
$this->_productImageFactory = $productImageFactory;
142150
parent::__construct($context);
143151
$this->_assetRepo = $assetRepo;
144152
$this->viewConfig = $viewConfig;
153+
$this->viewAssetPlaceholderFactory = $placeholderFactory ?:
154+
ObjectManager::getInstance()->get(\Magento\Catalog\Model\View\Asset\PlaceholderFactory::class);
145155
}
146156

147157
/**
@@ -544,14 +554,16 @@ public function getResizedImageInfo()
544554
/**
545555
* @param null|string $placeholder
546556
* @return string
547-
*
548-
* @deprecated Returns only default placeholder.
549-
* Does not take into account custom placeholders set in Configuration.
550557
*/
551558
public function getDefaultPlaceholderUrl($placeholder = null)
552559
{
553560
try {
554-
$url = $this->_assetRepo->getUrl($this->getPlaceholder($placeholder));
561+
$imageAsset = $this->viewAssetPlaceholderFactory->create(
562+
[
563+
'type' => $placeholder ?: $this->_getModel()->getDestinationSubdir(),
564+
]
565+
);
566+
$url = $imageAsset->getUrl();
555567
} catch (\Exception $e) {
556568
$this->_logger->critical($e);
557569
$url = $this->_urlBuilder->getUrl('', ['_direct' => 'core/index/notFound']);

0 commit comments

Comments
 (0)