I have prepared a code which check product with no images and than add an image to it form a folder with same name as that of product. In Magento 1.9 it is working perfectly. But when i try it on magento1.7 it throughs fatal error. Here is my code

error_reporting(E_ALL | E_STRICT);
$mageFilename = 'app/Mage.php';
require_once $mageFilename;
ini_set('display_errors', 1);
ini_set('memory_limit', '600M');
ini_set('max_execution_time', 1800);
$products_model =  Mage::getModel('catalog/product')
                ->addAttributeToFilter('status', array("eq" => 1))
$backendModel = $products_model->getResource()->getAttribute('media_gallery')->getBackend();

foreach ($products_model as $pid){
    $img = pathinfo($pid->getImageUrl())['basename'];
     echo 'Name  =  '.$pid->getName().'<br>';
    echo 'Image  =  '.$img.'<br>';
    if($img =='' || $img== 'image.jpg'){
        $ImagePath = "/var/www/vhosts/inriverimage/pics/".$pid->getName().".jpg"; // path of the image

        //$ImagePath = dirname(__FILE__)."/media/import/".$pid->getName().".jpg"; // path of the image
            echo 'Image  Found<br>';
            $products_model = Mage::getModel('catalog/product')->load($pid->getId()); 
            $products_model->addImageToMediaGallery($ImagePath, array('image', 'small_image', 'thumbnail'), false);
            echo 'Image  Not found<br>';

This code is working in Magento 1.9. But If i try run it in magento1.7 using following URL http://localhost/magento1.7/addimage.php it through following error

Fatal error: Uncaught exception 'Exception' with message 'Strict Notice: Declaration of Mage_Core_Controller_Request_Http::getBaseUrl() should be compatible with Zend_Controller_Request_Http::getBaseUrl($raw = false) in /var/www/vhosts/loruslive/httpdocs/app/code/core/Mage/Core/Controller/Request/Http.php on line 36' in /var/www/vhosts/loruslive/httpdocs/app/code/core/Mage/Core/functions.php:245 Stack trace: #0 /var/www/vhosts/loruslive/httpdocs/app/code/core/Mage/Core/Controller/Request/Http.php(36): mageCoreErrorHandler(2048, 'Declaration of ...', '/var/www/vhosts...', 36, Array) #1 /var/www/vhosts/loruslive/httpdocs/lib/Varien/Autoload.php(93): include('/var/www/vhosts...') #2 [internal function]: Varien_Autoload->autoload('Mage_Core_Contr...') #3 /var/www/vhosts/loruslive/httpdocs/app/code/core/Mage/Core/Model/App.php(1219): spl_autoload_call('Mage_Core_Contr...') #4 /var/www/vhosts/loruslive/httpdocs/app/code/core/Mage/Core/Model/Cookie.php(83): Mage_Core_Model_App->getRequest() #5 /var/www/vhosts/loruslive/httpdocs in /var/www/vhosts/loruslive/httpdocs/app/code/core/Mage/Core/functions.php on line 245
  • 1
    remove E_Strict from your error reporting : E_ALL & ~E_STRICT
    – paj
    Feb 12 '21 at 20:47

I finally fixed the problem by editing the file app/code/core/Mage/Core/Controller/Request/Http.php and changing the function getBaseUrl() as follows:

public function getBaseUrl($raw = false)
    $url = parent::getBaseUrl($raw);
    $url = str_replace('\\', '/', $url);
    return $url;

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.