Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/280.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何在magento中的购物车页面上显示自定义图像_Php_Magento - Fatal编程技术网

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

Php 如何在magento中的购物车页面上显示自定义图像,php,magento,Php,Magento,我想在Magento的购物车页面上显示产品的自定义图像 Config.xml文件 <checkout> <rewrite> <cart_item_renderer>ProductCustomizer_ProductCustomizer_Block_Checkout_Cart_Item_Renderer</cart_item_renderer> </rewrite> </checkout> &

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

Config.xml文件

<checkout>
    <rewrite>
        <cart_item_renderer>ProductCustomizer_ProductCustomizer_Block_Checkout_Cart_Item_Renderer</cart_item_renderer>
    </rewrite>
</checkout>
<?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();
        }
    }
}

产品定制器\u产品定制器\u块\u结帐\u购物车\u项目\u渲染器
我在Block/Checkout/Cart/Item/Renderer.php文件中添加了以下代码

<checkout>
    <rewrite>
        <cart_item_renderer>ProductCustomizer_ProductCustomizer_Block_Checkout_Cart_Item_Renderer</cart_item_renderer>
    </rewrite>
</checkout>
<?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();
        }
    }
}

所以这里是想法。您正在调用的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\u Checkout\u Block\u Cart\u Item\u Renderer
。现在,在你的
app/design/frontend/rwd/default/template/checkout/cart/item/default.phtml
文件或任何你的文件中,像这样调用这个函数
echo$this->getProductThumbnail1()
而不是这个
echo$this->getProductThumbnaila()->resize(180)
我找到了解决方案。你已经覆盖了核心类,我在下面添加了类

在自定义模块的帮助程序中创建帮助程序“Customezerimage.php

<?php
class ProductCustomizer_ProductCustomizer_Helper_Customezerimage extends Mage_Catalog_Helper_Image {
    public function setCustomeImage($path){
        $this->_imageFile = $path;
        $this->_setModel(Mage::getModel('productcustomizer/product_image'));
        $this->_getModel()->setCustomeBaseFile($this->_imageFile);
        return $this;
    }
    public function __toString() {
        try {
            $model = $this->_getModel();
            $url = $model->getUrl();
        } catch (Exception $e) {
            $url = Mage::getDesign()->getSkinUrl($this->getPlaceholder());
        }
        return $url;
    }
}

我正在开发扩展,因此无法在
应用程序/design/frontend/rwd/default/template/checkout/cart/item/default.phtml中进行更改。如果你还有别的办法,请告诉我。