0

I have a code in Magento that I want to overwrite. Code can be found in /app/code/core/Mage/Core/Model/Config/Options.php:

The code goes something like this :

protected function _construct()
{
    ...
    $this->_data['media_dir']   = $root.DS.'default_media';
    ...
}

I need to change default media, that every store have its own media directory. So i made a function:

public function getMediaFromStore()
{
    $fullMediaUrl = Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_MEDIA);
    $baseUrl = Mage::getBaseUrl();
    echo substr(Mage::getBaseUrl($fullMediaUrl, strlen($baseUrl));
}

And then, instead of

$this->_data['media_dir']   = $root.DS.'default_media';

i put

$this->_data['media_dir']   = $root.DS.$this->getMediaFromStore();

and i got freaking error, that goes like this...

Fatal error: Call to a member function getOptions() on a non-object in /home/cofamedia/www/magento/app/Mage.php on line 328

And I'm stuck. Does any of you have some explanation how to go over this error. And do for every store their own media folder in Magento. Thank you.

  • Can you please update your question with the full error stack trace? – user487772 Jun 3 '13 at 18:21
  • @Tim What do you mean? – stefankuburovic Jun 3 '13 at 18:34
  • Ah, now I see that you got PHP fatal error and not Magento exception. – user487772 Jun 3 '13 at 18:45
  • Incorrect use of substr() – mageUz Jun 5 '13 at 13:40
1

You have a child error in your method. Instead of echoing

echo substr(Mage::getBaseUrl($fullMediaUrl, strlen($baseUrl));

you should return the value

return substr(Mage::getBaseUrl($fullMediaUrl, strlen($baseUrl));
| improve this answer | |
  • That is not it, neither, i realize that i have mistakes in function, but either way, same error showing up, thank you. – stefankuburovic Jun 4 '13 at 9:04
1

I cannot understand what is mean of your snippet? If you want different media url for every store you can do this logic with standard Magento functionality. Go to admin->system->config and open Web tab. Top left corner you can change store scope and you should set media url for every store differently via unsecure/secure field-set.

Updated:

In my opinion you have more store with different domain name with one magento installation. And you want every store should has own media root named as domain name:

www.somestore.com -> somestore
www.anotherstore.com -> anotherstore

There is somestore, anotherstore are media folder names. Use like as:

public function getMediaFromStore()
{
    $host=explode('.',$_SERVER["HTTP_HOST"]);
    return $host[count($host)-2]; 
}
| improve this answer | |
  • No that is not it, when you change in admin panel, nothing happens, but thank you. – stefankuburovic Jun 4 '13 at 9:00
  • You mean media folder, not media url, right? – mageUz Jun 4 '13 at 10:47
  • Yes, media folder. – stefankuburovic Jun 5 '13 at 8:55
  • Did you try this? – mageUz Jun 12 '13 at 15:08
  • Yes i have tried, but still the same error. – stefankuburovic Jun 14 '13 at 8:56

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.