Images in Magento widgets

前端 未结 6 2231
無奈伤痛
無奈伤痛 2020-12-31 21:33

I am developing a site for a fashion client in Magento Community version 1.4.2 and as part of this project I need to have some customized home page promotion blocks to featu

6条回答
  •  执笔经年
    2020-12-31 21:35

    Thx krus for you answer! I've found a nicer way to solve the problem with the cached image URLs. I even had to do this, because your solution overwriting the Widget Model didn't work with Magento 1.7.0.2.

    So what I have done is adding a new GET parameter use_file_url to the URL used for the Chooser Block:

    $url    = $this->getUrl(
        '*/cms_wysiwyg_images/index',
        array(
            'target_element_id' => $element->getName(),
            'use_file_url' => 1
        )
    );
    

    This passes the GET parameter to the media browser. The next step is to pass this parameter to the onInsertAction of the Mage_Adminhtml_Cms_Wysiwyg_ImagesController. Do do this, you have to override the getOnInsertUrl() function of the Mage_Adminhtml_Block_Cms_Wysiwyg_Images_Content Block:

    public function getOnInsertUrl()
    {
        $useFileUrl = (int)$this->getRequest()->getParam('use_file_url', 0);
        return $this->getUrl('*/*/onInsert', array('use_file_url' => $useFileUrl));
    }
    

    Then you need to handle the new parameter in the Mage_Adminhtml_Cms_Wysiwyg_ImagesController controller:

    public function onInsertAction()
    {
        $useFileUrl = (int)$this->getRequest()->getParam('use_file_url', 0) == 1 ? true : false;
        $helper     = Mage::helper('cms/wysiwyg_images');
        $storeId    = $this->getRequest()->getParam('store');
        $filename   = $this->getRequest()->getParam('filename');
        $filename   = $helper->idDecode($filename);
        $asIs       = $this->getRequest()->getParam('as_is');
    
        Mage::helper('catalog')->setStoreId($storeId);
        $helper->setStoreId($storeId);
    
        if ($useFileUrl == false) {
            $image = $helper->getImageHtmlDeclaration($filename, $asIs);
        } else {
            $image = $helper->getImageMediaUrl($filename);
        }
    
        $this->getResponse()->setBody($image);
    }
    

    The last step is to override the Mage_Cms_Helper_Wysiwyg_Images helper and add the getImageMediaUrl() function:

    public function getImageMediaUrl($filename)
    {
        return $this->getCurrentUrl() . $filename;
    }
    

    I think this is a quite pretty approach, even though you have to ovverride 4 classes. But passing a GET parameter seems to be more future safe than parsing the cached URL.

提交回复
热议问题