我们的使命

助力跨境卖家高效建立全球销售网络

喜报2021年我司获《江苏省国家高新技术企业》认定

分类目录

文章标签

热门推荐

相关咨讯

opencart外观,magento图片路径

2022-10-24 15:26:43 - 米境通跨境电商



    MagentoProductImagesFullURLPathInsteadofCached

    下面的代码适用于具有图像的产品,但是对于没有图像的产品,占位符小图像不会显示。

    echoMage::getModel('catalog/product_media_config')->getMediaUrl($_product->getSmallImage());

    相关讨论

    1

    2

    3

    4

    5

    6

    7

    8

    9

   
    //getimagefullurl

    echo$imageUrl=Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA).'catalog/product'.$_product->getImage();

    //getimageusingcustomsizewithurl

    echo$imageCacheUrl=Mage::helper('catalog/image')->init($_product,'image')->resize(135,135);

    ?>

    相关讨论

    影响您要执行的操作的代码是

    1

    2

    3

    4

    5

    6

    7

    8

    9

    10

    11

    12

    13

    14

    15

    16

    //file:app/code/core/Mag/Catalog/Helper/Image.php

    //class:Mage_Catalog_Helper_Image

    /**

    *ReturnImageURL

    *

    *@returnstring

    */

    publicfunction__toString()

    {

    try{

    //...

    }catch(Exception$e){

    $url=Mage::getDesign()->getSkinUrl($this->getPlaceholder());

    }

    return$url;

    }

    有趣的一行是

    1

    $url=Mage::getDesign()->getSkinUrl($this->getPlaceholder());

    因此在您的代码中,您需要测试$_product->getSmallImage()的返回值,如果它为false或null,请改用Mage::getDesign()->getSkinUrl($this->getPlaceholder());。

    您可能希望检查$_product->getSmallImage()以查看未设置任何值时返回的内容。

    哦,我刚刚检查了一下:getPlaceholder()是一个函数,不是一个神奇的吸气剂。这是函数:

    1

    2

    3

    4

    5

    6

    7

    8

    publicfunctiongetPlaceholder()

    {

    if(!$this->_placeholder){

    $attr=$this->_getModel()->getDestinationSubdir();

    $this->_placeholder='images/catalog/product/placeholder/'.$attr.'.jpg';

    }

    return$this->_placeholder;

    }

    所以您将不得不解开一些$this(提示$this->_getModel()是Mage::getModel('catalog/product_image'))

    或者简而言之,只是回到默认值:

    echo($this->helper('catalog/image')->init($_product,'small_image'));

    如果$_product->getSmallImage()不存在,则在您的phtml文件中为

    。

    根据您的评论进行更新:

    特别是在用于生成显示可写小图像的HTML的.phtml文件中:

    1

    2

    3

    4

    5

    6

    7

    8

    9

    $testSmallImageExists=$_product->getSmallImage();

    if($testSmallImageExists)

    {

    echoMage::getModel('catalog/product_media_config')->getMediaUrl($_product->getSmallImage());

    }

    else

    {

    echo($this->helper('catalog/image')->init($_product,'small_image'));

    }
    联系我们
  • 24H客服
  • 联系电话:16651690460(龙经理)
  • 微信咨询:
南京天遥路联网络科技有限公司,版权所有 Copyright By ©米境通ERP4.0,2015-2025,苏ICP备:苏ICP备15044100号-4, 苏公网安备:32011402011043