语言商店特定网址上的Magento 404错误
我有一家拥有2家语言商店的magento(企业)网站。每个用户都有自己的指定项目或资源的专用url,可以是静态页面或产品页面。语言商店特定网址上的Magento 404错误
我通过CMS使用URL规则来管理所有资源的SEF URL。
的问题是以下情形:
网站默认为LANG#1。
当用户从LANG#1切换到LANG#2时,切换没有问题 - 切换到特定语言(_store = lang>> http://www.sitename.com/?_store=lang)
但不管什么郎店我在,如果我有选择从其他郎商店网址为我目前的语言专卖店,我得到一个404错误。
我想什么系统检查当前存储的资源请求,如果没有找到,它应该路由到下一个存储并检查那里的资源,如果找到了,存储应该切换到langsto该项目被发现和网址重定向。
为了达到这个目的,我应该延伸什么类(我对magento来说是比较新的)。
我去就检查,如果我能扩展这个类做我想做的:/app/code/core/Mage/Core/Model/Mysql4/Url/Rewrite.php
但不能肯定是否我处于这样的要求的正确位置。
任何帮助将不胜感激!
谢谢
我能够解决这个问题了。我所做的只是扩展了/app/code/core/Mage/Core/Model/Mysql4/Url/Rewrite.php文件。
因此,我过去loadByRequestPath函数为当前存储中的请求提供服务,如果找不到,则获取所有其他可用存储的列表,循环并查找该项是否存在。如果发现重定向到存在该产品和whola的URL密钥的商店。
如果没有商店有它,那么返回404错误。
对于静态页面,当您切换商店/语言时,URL重写管理器将能够为您解决问题。
我希望这可以帮助别人!
我不认为我的是最优雅的解决方案,但我会发布它,因为它为我工作。 基本上我在所有商店中搜索我正在寻找的路径而不是指定的商店。任何建议都会受到欢迎。
我的config.xml
<?xml version="1.0"?>
<config>
<global>
<modules>
<Soipo_UrlRewrite>
<version>0.1</version>
</Soipo_UrlRewrite>
</modules>
<models>
<soipo_urlrewrite>
<class>Soipo_UrlRewrite_Model</class>
</soipo_urlrewrite>
<core_mysql4>
<rewrite>
<url_rewrite>Soipo_UrlRewrite_Model_Mage_Core_Model_Mysql4_Url_Rewrite</url_rewrite>
</rewrite>
</core_mysql4>
</models>
</global>
</config>
重写。PHP
类Soipo_UrlRewrite_Model_Mage_Core_Model_Mysql4_Url_Rewrite扩展Mage_Core_Model_Mysql4_Url_Rewrite {
/**
* This function get an array of store ids, containing the Admin store.
* @return array
*/
public function getStoreIds(){
$allStores = Mage::app()->getStores();
$storeIds = array();
$storeIds[] = Mage_Core_Model_App::ADMIN_STORE_ID;
foreach ($allStores as $_eachStoreId => $val)
{
$_storeId = Mage::app()->getStore($_eachStoreId)->getId();
$storeIds[] = $_storeId;
}
return $storeIds;
}
/**
* Load rewrite information for request
* If $path is array - we must load all possible records and choose one matching earlier record in array
*
* @param Mage_Core_Model_Url_Rewrite $object
* @param array|string $path
* @return Mage_Core_Model_Resource_Url_Rewrite
*/
public function loadByRequestPath(Mage_Core_Model_Url_Rewrite $object, $path)
{
if (!is_array($path)) {
$path = array($path);
}
$pathBind = array();
foreach ($path as $key => $url) {
$pathBind['path' . $key] = $url;
}
$storeIds = $this->getStoreIds();
// Form select
$adapter = $this->_getReadAdapter();
$select = $adapter->select()
->from($this->getMainTable())
->where('request_path IN (:' . implode(', :', array_flip($pathBind)) . ')')
->where('store_id IN(?)', $storeIds);
$items = $adapter->fetchAll($select, $pathBind);
// Go through all found records and choose one with lowest penalty - earlier path in array, concrete store
$mapPenalty = array_flip(array_values($path)); // we got mapping array(path => index), lower index - better
$currentPenalty = null;
$foundItem = null;
foreach ($items as $item) {
if (!array_key_exists($item['request_path'], $mapPenalty)) {
continue;
}
$penalty = $mapPenalty[$item['request_path']] << 1 + ($item['store_id'] ? 0 : 1);
if (!$foundItem || $currentPenalty > $penalty) {
$foundItem = $item;
$currentPenalty = $penalty;
if (!$currentPenalty) {
break; // Found best matching item with zero penalty, no reason to continue
}
}
}
// Set data and finish loading
if ($foundItem) {
$object->setData($foundItem);
}
// Finish
$this->unserializeFields($object);
$this->_afterLoad($object);
return $this;
}
}
能否请你加入循环代码为您loadByRequestPath功能? – Paktas
你想分享的代码,因为我有同样的magento安装5 +商店类似的问题。 –