我创建了一个自定义模块来向Mage/Checkout/Model/Type/Onepage.php中包含的 Checkout Model saveBilling()函数添加一个事件。除了每次调用事件都正确触发之外,模块现在偶尔会抛出错误:
Notice: Undefined property: Fla_Checkout_Model_Type_Onepage::$_customerEmailExistsMessage
in /home/magento/public_html/app/code/local/Fla/Checkout/Model/Type/Onepage.php
on line 154
模块的相关位,公共函数 saveBilling()中的代码除了dispatchEvent()行及其前面的注释外与 Magento 核心完全相同。引发错误的部分:
<?php
class Fla_Checkout_Model_Type_Onepage extends Mage_Checkout_Model_Type_Onepage {
public function saveBilling($data, $customerAddressId) {
/* much code removed here as not relevant to question */
/* This section throws error because $this->_customerEmailExistsMessage not found */
if (!$this->getQuote()->getCustomerId() && self::METHOD_REGISTER == $this->getQuote()->getCheckoutMethod()) {
if ($this->_customerEmailExists($address->getEmail(), Mage::app()->getWebsite()->getId())) {
return array('error' => 1, 'message' => $this->_customerEmailExistsMessage);
}
}
/* much code removed here as not relevant to question, below code works as intended*/
/* Fiascolabs added event for exporting billing data */
Mage::dispatchEvent('fla_billing_export', array('quote'=>$this->getQuote()));
return array();
}
}
当我查阅 Magento 核心代码时,在顶部,我声明了几个似乎在函数覆盖中无法访问的项目。
我的模块可以使用常量和公共函数 __construct()吗?
我只需要复制申报的私人物品吗?
有问题的代码如下:
/**
* Checkout types: Checkout as Guest, Register, Logged In Customer
*/
const METHOD_GUEST = 'guest';
const METHOD_REGISTER = 'register';
const METHOD_CUSTOMER = 'customer';
/**
* Error message of "customer already exists"
*
* @var string
*/
private $_customerEmailExistsMessage = '';
/**
* Class constructor
* Set customer already exists message
*/
public function __construct()
{
$this->_helper = Mage::helper('checkout');
$this->_customerEmailExistsMessage = $this->_helper->__('There is already a customer registered using this email address. Please login using this email address or enter a different email address to register your account.');
$this->_checkoutSession = Mage::getSingleton('checkout/session');
$this->_customerSession = Mage::getSingleton('customer/session');
}