【问题标题】:Magento custom Upsell image not showingMagento 自定义加售图像未显示
【发布时间】:2015-06-17 16:12:28
【问题描述】:

我有一个问题,我无法将名为 upsell 的自定义属性显示为我的追加销售图片。

属性信息
属性代码:加售
范围:商店视图
目录输入类型店主: 媒体图片
适用于: 所有产品类型

我在skin/frontend/.../images/catalog/product/placeholder/中创建了缩略图

这是显示图像的代码

<img src="<?php echo $this->helper('catalog/image')->init($_item, 'upsell')->constrainOnly(FALSE)->keepAspectRatio(TRUE)->keepFrame(FALSE)->resize(150); ?>" alt="<?php echo $this->htmlEscape($_item->getName()) ?>" />

如果我将 ($_item, 'upsell') 更改为 ($_item, 'thumbnail'),它会显示正确的缩略图。

我在创建属性的过程中是否遗漏了什么?

【问题讨论】:

  • 确保该属性在前端的产品视图页面上可见
  • 我如何确保它是 :)?
  • 如果我 var_dump 产品没有价值(就像图像、缩略图等一样)
  • templatemonster.com/help/… 最重要的选项是Visible on Catalog Pages on Front-end 您是否为此选项选择了yes?您是否启用了 lat 目录?
  • 因为它是一个图像,我没有选择“前端目录页面上可见的选项。不确定你所说的 lat 目录是什么意思?

标签: php magento e-commerce magento-1.9.1


【解决方案1】:

ay要调用图像,您可以使用: $this->helper('catalog/image')->init($_product, 'product_details_image')->resize()

完整的脚本是:

<?php
$_detailsImg = $this->helper('catalog/image')->init($_product,'product_details_image')->resize(); 

if ($_detailsImg != 'no_selection'):
    $_detailsImg ='<img src="'.$this->helper('catalog/image')->init($_product, 'product_details_image')->resize().'" alt="'.$this->htmlEscape($this->getImageLabel()).' "/>';
    echo $_helper->productAttribute($_product, $_detailsImg , 'product_details_image');
endif;

?>

请将 product_details_image 更改为您的属性图像代码。

如果您没有为产品分配图像,您将收到此错误:找不到图像文件。在(var/报告) 因此,要解决此问题,请创建一个与属性代码 (product_details_image.jpg) 同名的图像作为占位符并将其添加到: 皮肤/前端/基础/默认/图像/目录/产品/占位符/ 您也可以将其添加到您的皮肤文件夹中。这就对了。

编辑:

我会再次重写 upsell.phtml,让所有 id 将其添加到数组调用产品集合中,按 id 过滤,然后您就可以调用包括媒体图像在内的任何属性 - 我可以确认这对我有用

编辑:

这听起来可能很愚蠢,但我找不到其他方法,我必须为每个产品加载集合,希望有人能找到其他方法。

我确实尝试调用一个集合并使用产品 ID(追加销售产品 ID)对其进行过滤,但它不起作用。

<?php if(count($this->getItemCollection()->getItems())): 
    $items = $this->getItemCollection()->getItems();
    ?>
<div class="box-up-sell">
    <ul class="products-grid up-sell-grid">
        <?php foreach ($items as $item):  ?>
            <li class="item">
                <?php $product = Mage::getModel('catalog/product')->load($item->getId()); ?>
                <span><?php echo $product->getName(); ?></span>
                <img src="<?php echo Mage::helper('catalog/image')->init($product, 'measurements_guide_image')->resize(200, 200); ?>" alt="">
            </li>
        <?php endforeach ?>
    </ul>
</div>
<?php endif ?>

【讨论】:

  • 我的问题是我做的和你提供的一样,但它仍然没有显示在我的前端,它显示的是我的缩略图而不是在后台/管理面板上选择的图像
  • $_detailsImg 指的是什么?
  • 你可以这样使用:$_product = Mage::getModel('catalog/product')->load($_link->getId()); echo $_product->getMeasurementsGuideImage();
  • 我已经有了模型对象,但是图像没有返回任何东西给我:(
  • 今晚我会做并发送过来
【解决方案2】:

您需要将此媒体属性添加到产品平面设置中:

    <frontend>
    <product>
        <collection>
            <attributes>
                  <upsell/>
            </attributes>
        </collection>
    </product>
</frontend>

在我的模块 config.xml 中的这段代码,然后你需要从索引管理中重新索引。

【讨论】:

  • 它没有显示图像,它仍然显示默认图像。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-03-20
相关资源
最近更新 更多