1

please check attached snap-shot:

snap-shot

I am trying to Get image on shopping cart grid, but its showing no image, please check my code:

    ))->addColumn('image', array(
        'header'=> Mage::helper('catalog')->__('Image'),
        'type'  => 'image',
        'width' => '100px',
        'index' => 'image',

I have made changes in this file: app/code/core/Mage/Adminhtml/Block/Customer/Edit/Tab/View/Cart.php.

Please help.

  • First thing dont change in the core file always use rewrite concept of magento – Murtuza Zabuawala Sep 11 '16 at 9:29
  • How, Please Guide me.. How to Get Image.. – Kunwar Sunil chauhan Sep 11 '16 at 9:46
  • Hi have Put this code in end of the code, But image showing crack i means not showing image.. public function callback_image($value) { $width = 70; $height = 70; return "<img src='".Mage::getBaseUrl('media').'catalog/product'.$value."' width=".$width." height=".$height."/>"; } – Kunwar Sunil chauhan Sep 11 '16 at 10:09
  • can you provide me link or something – Murtuza Zabuawala Sep 11 '16 at 16:14
  • i am working in remote , can u pl give me code so i can change from my end. – Kunwar Sunil chauhan Sep 12 '16 at 17:14
0
  • Module in this case named Custom_MyModule, the code you need is in these files below.

app/etc/modules/Custom_MyModule.xml

<?xml version="1.0"?>
<config>
    <modules>
        <Custom_MyModule>
            <active>true</active>
            <codePool>local</codePool>
            <depends>
                <Mage_Adminhtml />
            </depends>
        </Custom_MyModule>
    </modules>
</config>

app/code/local/Custom/MyModule/etc/config.xml

<?xml version="1.0"?>
<config>
    <modules>
        <Custom_MyModule>
            <version>0.1.0</version>
        </Custom_MyModule>
    </modules>
    <adminhtml>
        <layout>
            <updates>
                <custom_mymodule>
                    <file>custom_layout.xml</file>
                </custom_mymodule>
            </updates>
        </layout>
    </adminhtml>
    <global>
        <blocks>
            <custom_mymodule>
                <class>Custom_MyModule_Block</class>
            </custom_mymodule>
        </blocks>
    </global>
</config>

app/design/adminhtml/default/default/layout/custom_layout.xml

<layout>
    <adminhtml_customer_viewcart>
        <reference name="admin.customer.view.cart">
            <action method="addColumnAfter">
                <columnId>image</columnId>
                <arguments>
                    <header>Image</header>
                    <type>text</type>
                    <renderer>custom_mymodule/adminhtml_renderer_image</renderer>
                </arguments>
                <after>sku</after>
            </action>
        </reference>
    </adminhtml_customer_viewcart>
</layout>

app/code/local/Custom/MyModule/Block/Adminhtml/Renderer/Image.php

<?php

class Custom_MyModule_Block_Adminhtml_Renderer_Image
    extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Abstract
{
    public function render(Varien_Object $row)
    {
        $productId = $row->getProductId();

        $product = Mage::getModel('catalog/product')->load($productId);
        if($product->getId()){
            $image = Mage::helper('catalog/image')->init($product, 'thumbnail')->resize(75);
            return
                '<img id="image_banner' . $product->getId() . '" src="' . $image . '" />';
        }else{
            return "";
        }
    }
}
  • After all, clear the caches and check it out.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.