, , 2009 , , , . . , Magento
, Magento , .
, Magento .
- - ( , -).
- - - - . Base Currecny, .
- System - Configuration - Catalog - - - "-"
- - .
- - URL- System-Configuration-Web-Secure Unsecure.
.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 Host ^ website-us.local MAGE_RUN_CODE = base_us
SetEnvIf Host ^ website-us.local MAGE_RUN_TYPE = -
SetEnvIf --uk.local MAGE_RUN_CODE = base_uk
SetEnvIf --uk.local MAGE_RUN_TYPE = -
SetEnvIf Host ^ website-uk.local MAGE_RUN_CODE = base_uk
SetEnvIf Host ^ website-uk.local MAGE_RUN_TYPE = -
convertPrice Mage/Core/Model/Store convertPrice - , .
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;
}
}
, , , -, .
System - - - -
magento/app/code/core/Mage/Checkout/Model/Session.php :
_getQuoteIdKey()
{ return 'quote_id'; // 'quote_id_'. $ [1];
}
magento/app/code/core/Mage/Sales/Model/Quote.php getSharedStoreIds :
getSharedStoreIds()
{
$ ids = $this β _ getData ('shared_store_ids');
if (is_null ($ ids) ||! is_array ($ ids)) { $ arrStoreIds = array(); foreach (Mage:: getModel ('core/website') β getCollection() $website) { $ arrStoreIds = array_merge ($ arrStoreIds, $website- > getStoreIds()); } return $arrStoreIds; /* if ($ website = $this- > getWebsite()) { return $website- > getStoreIds(); } var_dump ($ this- > getStore() β getWebsite() β getStoreIds()); (); return $this- > getStore() β getWebsite() β getStoreIds(); */
}
return $ids;
}
magento/app/code/core/Mage/Customers/Model/Customer.php getSharedWebsiteIds() :
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() $website) { $ ids [] = $website- > getId(); } } $ this- > setData ('shared_website_ids', $ids); } return $ids; }
, magento/app/code/core/Mage/Wishlist/Model/Wishlist.php getSharedWebsiteIds, -,
(-) , magento , .
Magento//// /yourtheme///currency.phtml
- , magento , .
<?php
?>
<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>
, magento cookie.
Magento///ββ ββ/Mage///Session//Varien.php
$this->setSessionId();
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();
}
, - . , , , , , !