Magento Observer - 从订单对象获取新闻订阅

时间:2014-03-20 19:21:00

标签: magento checkout newsletter observers

我可以从$observer对象调用什么来确定访客或客户是否在结帐时点击了订阅复选框?到目前为止,我有这个:

public function collectCustomerData($observer)
{
    $this->observer = $observer;
    $this->_order = $this->observer->getEvent()->getOrder();
    $this->_address = $this->_order->getShippingAddress();
    $this->data['first_name'] = $this->_address->getFirstname();
    $this->data['last_name'] = $this->_address->getLastname();
    $this->data['city'] = $this->_address->getCity();
    $this->data['email'] = $this->_order->getCustomerEmail();
}

但是我需要从$this->data['is_newsletter'](Mage_Sales_Model_Order)或$this->_order(Mage_Sales_Model_Order_Address)添加$this->_address,或者通过静态工厂方法(如Mage)提取具有该信息的其他模型: :getModel()如果我需要

1 个答案:

答案 0 :(得分:0)

我想通了,我必须将newsletter/subscriber模型带入等式中。以下代码返回1或null:

$email = $this->_order->getCustomerEmail();
$isNewsletter = Mage::getModel('newsletter/subscriber')
    ->loadByEmail($email)
    ->getSubscriberStatus();

基于此,我能够适当地设置opt in标志:

$this->data['is_newsletter'] = $isNewsletter;