Numerous Magento Websites

I have a bit of a dilemma with the Magento website I created. I have two web sites with a store, each of which is configured to allow multiple currency checks for each site. Thus, the only difference between two sites (on two different domains) that are managed through one common magento installation is the currency and the currency of the statement. So far, everything is working. However, I am trying to split the verification session between sites, so the shopping cart remains unchanged when switching between sites. I manage to get the correct session id added to the switch url, so every site knows which session we are looking for. However, the method that actually displays the shopping cart does not work on the website independently - for example, in

Mage_Checkout_Model_Session

_getQuoteIdKey () β†’ uses the current site identifier to check the quote identifier in the session.

And I can’t understand what / how to rewrite this functionality so that every website shares exactly the same shopping cart data!

my variable $ _SESSION ['checkout'] shows the same thing on every site, but with the specified identifier for this site, the data is useless for the shopping cart: 'quote_id_4' => string '13' (length = 2)

Any ideas, is this even possible?

+5
source share
1 answer

, , 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 - , .

    /**
     * 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;
    }
    

    }

, , , -, .

  • 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
/**
 * 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>

, magento cookie.

  • ,

Magento///​​ ​​/Mage///Session//Varien.php

// potential custom logic for session id (ex. switching between hosts)
$this->setSessionId();

// 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 */

, - . , , , , , !

+10

All Articles