2

我正在为 Magento 开发一个调用 Web 服务并添加 cookie 的模块。我希望在保存用户时调用类中的方法( customer_save_after )。在本地主机上开发时,我能够以某种方式使其工作,但在我尝试实现它的实时站点上出现此错误:

法师注册表键“_singleton/Eight18_Aqui4_Model_Observer”已经存在

这里有一个类似的线程,但它忽略了如何解决问题的实际细节。

这是我的 config.xml:(customer_save_after 事件似乎是错误开始的地方)

<?xml version="1.0"?>
<config>
    <global>
        <helpers>
            <aqui4>
                <class>Eight18_Aqui4_Helper</class>
            </aqui4>
        </helpers>
        <modules>
                <Eight18_aqui4>
                        <version>0.1.0</version>
                </Eight18_aqui4>
        </modules>
    </global>
    <adminhtml>
    <acl>
        <resources>
            <all>
                <title>Allow Everything</title>
            </all>
        <admin>
            <children>
            <Eight18_Aqui4>
                <title>Aqui4 Module</title>
                <sort_order>10</sort_order>
            </Eight18_Aqui4>
            </children>
        </admin>
        </resources>
    </acl>
    <layout>
        <updates>
        <aqui4>
            <file>aqui4.xml</file>
        </aqui4>
        </updates>
    </layout>
    </adminhtml>

    <default>
        <main>
            <enable>1</enable>
            <siteid>0</siteid>
            <sitetoken>0</sitetoken>
        </main>
    </default>


    <frontend>
        <events>
            <customer_save_after>
            <observers>
                <aqui4_observer>
                    <class>Eight18_Aqui4_Model_Observer</class>
                    <method>start_aqui4</method>
                </aqui4_observer>
            </observers>
        </customer_save_after>
        </events>
        <routers>
            <aqui4>
                <use>standard</use>
                <args>
                    <module>Eight18_Aqui4</module>
                    <frontName>aqui4</frontName>
                </args>
            </aqui4>
        </routers>
        <layout>
            <updates>
                <aqui4>
                      <file>aqui4.xml</file>
                </aqui4>
            </updates>
            </layout>
        </frontend>
</config>

/公司/模块/模型/observer.php:

Public function start_aqui4() {//THIS IS CALLED BY THE EVENT OBSERVER ON CUSTOMER CREATION
    // get variables
    $userEmail = Mage::helper('aqui4')->getUserEmail();
    $userFirstName = Mage::helper('aqui4')->getUserFirstName();
    $userLastName = Mage::helper('aqui4')->getUserLastName();
    $siteID = Mage::helper('aqui4')->getSiteID();
    $siteToken = Mage::helper('aqui4')->getSiteToken();
    $expire=time()+60*60*24*30.42*6;//THE LAST NUMBER IS THE MONTHS
    $randomNumber = rand(0, pow(10, 5));//SERVICE EXPECTS RAND NUMBER

    if(isset( $_COOKIE['aqui4userid'] )){//CHECK TO SEE IF USER ALREADY HAS A COOKIE
        return;
    }
    else{//CHANGE JSON DATA SO JSON_DECODE CAN READ IT
        $getContent = file_get_contents("http://www.domain.com/service.ashx?siteId=" . $siteID . "&token=" . $siteToken . "&email=" . $userEmail . "&data={\"firstName\":\"" . $userFirstName . "\",\"lastName\":\"" . $userLastName . "\",\"email\":\"" . $userEmail . "\",\"company\":\"\",\"position\":\"\",\"country\":\"\"}", true);
        $getContent = str_replace('function __authenticate() ', '', $getContent);
        $getContent = str_replace('{ return ', '', $getContent);
        $getContent = str_replace(';}', '', $getContent);
        $getContent = str_replace('\'', '"', $getContent);
        $getContent = str_replace(': "', ':"', $getContent);

        //SET THE USER ID AND ERROR VARS BASED ON DATA PASSED BACK
        $getContentArray = json_decode($getContent, true);
        $error = $getContentArray['HasError'];
        $userID = $getContentArray['UserId'];

        if($error){
            if($error != "True"){//SERVICE RETURNS NO ERROR
                setcookie("aqui4userid", $userID, $expire);
                return;
            }
            else{//NO COOKIE SET - USER WAS NOT ADDED
                return;
            }
        }
    }
}

}

