Pertama, Anda perlu melakukan beberapa perubahan dalam pengaturan.
Bagikan akun pelanggan antara beberapa situs web
Anda harus mengkonfigurasi fitur ini di sini: System -> Configuration -> Customer Configuration -> Share Customer Accounts
.
Buat pengaturan ini ke Global untuk berbagi setiap pelanggan ke semua situs web .
Bagikan login antar situs web
Untuk menjaga sesi ketika beralih antar toko di situs web yang berbeda , aktifkan "Gunakan SID di Frontend" di System> Configuration> General> Web :
Paksa pengguna untuk mengalihkan ke situs web yang sama dengan yang mereka daftarkan
Pelanggan secara paksa masuk ke situs web yang sama dengan yang mereka daftarkan ketika kami mencoba masuk dari situs web lain.
Menggunakan customer_login
Tentukan acara ke config.xml
<?xml version="1.0"?>
<config>
<modules>
<Stackexchange_Magento165528>
<version>1.0.0</version>
</Stackexchange_Magento165528>
</modules>
<global>
<models>
<magento165528>
<class>Stackexchange_Magento165528_Model</class>
</magento165528>
</models>
<events>
<customer_login> <!-- identifier of the event we want to catch -->
<observers>
<customer_login_handler> <!-- identifier of the event handler -->
<type>singleton</type> <!-- class method call type; valid are model, object and singleton -->
<class>magento165528/observer</class> <!-- observers class alias -->
<method>redirectoSourceDomain</method> <!-- observer's method to be called -->
<args></args> <!-- additional arguments passed to observer -->
</customer_login_handler>
</observers>
</customer_login>
</events>
</global>
</config>
Kelas pengamat:
<?php
class Stackexchange_Magento165528_Model_Observer
{
public function redirectoSourceDomain(Varien_Event_Observer $observer)
{
$_customer = $observer->getEvent()->getCustomer();
/*
* Store of website from which website Customer have registered
*/
$_customer_resgister_store_id= $_customer->getStoreId();
if($_customer_resgister_store_id != Mage::app()->getStore()->getStoreId()){
$allStores=Mage::app()->getStores(); //get list of all stores,websites
foreach ($allStores as $_eachStoreId => $val){
$_storeId = Mage::app()->getStore($_eachStoreId)->getId();
//get url using store id
if($_customer_resgister_store_id == $_eachStoreId ){
$Websiteurl= Mage::app()->getStore($_storeId)->getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB);
$_redirecUrl = $Websiteurl."customer/account/login?SID=".Mage::getModel("core/session")->getEncryptedSessionId();
/* Force redirect to repective Website */
Mage::app()->getFrontController()->getResponse()
->setRedirect($_redirecUrl)
->sendResponse();
exit;
}
}
}
return;
}
}
CATATAN:
SAYA TELAH MENGUJI KODE INI DI SITUS WEB SITUS MAGENTO DEMO.
Dua situs web ini berjalan dari instance magento yang sama menggunakan konsep situs web.