php - 如何在magento中的购物车页面上显示自定义图像

标签 php magento

我想在 Magento 的购物车页面上显示产品的自定义图像。

Config.xml文件

<checkout>
    <rewrite>
        <cart_item_renderer>ProductCustomizer_ProductCustomizer_Block_Checkout_Cart_Item_Renderer</cart_item_renderer>
    </rewrite>
</checkout>

我在Block/Checkout/Cart/Item/Renderer.php文件中添加了以下代码

<?php
class ProductCustomizer_ProductCustomizer_Block_Checkout_Cart_Item_Renderer extends Mage_Checkout_Block_Cart_Item_Renderer{

    public function getProductThumbnail()
    {
        $item = $this->_item;
        $customize_data = $item->getData('customize_data');
        $customize_image = $item->getData('customize_image');

        $results_data = $item->getOptionByCode("customizer_data")->getValue();
        if(!is_null($results_data)){
            $results = unserialize($results_data); 
            $path = Mage::getBaseDir()."/skin/";
            $_product = $item->getProduct()->load();
            $customize_image = $this->helper('catalog/image')->init($_product, 'thumbnail',$path.'adminhtml/default/default/images/logo.gif');

            //$customize_image = $this->helper('catalog/image')->init($_product, 'thumbnail',$results['image']);
        }

        if (!empty($customize_image)) {
            return $customize_image;
        } else {
            return parent::getProductThumbnail();
        }
    }
}

我已尝试使用图像$customize_image“URL”、“路径”和“数据(data:image/png;base64,iVBORw0KG ....)" 但它不起作用。

最佳答案

所以这就是我们的想法。您调用的 init 函数正在为您创建问题。执行类似的操作,因为您已经完成了该类的覆盖。

public function getProductThumbnail1()
    {
        if (!is_null($this->_productThumbnail)) {
            return $this->_productThumbnail;
        }
        return $this->getSkinUrl('images/jhonson.jpg');
        //return $this->helper('catalog/image')->init($this->getProduct(), 'thumbnail');
    }

在您已经覆盖的类中添加此函数,即 Mage_Checkout_Block_Cart_Item_Renderer。现在,在您的 app/design/frontend/rwd/default/template/checkout/cart/item/default.phtml 文件或任何文件中调用此函数,如下所示 echo $this-> getProductThumbnail1() 而不是这个 echo $this->getProductThumbnail()->resize(180)

关于php - 如何在magento中的购物车页面上显示自定义图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41424419/

相关文章:

magento - 在 Magento 中设置类别页面的默认模板

php - 为什么这两个对象相等(==)?

PHP mysql 查询两个表

email - 将附件添加到订单电子邮件 + Magento

java - 安卓 : create customer in magento via SOAP API

PHP/Magento - 缓存策略

PHP:使用 MySQL 数据库将区号与电话号码分开

php - php 按时间顺序按日和月对数组进行排序

php - 连接多个MySQL数据库,连接则加入Array,连接不上则跳过

Magento 管理 URL 不起作用 : 404 after changing it, 无法返回