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

  1. {{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:

  1.  //app\code\core\Mage\Catalog\Block\Category\Widget\Link.php
  2. class Mage_Catalog_Block_Category_Widget_Link
  3.     extends Mage_Catalog_Block_Widget_Link
  4. {
  5.     /**
  6.      * Initialize entity model
  7.      */
  8.     protected function _construct()
  9.     {
  10.         parent::_construct();
  11.         $this->_entityResource = Mage::getResourceSingleton('catalog/category');
  12.     }
  13. }

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

  1. <?php
  2. public function getHref()
  3.     {
  4.         if (!$this->_href) {
  5.  
  6.             if($this->hasStoreId()) {
  7.                 $store = Mage::app()->getStore($this->getStoreId());
  8.             } else {
  9.                 $store = Mage::app()->getStore();
  10.             }
  11.  
  12.             /* @var $store Mage_Core_Model_Store */
  13.             $href = "";
  14.             if ($this->getData('id_path')) {
  15.                 /* @var $urlRewriteResource Mage_Core_Model_Mysql4_Url_Rewrite */
  16.                 $urlRewriteResource = Mage::getResourceSingleton('core/url_rewrite');
  17.                 $href = $urlRewriteResource->getRequestPathByIdPath($this->getData('id_path'), $store);
  18.                 if (!$href) {
  19.                     return false;
  20.                 }
  21.             }
  22.  
  23.             $this->_href = $store->getUrl('', array('_direct' => $href));
  24.         }
  25.  
  26.         if(strpos($this->_href, "___store") === false){
  27.             $symbol = (strpos($this->_href, "?") === false) ? "?" : "&";
  28.             $this->_href = $this->_href . $symbol . "___store=" . $store->getCode();
  29.         }
  30.  
  31.         return $this->_href;
  32.     }
  33. ?>

重点在这里:

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

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

发表评论

电子邮件地址不会被公开。 必填项已用*标注