Skip to content

Commit

Permalink
Merge pull request #1 from codeblanche/feature/compat-magento-1.9.1
Browse files Browse the repository at this point in the history
Fixed fatal error with newsletter subscribe event observer
  • Loading branch information
mertenvg committed Sep 2, 2015
2 parents a48de50 + c439f11 commit 62a6708
Showing 1 changed file with 18 additions and 14 deletions.
32 changes: 18 additions & 14 deletions public/app/code/community/Laposta/Connect/Model/Observer.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,35 +75,39 @@ public function handleNewsletterSubscriberSave(Varien_Event_Observer $observer)

/** @var $collection Laposta_Connect_Model_Mysql4_Subscriber_Collection */
$collection = Mage::getModel('lapostaconnect/subscriber')->getCollection();
$customerId = $nativeSubscriber->getCustomerId();

/*
* find laposta subscriber by subscriber id
*/

/** @var $subscriber Laposta_Connect_Model_Subscriber */
$subscriber = $collection->getItemByColumnValue('newsletter_subscriber_id', $nativeSubscriber->getId());
$customerId = $nativeSubscriber->getCustomerId();

/*
* if not found and customer id is not '0' it could be a legacy record
*/

if ($customerId != "0" && (!$subscriber instanceof Laposta_Connect_Model_Subscriber || $subscriber->isEmpty())) {
if ($subscriber instanceof Laposta_Connect_Model_Subscriber && !$subscriber->isEmpty()) {
/*
* Subscriber already exists. No need to continue.
*/
return;
}
else if ($customerId != "0") {
/*
* if not found and customer id is not '0' it could be a legacy record
*/
$subscriber = $collection->getItemByColumnValue('customer_id', $customerId);
}

if ($subscriber instanceof Laposta_Connect_Model_Subscriber && !$subscriber->isEmpty()) {
/*
* update entries stored without a newsletter_subscriber_id
* If subscriber is found then update the newsletter subscriber id
*/

$subscriber->setNewsletterSubscriberId($nativeSubscriber->getId());
$subscriber->save();
}

/*
* if subscriber still doesn't exist then it really doesn't exist yet.
*/

if (!$subscriber instanceof Laposta_Connect_Model_Subscriber || $subscriber->isEmpty()) {
else {
/*
* if subscriber still doesn't exist then it really doesn't exist yet.
*/
/** @var $lists Laposta_Connect_Model_Mysql4_List_Collection */
$lists = Mage::getModel('lapostaconnect/list')->getCollection();
/** @var $list Laposta_Connect_Model_List */
Expand Down

0 comments on commit 62a6708

Please sign in to comment.