zoukankan      html  css  js  c++  java
  • Magento去除Widget Link生成的URL后商店码

    原始链接:http://www.***.com/new-arrival.html?___store=default
    处理链接:http://www.***.com/new-arrival.html
    具体步骤:
    1,仔细观察widget生成url的block:

    {{widget type="catalog/category_widget_link" anchor_text="New Arrival" title="New Arrival" template="catalog/category/widget/link/link_inline.phtml" id_path="category/11"}}

    2,根据type找到相应的Block:

     //appcodecoreMageCatalogBlockCategoryWidgetLink.php
    class Mage_Catalog_Block_Category_Widget_Link
        extends Mage_Catalog_Block_Widget_Link
    {
        /**
         * Initialize entity model
         */
        protected function _construct()
        {
            parent::_construct();
            $this->_entityResource = Mage::getResourceSingleton('catalog/category');
        }
    }

    发现该类继承了Mage_Catalog_Block_Widget_Link 再向上查找Mage_Catalog_Block_Widget_Link类
    3,在Mage_Catalog_Block_Widget_Link类中查找getHref方法

    public function getHref()
        {
            if (!$this->_href) {
     
                if($this->hasStoreId()) {
                    $store = Mage::app()->getStore($this->getStoreId());
                } else {
                    $store = Mage::app()->getStore();
                }
     
                /* @var $store Mage_Core_Model_Store */
                $href = "";
                if ($this->getData('id_path')) {
                    /* @var $urlRewriteResource Mage_Core_Model_Mysql4_Url_Rewrite */
                    $urlRewriteResource = Mage::getResourceSingleton('core/url_rewrite');
                    $href = $urlRewriteResource->getRequestPathByIdPath($this->getData('id_path'), $store);
                    if (!$href) {
                        return false;
                    }
                }
     
                $this->_href = $store->getUrl('', array('_direct' => $href));
            }
     
            if(strpos($this->_href, "___store") === false){
                $symbol = (strpos($this->_href, "?") === false) ? "?" : "&";
                $this->_href = $this->_href . $symbol . "___store=" . $store->getCode();
            }
     
            return $this->_href;
        }

    重点在这里:

    if(strpos($this->_href, "___store") === false){
                $symbol = (strpos($this->_href, "?") === false) ? "?" : "&";
                $this->_href = $this->_href . $symbol . "___store=" . $store->getCode();
            }

    这段代码就是给链接后面添加商店码的。注释掉即可。

  • 相关阅读:
    Solution -「ARC 126E」Infinite Operations
    toString()、String.valueOf、(String)强转,有啥区别?
    Win10下python3和python2同时安装并解决pip共存问题
    3295. 星际旅行(计算几何)
    计算几何基础(入土)知识
    (淀粉质)P2634 [国家集训队]聪聪可可 and P3806 多次离线查询树上距离为k的点对是否存在
    企业微信 之员工报餐
    PHP 之tp5导出到Excel并下载
    小程序 之安全问题考虑
    PHP 之上传网络图片到微信临时素材
  • 原文地址:https://www.cnblogs.com/liuxgnu/p/3535380.html
Copyright © 2011-2022 走看看