最后是 system.log 文件:

2012-07-24T23:21:52+00:00 ERR (3): Warning: include(/var/www/clients/client3/web4/web/includes/src/Eight18_Aqui4_Model_Observer.php): failed to open stream: No such file or directory  in /var/www/clients/client3/web4/web/includes/src/Varien_Autoload.php on line 93
2012-07-24T23:21:52+00:00 ERR (3): Warning: include(): Failed opening '/var/www/clients/client3/web4/web/includes/src/Eight18_Aqui4_Model_Observer.php' for inclusion (include_path='/var/www/clients/client3/web4/web/includes/src:.:/usr/share/php:/usr/share/pear')  in /var/www/clients/client3/web4/web/includes/src/Varien_Autoload.php on line 93
2012-07-24T23:21:52+00:00 ERR (3): Warning: include(/var/www/clients/client3/web4/web/includes/src/Eight18_Aqui4_Model_Observer.php): failed to open stream: No such file or directory  in /var/www/clients/client3/web4/web/includes/src/Varien_Autoload.php on line 93
2012-07-24T23:21:52+00:00 ERR (3): Warning: include(): Failed opening '/var/www/clients/client3/web4/web/includes/src/Eight18_Aqui4_Model_Observer.php' for inclusion (include_path='/var/www/clients/client3/web4/web/includes/src:.:/usr/share/php:/usr/share/pear')  in /var/www/clients/client3/web4/web/includes/src/Varien_Autoload.php on line 93
2012-07-24T23:21:54+00:00 ERR (3): Warning: include(/var/www/clients/client3/web4/web/includes/src/Eight18_Aqui4_Model_Observer.php): failed to open stream: No such file or directory  in /var/www/clients/client3/web4/web/includes/src/Varien_Autoload.php on line 93
2012-07-24T23:21:54+00:00 ERR (3): Warning: include(): Failed opening '/var/www/clients/client3/web4/web/includes/src/Eight18_Aqui4_Model_Observer.php' for inclusion (include_path='/var/www/clients/client3/web4/web/includes/src:.:/usr/share/php:/usr/share/pear')  in /var/www/clients/client3/web4/web/includes/src/Varien_Autoload.php on line 93
4

1 回答 1

2

简短版本:您的生产系统正在“编译器模式”下运行,并且您尚未编译模块类。

您的生产服务器在 Magento 的“编译器模式”(自链接)打开的情况下运行。您可以通过 Magento's logging 的错误消息来判断

ERR (3): Warning: include(): Failed opening '/var/www/clients/client3/web4/web/includes/src/Eight18_Aqui4_Model_Observer.php' 
for inclusion (include_path='/var/www/clients/client3/web4/web/includes/src:.:/usr/share/php:/usr/share/pear')  in /var/www/clients/client3/web4/web/includes/src/Varien_Autoload.php on line 93

Magento 正在寻找includes/src课程。那是放置编译类的地方。此外,PHP 正在尝试包含一个完全下划线的文件名Eight18_Aqui4_Model_Observer.php。这只发生在编译器模式打开时。

当您将模块更改推送到生产环境时,您需要重新编译您的模块。你可以从

System -> Tools -> Compilation

或使用命令行编译器脚本

$ php shell/compiler.php
Usage:  php -f compiler.php -- [options]

  state         Show Compilation State
  compile       Run Compilation Process
  clear         Disable Compiler include path and Remove compiled files
  enable        Enable Compiler include path
  disable       Disable Compiler include path
  help          This help
于 2012-07-25T00:02:03.727 回答