Reorder Magento JavaScript Includes (addJs)

前端 未结 7 1574
无人共我
无人共我 2021-02-09 01:37

I\'ll keep this simple.... on my product pages I need to remove the prototype.js file and replace it with the latest version of prototype. So far using local.xml I have successf

7条回答
  •  失恋的感觉
    2021-02-09 02:22

    Ok here's my solution. First copy app\code\core\Mage\Page\Block\Html\head.php to app\code\local\Mage\Page\Block\Html\head.php

    Then add this function to the file :

    public function replaceItem($type, $name, $replace)
    {
        $newArray = array();
    
        foreach($this->_data['items'] as $key => $value) {
            if($key == $type.'/'.$name) {
                $newArray[$type . '/'. $replace] = array(
                'type'   => $type,
                'name'   => $replace,
                'params' => $value['params'],
                'if'     => $value['if'],
                'cond'   => $value['cond']);
            } else {
                $newArray[$key] = $value;
            }
        }
        $this->_data['items'] = $newArray;
        return $this;
    }
    

    Now in your .XML layout file include a line like this :

    jsprototype/prototype.jsonestepcheckout/prototype/prototype.js
    

    The parameters are exactly as for removeItem BUT now the replace file will be injected into the list in the same place as the original file. It will also inherit the same param, if and cond values. Please use this code carefully as I've only just written and done basic tests on it!

提交回复
热议问题