本文整理汇总了PHP中Magento\Catalog\Api\Data\ProductInterface::getMediaGalleryImages方法的典型用法代码示例。如果您正苦于以下问题:PHP ProductInterface::getMediaGalleryImages方法的具体用法?PHP ProductInterface::getMediaGalleryImages怎么用?PHP ProductInterface::getMediaGalleryImages使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Magento\Catalog\Api\Data\ProductInterface
的用法示例。
在下文中一共展示了ProductInterface::getMediaGalleryImages方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getGalleryImages
/**
* Retrieve collection of gallery images
*
* @param \Magento\Catalog\Api\Data\ProductInterface $product
* @return \Magento\Catalog\Model\Product\Image[]|null
*/
public function getGalleryImages(\Magento\Catalog\Api\Data\ProductInterface $product)
{
$images = $product->getMediaGalleryImages();
if ($images instanceof \Magento\Framework\Data\Collection) {
foreach ($images as $image) {
/** @var $image \Magento\Catalog\Model\Product\Image */
$image->setData('small_image_url', $this->imageHelper->init($product, 'product_page_image_small')->setImageFile($image->getFile())->getUrl());
$image->setData('medium_image_url', $this->imageHelper->init($product, 'product_page_image_medium')->constrainOnly(true)->keepAspectRatio(true)->keepFrame(false)->setImageFile($image->getFile())->getUrl());
$image->setData('large_image_url', $this->imageHelper->init($product, 'product_page_image_large')->constrainOnly(true)->keepAspectRatio(true)->keepFrame(false)->setImageFile($image->getFile())->getUrl());
}
}
return $images;
}
示例2: getGalleryImages
/**
* @param Product $product
* @return array
*/
protected function getGalleryImages(Product $product)
{
$result = [];
$mediaGallery = $product->getMediaGalleryImages();
if ($mediaGallery instanceof \Magento\Framework\Data\Collection) {
foreach ($mediaGallery as $media) {
$result[$media->getData('value_id')] = $this->getAllSizeImages($product, $media->getData('file'));
}
}
return $result;
}