【发布时间】:2015-05-05 09:24:49
【问题描述】:
我们将时事通讯订阅者存储在 Magento 的单独数据库中,因此当用户注册帐户时,我们需要将他们的地址添加到该数据库中。
代码位于此处:
/app/code/core/Mage/Newsletter/Model/Subscriber.php
相关功能(我认为)是 subscribeCustomer。
如果我将代码插入此函数的顶部,它会将用户的电子邮件地址添加到单独的数据库中,这很棒。但是,无论是否勾选了“订阅时事通讯”框,它都会执行此操作。
我对 PHP 还很陌生,所以很难弄清楚代码在复选框的位置。它在这个函数的某个地方吗?
public function subscribeCustomer($customer)
{
$this->loadByCustomer($customer);
if ($customer->getImportMode()) {
$this->setImportMode(true);
}
if (!$customer->getIsSubscribed() && !$this->getId()) {
// If subscription flag not set or customer is not a subscriber
// and no subscribe below
return $this;
}
if(!$this->getId()) {
$this->setSubscriberConfirmCode($this->randomSequence());
}
/*
* Logical mismatch between customer registration confirmation code and customer password confirmation
*/
$confirmation = null;
if ($customer->isConfirmationRequired() && ($customer->getConfirmation() != $customer->getPassword())) {
$confirmation = $customer->getConfirmation();
}
$sendInformationEmail = false;
if ($customer->hasIsSubscribed()) {
$status = $customer->getIsSubscribed()
? (!is_null($confirmation) ? self::STATUS_UNCONFIRMED : self::STATUS_SUBSCRIBED)
: self::STATUS_UNSUBSCRIBED;
/**
* If subscription status has been changed then send email to the customer
*/
if ($status != self::STATUS_UNCONFIRMED && $status != $this->getStatus()) {
$sendInformationEmail = true;
}
} elseif (($this->getStatus() == self::STATUS_UNCONFIRMED) && (is_null($confirmation))) {
$status = self::STATUS_SUBSCRIBED;
$sendInformationEmail = true;
} else {
$status = ($this->getStatus() == self::STATUS_NOT_ACTIVE ? self::STATUS_UNSUBSCRIBED : $this->getStatus());
}
if($status != $this->getStatus()) {
$this->setIsStatusChanged(true);
}
$this->setStatus($status);
if(!$this->getId()) {
$storeId = $customer->getStoreId();
if ($customer->getStoreId() == 0) {
$storeId = Mage::app()->getWebsite($customer->getWebsiteId())->getDefaultStore()->getId();
}
$this->setStoreId($storeId)
->setCustomerId($customer->getId())
->setEmail($customer->getEmail());
} else {
$this->setStoreId($customer->getStoreId())
->setEmail($customer->getEmail());
}
$this->save();
$sendSubscription = $customer->getData('sendSubscription') || $sendInformationEmail;
if (is_null($sendSubscription) xor $sendSubscription) {
if ($this->getIsStatusChanged() && $status == self::STATUS_UNSUBSCRIBED) {
$this->sendUnsubscriptionEmail();
} elseif ($this->getIsStatusChanged() && $status == self::STATUS_SUBSCRIBED) {
$this->sendConfirmationSuccessEmail();
}
}
return $this;
}
【问题讨论】: