9

I have Magento CE 1.9.2.4 installed along with patches (5377,1533,4788 etc. almost all patches).

This question also reveals issues that may/surely occur in any custom module involving Image uploads in their custom sections, rather than just core magento issues.

  1. Now after I installed the latest patch 8788 through command-line, I am not able to open "Add/Edit" page of my custom module, which was working fine prior to 8788 installation.

I am getting below error when I try to open the "Add New Banner" page of my module:

Fatal error: Call to a member function setUrl() on a non-object in /home/site_user/public_html/app/code/community/My/Module/Block/Adminhtml/Banner/Add/Tab/Image.php on line 57

The culprit line is as below:

$this->getUploader()->getConfig()->setUrl(Mage::getModel('adminhtml/url')->addSessionParam()->getUrl('*/*/image'))
  1. Also I cannot see already uploaded product images in admin Catalog > Manage Products > Any product > Images section.

Below is the core Mage_Adminhtml_Block_Media_Uploader class being called.

<?php
/**
 * Magento
 *
 * NOTICE OF LICENSE
 *
 * This source file is subject to the Open Software License (OSL 3.0)
 * that is bundled with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://opensource.org/licenses/osl-3.0.php
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to [email protected] so we can send you a copy immediately.
 *
 * DISCLAIMER
 *
 * Do not edit or add to this file if you wish to upgrade Magento to newer
 * versions in the future. If you wish to customize Magento for your
 * needs please refer to http://www.magento.com for more information.
 *
 * @category    Mage
 * @package     Mage_Adminhtml
 * @copyright  Copyright (c) 2006-2016 X.commerce, Inc. and affiliates (http://www.magento.com)
 * @license    http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
 */

/**
 * Adminhtml media library uploader
 *
 * @category   Mage
 * @package    Mage_Adminhtml
 * @author      Magento Core Team <[email protected]>
 */

/**
 * @deprecated
 * Class Mage_Adminhtml_Block_Media_Uploader
 */
class Mage_Adminhtml_Block_Media_Uploader extends Mage_Uploader_Block_Multiple
{
    /**
     * Constructor for uploader block
     */
    public function __construct()
    {
        parent::__construct();
        $this->getUploaderConfig()->setTarget(Mage::getModel('adminhtml/url')->addSessionParam()->getUrl('*/*/upload'));
        $this->getUploaderConfig()->setFileParameterName('file');
    }
}

Anyone let me know how to fix this with least code changes as possible.

13

4 Answers 4

17

Mage_Adminhtml_Block_Media_Uploader is deprecated on after SUPEE-8788 (and 1.9.3). Thus there are several backward incompatibility changes which breaks module using the uploader.

I first thought a small change would fix it but there's actually way more to do.

Make a module using the gallery compatible with 1.9.2 and 1.9.3

So if you're a module provider, you don't want to have two different versions of your module for 1.9.2 and 1.9.3. Here's how to make your code compatible with both:

In your block _prepareLayout method you need to do the following:

Replace:

 $this->getUploader()->getConfig()
            ->setUrl($url)
            ->setFileField('image')
            ->setFilters(array(
                'images' => array(
                    'label' => Mage::helper('adminhtml')->__('Images (.gif, .jpg, .png)'),
                    'files' => array('*.gif', '*.jpg','*.jpeg', '*.png')
                )
            ));

With:

    if (class_exists("Mage_Uploader_Block_Abstract")) {
        // PATCH SUPEE-8788 or Magento 1.9.3
        $this->getUploader()->getUploaderConfig()
            ->setFileParameterName('image')
            ->setTarget($url);

        $browseConfig = $this->getUploader()->getButtonConfig();
        $browseConfig
            ->setAttributes(
                array("accept"  =>  $browseConfig->getMimeTypesByExtensions('gif, png, jpeg, jpg'))
            );
    } else {
        $this->getUploader()->getConfig()
            ->setUrl($url)
            ->setFileField('image')
            ->setFilters(array(
                'images' => array(
                    'label' => Mage::helper('adminhtml')->__('Images (.gif, .jpg, .png)'),
                    'files' => array('*.gif', '*.jpg','*.jpeg', '*.png')
                )
            ));
    }

As you can see I'm using class_exists to check whether SUPEE-8788 or Magento 1.9.3 is applied.

Then in your gallery.phtml you need to replace:

var <?php echo $_block->getJsObjectName(); ?> = new Product.Gallery('<?php echo $_block->getHtmlId() ?>', <?php if ($_block->getElement()->getReadonly()):?>null<?php else:?><?php echo $_block->getUploader()->getJsObjectName() ?><?php endif;?>, <?php echo $_block->getImageTypesJson() ?>);

With:

<?php if (class_exists("Mage_Uploader_Block_Abstract")): ?>
    var <?php echo $_block->getJsObjectName(); ?> = new Product.Gallery('<?php echo $_block->getHtmlId() ?>', <?php echo $_block->getImageTypesJson() ?>);
<?php else: ?>
    var <?php echo $_block->getJsObjectName(); ?> = new Product.Gallery('<?php echo $_block->getHtmlId() ?>', <?php if ($_block->getElement()->getReadonly()):?>null<?php else:?><?php echo $_block->getUploader()->getJsObjectName() ?><?php endif;?>, <?php echo $_block->getImageTypesJson() ?>);
<?php endif; ?>

Then for the layout file, you can do it like this:

<reference name="head">
    <action method="addJs"><file helper="module/getFlowMin" /></action>
    <action method="addJs"><file helper="module/getFustyFlow" /></action>
    <action method="addJs"><file helper="module/getFustyFlowFactory" /></action>
    <action method="addJs"><file helper="module/getAdminhtmlUploaderInstance" /></action>
</reference>

Replace module with your helper class identifier and in your module Data.php helper add the following:

protected function _isNoFlashUploader()
{
    return class_exists("Mage_Uploader_Block_Abstract");
}

public function getFlowMin()
{
    return $this->_isNoFlashUploader() ? "lib/uploader/flow.min.js" : null;
}

public function getFustyFlow()
{
    return $this->_isNoFlashUploader() ? "lib/uploader/fusty-flow.js" : null;
}

public function getFustyFlowFactory()
{
    return $this->_isNoFlashUploader() ? "lib/uploader/fusty-flow-factory.js" : null;
}

public function getAdminhtmlUploaderInstance()
{
    return $this->_isNoFlashUploader() ? "mage/adminhtml/uploader/instance.js" : null;
}
2
  • 1
    also setUrl change with setTarget. Oct 21, 2016 at 12:00
  • It works for csv file upload issue on Magento 1.9.3.8. Great! May 17, 2018 at 4:29
3

adding in @Raphael answer you need to add three fixes

first fix

Spacename_Moduelname_Block_Adminhtml_Modulename_Edit_Tab_Images.php

protected $_uploaderType = 'uploader/multiple';
public function __construct()
{
    parent::__construct();
    $this->setTemplate('moduelname/gallery.phtml');
    ....
}
protected function _prepareLayout()
    {
 $this->setChild('uploader',
            $this->getLayout()->createBlock($this->_uploaderType)
        );

        $this->getUploader()->getUploaderConfig()
            ->setFileParameterName('image')
            ->setTarget(Mage::getModel('adminhtml/url')->addSessionParam()->getUrl('*/*/image'));

        $browseConfig = $this->getUploader()->getButtonConfig();
        $browseConfig
            ->setAttributes(array(
                'accept' => $browseConfig->getMimeTypesByExtensions('gif, png, jpeg, jpg')
            ));
     return parent::_prepareLayout();
    }

Second fix in adminhtml/default/default/modulename/gallery.phtml file

 <script type="text/javascript">
//<![CDATA[
var <?php echo $_block->getJsObjectName(); ?> = new Product.Gallery('<?php echo $_block->getHtmlId() ?>', <?php echo $_block->getImageTypesJson() ?>);
//]]>
</script>

third fix the js part layout/module.xml

<reference name="head">
            <action method="addJs"><file>lib/uploader/flow.min.js</file></action>
            <action method="addJs"><file>lib/uploader/fusty-flow.js</file></action>
            <action method="addJs"><file>lib/uploader/fusty-flow-factory.js</file></action>
            <action method="addJs"><file>mage/adminhtml/uploader/instance.js</file></action>
</reference>

files to fixes loaction

first fix app/code/core/Mage/Adminhtml/Block/Catalog/Product/Helper/Form/Gallery/Content.php

second fix app/design/adminhtml/default/default/template/catalog/product/helper/gallery.phtml

17
  • It would be really helpful, if you mention the files for fixes too.
    – Vicky Dev
    Oct 21, 2016 at 11:21
  • @VickyDev added the filename too. Oct 21, 2016 at 11:24
  • Thanks, for you answer, but this thing occurs in Core Magento product images, so where do I need to make the first two changes ? Magento ce 1.9.2.4 with patch 8788 installed.
    – Vicky Dev
    Oct 21, 2016 at 11:38
  • 1
    But I see no link for moving to chat displays here.
    – Vicky Dev
    Oct 21, 2016 at 12:20
  • 1
    @QaisarSatti see I've updated my code so it's compatible with both 1.9.2 and 1.9.3 ;) Oct 21, 2016 at 12:21
2

Fixed - Image Upload issue after PATCH 8788 install of Magento version CE 1.7.0.2 - 1.9.2.4.

I was able to fix it,Please Follow following instruction.

Step >> 1: After installed security patch 8788 successfully, Please go to admin panel and flush all Magento cache. Then Logout your Admin Panel and Relogin to Admin Panel.

Step >> 2: Go to Index Management and select all reindex all data after flush all Magento cache once again.

Step >> 3: This very Important step, Delete your browser cache(Ctrl+shift+Delete) history clear all browsing data from browser including cookies.

Step >> 4: Go to Catalog >> Product Management , add new image of any product,now you can see everything work fine.

0

I was experiencing your same Issue case 2. In my case it was caused by this file being overwritten by a custom module:

app/design/adminhtml/default/default/template/catalog/product/helper/gallery.phtml

I would suggest you check to see if you have a similar template overwriting the template for that block Mage_Adminhtml_Block_Catalog_Product_Helper_Form_Gallery_Content and if that is the case, apply the Supee-8788 patch to the overwriting file.

Your Answer

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

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