magento Url第一次没有工作

时间:2016-05-16 06:51:25

标签: magento

当我们打开网站时:http://ab1.domain.com/

首次在浏览器中,它会重定向到以下网址

http://ab1.domain.com/://index.php/? &安培;给 404 Not Found 1

://index.php /?正在添加后缀。但如果我们第二次开放,那么它的工作正常。

它的多店铺网站,当我们禁用所有商店时,仍然存在问题。

这是自定义模块的问题,我们使用此模块根据国家/地区显示各自的货币。

Data.php

<?php
/**
 * Atwix
 *
 * 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.
 *
 * @category    Atwix Mod
 * @package     Atwix_Ipstoreswitcher
 * @author      Atwix Core Team
 * @copyright   Copyright (c) 2014 Atwix (http://www.atwix.com)
 * @license     http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
 */
/* app/code/local/Atwix/Ipstoreswitcher/Helper/Data.php */
class Atwix_Ipstoreswitcher_Helper_Data extends Mage_Core_Helper_Abstract
{
    const DEFAULT_STORE = 'India';

    /**
     * countries to store relation
     * default is English
     * @var array
     */
    protected $_countryToStore = array(
        'IN' => 'India',
        'US' => 'USA',
        'FR' => 'France',
        'AR' => 'US dollar [$]',
       // 'BO' => 'US dollar [$]'




    );

    /**
     * get store view name by country
     * @param $country
     * @return bool
     */
    public function getStoreByCountry($country)
    {
        if (isset($this->_countryToStore[$country])) {
            return $this->_countryToStore[$country];
        }
        return self::DEFAULT_STORE;
    }
}

config.xml中

<config>
    <modules>
        <Atwix_Ipstoreswitcher>
            <version>1.0.0</version>
        </Atwix_Ipstoreswitcher>
    </modules>
    <global>
        <helpers>
            <atwix_ipstoreswitcher>
                <class>Atwix_Ipstoreswitcher_Helper</class>
            </atwix_ipstoreswitcher>
        </helpers>
        <models>
            <atwix_ipstoreswitcher>
                <class>Atwix_Ipstoreswitcher_Model</class>
            </atwix_ipstoreswitcher>
        </models>
    </global>
    <frontend>
        <events>
            <controller_action_postdispatch>
                <observers>
                    <atwix_ipstoreswitcher>
                        <class>atwix_ipstoreswitcher/observer</class>
                        <method>controllerActionPostdispatch</method>
                    </atwix_ipstoreswitcher>
                </observers>
            </controller_action_postdispatch>
        </events>
    </frontend>
</config>

Observer.php

class Atwix_Ipstoreswitcher_Model_Observer
{
    /**
     * redirects customer to store view based on GeoIP
     * @param $event
     */
    public function controllerActionPostdispatch($event)
    {
        $cookie = Mage::getSingleton('core/cookie');
        if ($cookie->get('geoip_processed') != 1) {
            $geoIPCountry = Mage::getSingleton('geoip/country');
            $countryCode = $geoIPCountry->getCountry();
            if ($countryCode) {
                $storeName = Mage::helper('atwix_ipstoreswitcher')->getStoreByCountry($countryCode);
                if ($storeName) {
                    $store = Mage::getModel('core/store')->load($storeName, 'name');
                    if ($store->getName() != Mage::app()->getStore()->getName()) {
                        $event->getControllerAction()->getResponse()->setRedirect($store->getCurrentUrl(false));
                    }
                }
            }
            $cookie->set('geoip_processed', '1', time() + 86400, '/');
        }
    }
}

修改

我尝试过的是$store->getCurrentUrl(false)替换Mage::getUrl('*/*/*', array('_use_rewrite' => true, '_forced_secure' => true))而不是url问题已解决。但模块功能不起作用。

2 个答案:

答案 0 :(得分:1)

您可以在数据库中查找(搜索)://index.php/?并在数据库中进行更改,您可以从中获取扩展名,也可以从核心文件中获取扩展名。

答案 1 :(得分:0)

<?php
/**
 * Atwix
 *
 * 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.
 *
 * @category    Atwix Mod
 * @package     Atwix_Ipstoreswitcher
 * @author      Atwix Core Team
 * @copyright   Copyright (c) 2014 Atwix (http://www.atwix.com)
 * @license     http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
 */
/* app/code/local/Atwix/Ipstoreswitcher/Model/Observer.php */

class Atwix_Ipstoreswitcher_Model_Observer
{
    /**
     * redirects customer to store view based on GeoIP
     * @param $event
     */
    public function controllerActionPostdispatch($event)
    {
        $geoIP = Mage::getSingleton('geoip/country');
            $cnCode =  $geoIP->getCountry();
       // echo $cnCode='IN';
            switch ($cnCode) {
                case "US": {
                      Mage::app()->setCurrentStore('default');
                      break;
                }
                case "IN": {
                    Mage::app()->setCurrentStore('usa');
                    break;
                }
                case "CA": {
                    Mage::app()->setCurrentStore('lca');
                    break;
                }
                default: {
                    Mage::app()->setCurrentStore('default');
                    break;
                }
                echo Mage::app()->getCurrentStore();

        }

    }
}