[英]How to add external image in magento2 pdp
How can we add an external image for magento2 product detail page(not from the magento2 backend).我们如何为 magento2 产品详细信息页面添加外部图像(不是来自 magento2 后端)。 I tried some stuff in the galley.phtml but not succeed.
我在galley.phtml 中尝试了一些东西,但没有成功。 Is there anybody who can fix this, help me please.
有没有人可以解决这个问题,请帮助我。
Uploading the product image in Magento 2 via the code snippet is a helpful article for the developers.通过代码片段上传Magento 2 中的产品图片对开发人员很有帮助。
Here is a snippet:这是一个片段:
use Magento\Framework\App\Filesystem\DirectoryList;
use Magento\Backend\App\Action;
protected $_fileUploaderFactory;
public function __construct(
\Magento\MediaStorage\Model\File\UploaderFactory $fileUploaderFactory,
Action\Context $context
) {
$this->_fileUploaderFactory = $fileUploaderFactory;
parent::__construct($context);
}
public function execute(){
$uploader = $this->_fileUploaderFactory->create(['fileId' => 'image']);
$uploader->setAllowedExtensions(['jpg', 'jpeg', 'gif', 'png']);
$uploader->setAllowRenameFiles(false);
$uploader->setFilesDispersion(false);
$path = $this->_filesystem->getDirectoryRead(DirectoryList::MEDIA)
->getAbsolutePath('images/');
$uploader->save($path);
}
add this code to gallery.phtml将此代码添加到 gallery.phtml
<script>
require(['jquery'], function ($) {
$(document).on('gallery:loaded', function () {
var $fotorama = jQuery('div.gallery-placeholder > div.fotorama');
var fotorama = $fotorama.data('fotorama');
$fotorama.on('fotorama:load', function fotorama_onLoad(e, fotorama, extra) {
if (extra.frame.type === 'iframe') {
extra.frame.$stageFrame.html('<iframe align="middle" type="text/html" width="100%" height="100%" src="' + extra.frame.src + '" frameborder="0" scrolling="no" allowfullscreen webkitallowfullscreen mozallowfullscreen oallowfullscreen msallowfullscreen></iframe>');
}
});
fotorama.push({
thumb: '<set your thumbnail image path>',
'src': '<set your image/video url>',
type: 'iframe',
caption: '<set your caption>'
});
});
});
</script>
this fix my requirement.这解决了我的要求。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.