Magento Multiple Stores Issue - 第二个域正在加载默认商店产品

时间:2014-03-25 20:49:11

标签: magento

我在Magento的单个安装中有两个商店,我有第二个商店的单独域名,只指向主要安装(第二个域中根本没有文件)。但是,当用户通过第二个域访问时,不会加载第二个商店,而是加载默认商店的类别和产品。我将以下行添加到Magentos根目录中的.htaccess文件中,但它们似乎没有用。

############################################
enable rewrites

SetEnvIf Host www\.testsite\.com MAGE_RUN_CODE=shoe_store
SetEnvIf Host www\.testsite\.com MAGE_RUN_TYPE=website
SetEnvIf Host ^testsite\.com MAGE_RUN_CODE=shoe_store
SetEnvIf Host ^testsite\.com MAGE_RUN_TYPE=website

Options +FollowSymLinks
RewriteEngine on
############################################

shoe_store是第二个商店的“网站名称”的代码,而不是“商店视图名称”,但它们都不起作用。我不确定所有的反斜杠是什么,但它们都在我读过的所有教程中。我还检查了安全和不安全部分中的基本URL,它是正确的地址,末尾有一个/(http://testsite.com/)。

我有多个商店在使用子域,但单独的域证明更加困难。谁知道我做错了什么?

编辑:在下面的index.php代码中添加

<?php
/**
 * Magento
 *
 * NOTICE OF LICENSE
 *
 * This source file is subject to the Open Software License (OSL 3.0)
 * that is bundled with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://opensource.org/licenses/osl-3.0.php
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@magentocommerce.com so we can send you a copy immediately.
 *
 * DISCLAIMER
 *
 * Do not edit or add to this file if you wish to upgrade Magento to newer
 * versions in the future. If you wish to customize Magento for your
 * needs please refer to http://www.magentocommerce.com for more information.
 *
 * @category   Mage
 * @package    Mage
 * @copyright  Copyright (c) 2008 Irubin Consulting Inc. DBA Varien (http://www.varien.com)
 * @license    http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
 */

if (version_compare(phpversion(), '5.2.0', '<')===true) {
    echo  '<div style="font:12px/1.35em arial, helvetica, sans-serif;">
<div style="margin:0 0 25px 0; border-bottom:1px solid #ccc;">
<h3 style="margin:0; font-size:1.7em; font-weight:normal; text-transform:none; text-align:left; color:#2f2f2f;">
Whoops, it looks like you have an invalid PHP version.</h3></div><p>Magento supports PHP 5.2.0 or newer.
<a href="http://www.magentocommerce.com/install" target="">Find out</a> how to install</a>
 Magento using PHP-CGI as a work-around.</p></div>';
    exit;
}

/**
 * Error reporting
 */
error_reporting(E_ALL | E_STRICT);

/**
 * Compilation includes configuration file
 */
define('MAGENTO_ROOT', getcwd());

$compilerConfig = MAGENTO_ROOT . '/includes/config.php';
if (file_exists($compilerConfig)) {
    include $compilerConfig;
}

$mageFilename = MAGENTO_ROOT . '/app/Mage.php';
$maintenanceFile = 'maintenance.flag';

if (!file_exists($mageFilename)) {
    if (is_dir('downloader')) {
        header("Location: downloader");
    } else {
        echo $mageFilename." was not found";
    }
    exit;
}

if (file_exists($maintenanceFile)) {
    include_once dirname(__FILE__) . '/errors/503.php';
    exit;
}

require_once $mageFilename;

#Varien_Profiler::enable();

if (isset($_SERVER['MAGE_IS_DEVELOPER_MODE'])) {
    Mage::setIsDeveloperMode(true);
}

#ini_set('display_errors', 1);

umask(0);

/* Store or website code */
$mageRunCode = isset($_SERVER['MAGE_RUN_CODE']) ? $_SERVER['MAGE_RUN_CODE'] : '';

/* Run store or run website */
$mageRunType = isset($_SERVER['MAGE_RUN_TYPE']) ? $_SERVER['MAGE_RUN_TYPE'] : 'store';

if (file_exists($autoload = __DIR__.'/vendor/autoload.php')) {
    require_once $autoload;
}

switch($_SERVER['HTTP_HOST']) {
     case 'mainsite.com':
     case 'www.mainsite.com':
          $mageRunCode = 'base'; //not your website code, it should be code for your first store
          $mageRunType = 'website'; //it should be 'store', since you have multiple stores.Another possible value is 'website'
           break;
     case 'testsite.com':
     case 'www.testsite.com':
           $mageRunCode = 'shoe_store'; //code of second store
           $mageRunType = 'website';
           break;
}
Mage::run($mageRunCode, $mageRunType);

1 个答案:

答案 0 :(得分:1)

通过解决您的问题,我觉得您的域名工作正常。但是,对于您的两个域,同一商店(默认一个)正在加载。这是因为您没有指定要为哪个域加载哪个商店。对于magento,您的两个域是陌生人,因此它将为每个域加载默认存储。

因此,我们想告知magento,对于每个域,应加载特定的商店。商店正在index.php本身(在根目录中)加载。

请转到index.php文件,您将看到加载欲望存储和存储视图的最后一行。我们需要改变它,以便magento根据我们的需要加载正确的商店。

因此,请在此代码段Mage::run($mageRunCode, $mageRunType);

上方添加以下代码
 switch($_SERVER['HTTP_HOST']) {
     case 'firstdomain.com':
     case 'www.firstdomain.com':
          $mageRunCode = 'store_code'; //not your website code, it should be code for your first store
          $mageRunType = 'store'; //it should be 'store', since you have multiple stores.Another possible value is 'website'
           break;
     case 'seconddomain.com':
     case 'www.seconddomain.com':
           $mageRunCode = 'store_code'; //code of second store
           $mageRunType = 'store';
           break;
}
Mage::run($mageRunCode, $mageRunType);

希望有帮助...

相关问题