1

I have created a custom image media type "custom" using this tutorial:

http://www.pixafy.com/blog/2012/12/adding-a-fourth-image-position-to-the-admin-for-a-magento-product/

Currently magento shows thumbnail image type on shopping cart page but I want custom type image on the page. How can I do this?

I have tried this:

    /magento/app/design/frontend/rwd/default/template/checkout/cart/item/default.phtml

 <img src="<?php echo $this->getProductCustom()->resize(180); ?>" alt="<?php echo $this->escapeHtml($this->getProductName()) ?>" />

after trying Siarhey Uchukhlebau's answer:

<img src="<?php echo $this->helper('catalog/image')->init($_item->getProduct(), 'custom')->resize(180);?>" alt="<?php echo $this->escapeHtml($this->getProductName()) ?>" />

I got this error:

Image file was not found.

Trace:
#0 /var/www/html/magento/app/code/core/Mage/Catalog/Helper/Image.php(166): Mage_Catalog_Model_Product_Image->setBaseFile(NULL)
#1 /var/www/html/magento/app/design/frontend/rwd/default/template/checkout/cart/item/default.phtml(38): Mage_Catalog_Helper_Image->init(Object(Mage_Catalog_Model_Product), 'custom')
#2 /var/www/html/magento/app/code/core/Mage/Core/Block/Template.php(241): include('/var/www/html/m...')
#3 /var/www/html/magento/app/code/core/Mage/Core/Block/Template.php(272): Mage_Core_Block_Template->fetchView('frontend/rwd/de...')
#4 /var/www/html/magento/app/code/core/Mage/Core/Block/Template.php(286): Mage_Core_Block_Template->renderView()
#5 /var/www/html/magento/app/code/core/Mage/Core/Block/Abstract.php(919): Mage_Core_Block_Template->_toHtml()
#6 /var/www/html/magento/app/code/core/Mage/Checkout/Block/Cart/Abstract.php(174): Mage_Core_Block_Abstract->toHtml()
#7 /var/www/html/magento/app/design/frontend/rwd/default/template/checkout/cart.phtml(147): Mage_Checkout_Block_Cart_Abstract->getItemHtml(Object(Mage_Sales_Model_Quote_Item))
#8 /var/www/html/magento/app/code/core/Mage/Core/Block/Template.php(241): include('/var/www/html/m...')
#9 /var/www/html/magento/app/code/core/Mage/Core/Block/Template.php(272): Mage_Core_Block_Template->fetchView('frontend/rwd/de...')
#10 /var/www/html/magento/app/code/core/Mage/Core/Block/Template.php(286): Mage_Core_Block_Template->renderView()
#11 /var/www/html/magento/app/code/core/Mage/Core/Block/Abstract.php(919): Mage_Core_Block_Template->_toHtml()
#12 /var/www/html/magento/app/code/core/Mage/Core/Block/Text/List.php(43): Mage_Core_Block_Abstract->toHtml()
#13 /var/www/html/magento/app/code/core/Mage/Core/Block/Abstract.php(919): Mage_Core_Block_Text_List->_toHtml()
#14 /var/www/html/magento/app/code/core/Mage/Core/Block/Abstract.php(637): Mage_Core_Block_Abstract->toHtml()
#15 /var/www/html/magento/app/code/core/Mage/Core/Block/Abstract.php(581): Mage_Core_Block_Abstract->_getChildHtml('content', true)
#16 /var/www/html/magento/app/design/frontend/rwd/default/template/page/1column.phtml(55): Mage_Core_Block_Abstract->getChildHtml('content')
#17 /var/www/html/magento/app/code/core/Mage/Core/Block/Template.php(241): include('/var/www/html/m...')
#18 /var/www/html/magento/app/code/core/Mage/Core/Block/Template.php(272): Mage_Core_Block_Template->fetchView('frontend/rwd/de...')
#19 /var/www/html/magento/app/code/core/Mage/Core/Block/Template.php(286): Mage_Core_Block_Template->renderView()
#20 /var/www/html/magento/app/code/core/Mage/Core/Block/Abstract.php(919): Mage_Core_Block_Template->_toHtml()
#21 /var/www/html/magento/app/code/core/Mage/Core/Model/Layout.php(555): Mage_Core_Block_Abstract->toHtml()
#22 /var/www/html/magento/app/code/core/Mage/Core/Controller/Varien/Action.php(390): Mage_Core_Model_Layout->getOutput()
#23 /var/www/html/magento/app/code/core/Mage/Checkout/controllers/CartController.php(181): Mage_Core_Controller_Varien_Action->renderLayout()
#24 /var/www/html/magento/app/code/core/Mage/Core/Controller/Varien/Action.php(418): Mage_Checkout_CartController->indexAction()
#25 /var/www/html/magento/app/code/core/Mage/Core/Controller/Varien/Router/Standard.php(254): Mage_Core_Controller_Varien_Action->dispatch('index')
#26 /var/www/html/magento/app/code/core/Mage/Core/Controller/Varien/Front.php(172): Mage_Core_Controller_Varien_Router_Standard->match(Object(Mage_Core_Controller_Request_Http))
#27 /var/www/html/magento/app/code/core/Mage/Core/Model/App.php(365): Mage_Core_Controller_Varien_Front->dispatch()
#28 /var/www/html/magento/app/Mage.php(684): Mage_Core_Model_App->run(Array)
#29 /var/www/html/magento/index.php(83): Mage::run('', 'store')
#30 {main}

after this I set up place holder image for this custom attribute from this path:

System -> Configuration -> Catalog -> Product Image Placeholders

and now I am getting the place holder image but not the actual image that I selected as "custom"

1 Answer 1

4

Load product by id (from quote item):

$_product = Mage::getModel('catalog/product')->load($_item->getProductId());

get custom image from loaded product:

<img src="<?php echo $this->helper('catalog/image')->init($_product, 'product_custom')->resize(180);?>" alt="<?php echo $this->escapeHtml($this->getProductName()) ?>" />

The issue was that the product initially had no your custom attribute, this is the reason why it could not display it. Product conf In Cart

7
  • I have tried your code but getting error. I have used "product_custom" and "custom" but no one is working for me. error: There has been an error processing your request Exception printing is disabled by default for security reasons. Error log record number: 513180672 Mar 25, 2016 at 10:33
  • please show content of the var/report/513180672 file here Mar 25, 2016 at 10:44
  • @UchukhlebauI have added the error message in my post. Mar 25, 2016 at 11:31
  • @UchukhlebauI I have updated my post. Mar 25, 2016 at 11:48
  • 1
    This code works properly on this page at my side gyazo.com/a4d1bea807028942c87528b69fd2341a Mar 25, 2016 at 13:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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