2013-07-20 46 views
1

我正在尋找幾小時。我嘗試在登錄後切換商店語言。Magento通過登錄改變語言

假設是:

  • 我想改用太商店的ID。
  • 事件觀察者也完成了。

這是我制定了最後幾個小時

我的觀察報:

$customerId = Mage::getModel('customer/session')->getCustomer()->getId(); 
// Get the Store ID we want to switch too 
$connection = Mage::getSingleton('core/resource')->getConnection('distributor_read'); 
$mainLanguage = $connection->fetchAll('SELECT...'); 

$storeId = $mainLanguage[0]["store_id"]; 
if (!$storeId == null) {     
    $storeCode = Mage::app()->getStore($storeId)->getCode(); 
    // Here I have to switch by the store code 
    return; 
} 

會很高興,如果有人可以幫助我。 至少我需要一種方法來切換語言或storeview,但我沒有找到任何可行的MagentoAPI方法。

回答

0

我會告訴你們這個案子我做了些什麼。我試圖獲得Mage_Core_Controller_Response_Http班,完全徒勞。

所以我一直在進行我的研究,我發現了一個解決方案。

我用:

header('Location: '. Mage::app()->getStore()->getBaseUrl().'/customer/account?___store='.$storeCode); 

我們去那裏,我在登錄觀察員剛纔設置的語言。

編輯:

要設置一個新的標題可能會導致一些問題,因爲如果只是任何一塊的HTML已經呈現你不能設置一個新的標題。

我工作過。別的出路:

$url = Mage::getUrl('*/*'); 
$url .= "?___store=" . $storeCode; 

$response = Mage::app()->getFrontController()->getResponse(); 

$response->setRedirect($url); 
$response->sendResponse(); 
exit(); 

目前顯然仍存在問題,退出不應該在良好的軟件代碼中使用,但一個簡單的return不起作用,它並沒有結束或殺死觀察員的行動。 我仍在努力尋找解決方案,以正確的方式殺死觀察者。正如我所說的,觀察者需要被殺死以重定向網址。

0

設置店鋪ID編程

在index.php文件中,(在你的語言特定的文件夾),添加以下內容: -

$store_id = 'your_store_id_here'; 
$mageRunCode = 'store view code'; 
$mageRunType = 'store'; 

Mage::app()->setCurrentStore($store_id); 
Mage::run($mageRunCode, $mageRunType); 

我建議你創建一些臨時會話從登錄操作變量和index.php文件讀取設置語言包,再次取消它,如果你的工作已經完成

希望有人會發現此信息有用:)

+0

嘿, 感謝您的幫助。但我不得不問,你的意思是什麼index.php。我在app/locale中有我的語言文件夾,並且沒有包含index.php。 – Silom

+0

@Silom歡迎,這種情況下,當你有不同的網址存儲如果沒有像https://testdomain.com/germany_store不同的文件夾,那麼請忽略,你可以添加它你的主要index.php – liyakat