我都有点进退两难了Magento的网站我建立。 我有两个网站,一个存储的每个设置,以便为每个站点启用多种货币结算。 所以在两个站点之间,它们通过一个普通的magento安装管理的唯一差别(在两个不同的结构域)是货币显示和结帐货币。 这是所有工作的罚款为止。 但是我想分享站点之间的结账会议,以便在站点之间切换时,购物车保持不变。 我设法得到加到开关URL,这样每个站点知道什么会议上,我们正在寻找正确的会话ID。 然而,实际上显示购物车中的方法似乎并不工作网站独立 - 例如在
Mage_Checkout_Model_Session
_getQuoteIdKey() - >使用当前网站的ID,以检查该会话的报价ID。
我想不出什么/如何覆盖该功能使每个网站股完全相同的购物车数据!
我的$ _SESSION [“结帐”]变量显示在每个站点上,但与此网站ID相同的包括在数据是用于购物车中没有使用:“quote_id_4” =>字符串“13”(长度= 2)
任何想法,这是否是可能的呢?
我搜索的答案,在此之后,并在同样的问题,因为2009年被要求没有一个明确的解决方案迷迷糊糊的,我终于寻找到了自己的代码的深水区 - 瞧,我有一个可行的解决方案。 这里的人的详细指南谁想要建立与Magento的
- 不只是得到显示,但实际收取在选择货币多种货币
- 分享购物车整个网站,而不仅仅是商店
这种组合的主要问题是与默认Magento的结构,你永远只能做一个或另一个,而不是两个结合。
所以让我们先设置了Magento的多种货币。
- 为每种货币建立一个网站,相应的存储和商店视图(不只是存储的看法,完全网站)
- 系统设置 - 配置 - 每个网站设置货币对各自的货币。 所有这三个条目的基本Currecny,默认显示货币,并允许货币应设置为只同一个货币。
- 返回到默认的配置整体范围和系统设置 - 配置 - 目录 - - - 价格目录价格适用范围为“网站”
- 您还可以定义你汇率在系统 - 管理货币汇率
- 对于每一个网站范围设置相应的系统 - 配置 - 网络 - 安全与不安全的基础URL。
在你的.htaccess文件中添加这在顶部(更换相应的网站域名和您输入密码时,设置了网站(这里的http://website-us.local与base_us和HTTP://website-uk.local与代码base_uk)
SetEnvIf之后主机网站us.local MAGE_RUN_CODE = base_us SetEnvIf之后主机网站us.local MAGE_RUN_TYPE =网站SetEnvIf之后主机^网站us.local MAGE_RUN_CODE = base_us SetEnvIf之后主机^网站us.local MAGE_RUN_TYPE =网站
SetEnvIf之后主机网站uk.local MAGE_RUN_CODE = base_uk SetEnvIf之后主机网站uk.local MAGE_RUN_TYPE =网站SetEnvIf之后主机^网站uk.local MAGE_RUN_CODE = base_uk SetEnvIf之后主机^网站uk.local MAGE_RUN_TYPE =网站
覆盖在法师/核心/型号/存储的方法convertPrice,改变方法convertPrice - 这将确保价格始终显示在正确的转换和正确的货币符号。
/** * Convert price from default currency to current currency * * @param double $price * @param boolean $format Format price to currency format * @param boolean $includeContainer Enclose into <span class="price"><span> * @return double */ public function convertPrice($price, $format = false, $includeContainer = true) { $categories = Mage::getModel('catalog/category')->getCollection(); $categ_ids=$categories->getAllIds(); $baseCurrencyCode = Mage::app()->getBaseCurrencyCode(); $allowedCurrencies = Mage::getModel('directory/currency')->getConfigAllowCurrencies(); $currencyRates = Mage::getModel('directory/currency')->getCurrencyRates($baseCurrencyCode,array_values($allowedCurrencies)); if ($this->getCurrentCurrency() && $this->getBaseCurrency()) { $value = $this->getBaseCurrency()->convert($price, $this->getCurrentCurrency()); } else { $value = $price; } if($this->getCurrentCurrencyCode() != $baseCurrencyCode) { $value = $price * $currencyRates[$this->getCurrentCurrencyCode()]; } if ($this->getCurrentCurrency() && $format) { $value = $this->formatPrice($value, $includeContainer); } return $value; }
}
但是,当然,我们也想分享用户数据,车,整个登录我们刚建立的网站。
While in default config scope set System - Configuration - Customer Configuration - Account Sharing Options - Share Customer Accounts to Global
Overwrite magento/app/code/core/Mage/Checkout/Model/Session.php and replace this method:
protected function _getQuoteIdKey()
{
return 'quote_id';
//return 'quote_id_' . $websites[1];
}
Overwrite magento/app/code/core/Mage/Sales/Model/Quote.php and change the method getSharedStoreIds to:
public function getSharedStoreIds()
{
$ids = $this->_getData('shared_store_ids');
if (is_null($ids) || !is_array($ids)) {
$arrStoreIds = array();
foreach(Mage::getModel('core/website')->getCollection() as $website)
{
$arrStoreIds = array_merge($arrStoreIds,$website->getStoreIds());
}
return $arrStoreIds;
/*if ($website = $this->getWebsite()) {
return $website->getStoreIds();
}
var_dump($this->getStore()->getWebsite()->getStoreIds());exit();
return $this->getStore()->getWebsite()->getStoreIds();
*/
}
return $ids;
}
Overwrite magento/app/code/core/Mage/Customers/Model/Customer.php and change again the method getSharedWebsiteIds() to:
public function getSharedWebsiteIds() {
$ids = $this->_getData('shared_website_ids');
if ($ids === null) {
$ids = array();
if ((bool)$this->getSharingConfig()->isWebsiteScope()) {
$ids[] = $this->getWebsiteId();
} else {
foreach (Mage::app()->getWebsites() as $website) {
$ids[] = $website->getId();
}
}
$this->setData('shared_website_ids', $ids);
}
return $ids;
}
If you use the wishlist option you should do the same for the method in magento/app/code/core/Mage/Wishlist/Model/Wishlist.php and change getSharedWebsiteIds so it not only loads the store ids from the current website but from all of them
Now we also have to implement a currency (website) switch on the frontend stores and pass the correct session ids inbetween so magento knows what stores to look for. I imitated the currency switch here and added the following dropdown to
magento/app/design/frontend/default/yourtheme/template/directory/currency.phtml
This loads all websites and applies the current Session Id as a query string so magento knows on any domain which session to use.
<?php
/**
* Currency switcher
*
* @see Mage_Directory_Block_Currency
*/
?>
<div class="top-currency">
<?php
$websites = Mage::getModel('core/website')->getCollection();
$this_session_id = Mage::getSingleton('core/session', array('name' => 'frontend'))->getSessionId();
?>
<select id="website-changer" onChange="document.location=this.options[selectedIndex].value">
<?php
foreach($websites as $website):
$default_store = $website->getDefaultStore();
$website_currency = $default_store->getBaseCurrency()->getCurrencyCode();
$url_obj = new Mage_Core_Model_Url();
$default_store_path = $url_obj->getBaseUrl(array('_store'=> $default_store->getCode()));
$default_store_path .= Mage::getSingleton('core/url')->escape(ltrim(Mage::app()->getRequest()->getRequestString(), '/'));
$default_store_path = explode('?', $default_store_path);
$default_store_path = $default_store_path[0] . '?SID=' . $this_session_id;
?>
<option <? if(strstr($default_store_path,Mage::getBaseUrl())):?>selected="selected"<?endif; ?> value="<?=$default_store_path ?>">
<?=$website_currency?>
</option>
<?endforeach;?>
</select>
</div>
This query string will only be applied the first time you switch but magento will remember the session id after that stored in a cookie.
- In order for this to work properly, overwrite
magento/app/code/core/Mage/Core/Model/Session/Abstract/Varien.php
and
replace this
// potential custom logic for session id (ex. switching between hosts)
$this->setSessionId();
with
// potential custom logic for session id (ex. switching between hosts)
/* Amend to ensure shopping carts are shared between websites */
if (isset($_COOKIE['lastsid']))
{
session_decode(file_get_contents(Mage::getBaseDir('session').'/sess_'.$_COOKIE['lastsid']));
setcookie ('lastsid', '', time() - 3600);
}
if (isset($_GET['SID']))
{
$this->setSessionId($_GET['SID']);
session_decode(file_get_contents(Mage::getBaseDir('session') . '/sess_' . $_GET['SID']));
setcookie('lastsid', $_GET['SID']);
$_COOKIE['lastsid'] = $_GET['SID'];
}
else
{
$this->setSessionId();
}
/* Amend end */
This should now display multiple currencies, charge in multiple currencies across mutliple websites and on top of this share logins and shopping carts. This solution is a collection of knowledge I found on the interwebs combined with a few bits and pieces I figured out myself, so thanks for anyone who gave advice!