【问题标题】:Magento Mutliple Stores Issue - second domain is loading the default store productsMagento 多个商店问题 - 第二个域正在加载默认商店产品
【发布时间】:2014-03-25 20:49:11
【问题描述】:

我在一个 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 是第二家商店的“网站名称”代码,而不是“商店视图名称”,但它们都不起作用。我不确定所有反斜杠的用途,但它们在我读过的所有教程中都有。我还检查了 Secure 和 Unsecure 部分中的 Base 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);

【问题讨论】:

  • 您必须为商店指定根类别。
  • 嗨,我为每个商店有两个根类别,对于“管理商店”部分中的商店视图,我已将“鞋店”指定为根类别而不是“默认类别”,请执行我需要在其他地方做吗?
  • 你清除缓存了吗?
  • 我暂时禁用了缓存,我重新索引了数据,但它仍然是即将出现的主要商店视图。
  • 你能按 index.php 显示第二个商店吗

标签: magento


【解决方案1】:

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

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

请转到 index.php 文件,您将看到加载欲望商店和商店视图的最后一行。我们需要对其进行一些更改,以便 magento 可以根据我们的需要加载正确的商店。

所以在这段代码的正上方添加下面的代码sn -p 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);

希望对您有所帮助...

【讨论】:

  • 谢谢,但是我添加了代码并且问题仍然存在(index.php 代码现在在我原来的问题中)。我正在使用帧转发将第二个域指向主域/安装,这是正确的方法吗?使用我的托管帐户,可以使用以下选项“停车、单页网站、标准转发、帧转发、网站 (Apache)”。我认为帧转发是正确的选择,但我可能错了。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-03-07
  • 2014-02-21
  • 1970-01-01
  • 2011-05-18
  • 1970-01-01
相关资源
最近更新 更多