Every store have their own media folder?

随声附和 提交于 2019-12-08 11:09:25

问题


i have a code in magento that i need 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()
    {



        $appRoot= Mage::getRoot();
        $root   = dirname($appRoot);

        $this->_data['app_dir']     = $appRoot;
        $this->_data['base_dir']    = $root;
        $this->_data['code_dir']    = $appRoot.DS.'code';
        $this->_data['design_dir']  = $appRoot.DS.'design';
        $this->_data['etc_dir']     = $appRoot.DS.'etc';
        $this->_data['lib_dir']     = $root.DS.'lib';
        $this->_data['locale_dir']  = $appRoot.DS.'locale';
        $this->_data['media_dir']   = $root.DS.'default_media';
        $this->_data['skin_dir']    = $root.DS.'skin';
        $this->_data['var_dir']     = $this->getVarDir();
        $this->_data['tmp_dir']     = $this->_data['var_dir'].DS.'tmp';
        $this->_data['cache_dir']   = $this->_data['var_dir'].DS.'cache';
        $this->_data['log_dir']     = $this->_data['var_dir'].DS.'log';
        $this->_data['session_dir'] = $this->_data['var_dir'].DS.'session';
        $this->_data['upload_dir']  = $this->_data['media_dir'].DS.'upload';
        $this->_data['export_dir']  = $this->_data['var_dir'].DS.'export';
       }

I need to change default media, that every store have her own media folder. So i made 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 than, 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 stucked, does any of you have some explanation how to go over this error. And do for every store every media folder in Magento. Thank you.


回答1:


This is a very sticky change to make. If you need to implement this change in the core class, it would be better to copy the file to app/code/local/Mage/Core/Model/Config/Options.php and make your change there to protect against overwrite in an upgrade.

However, I think that it would be better to implement a change in the CMS WYSIWYG modeling to add store path in. I'm not sure of all of the places where you will need to look for & potentially alter behavior and values, but you can start for example in Mage_Cms_Helper_Wysiwyg_Images::getStorageRoot().

Note that the path for writing to and reading from storage (the filesystem path) is different from what will be needed in the frontend (the URL path). Your current example is trying to use the latter for the former, which will not work unless you have something hella crazy going on with file operations and URL wrappers.



来源:https://stackoverflow.com/questions/16896352/every-store-have-their-own-media-folder

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!