Skip to content

Commit

Permalink
Merge pull request #9 from codeblanche/master
Browse files Browse the repository at this point in the history
Fixes and improvements for v1.0.14
  • Loading branch information
mertenvg committed Sep 2, 2015
2 parents f69becb + 62a6708 commit b197f8e
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 52 deletions.
39 changes: 2 additions & 37 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,42 +1,7 @@
#
# Ignore all
#

# Ignore all magento files
*

#
# Except path to module files.
#
# note: Each level up the inclusion must be specified as an individual entry.
#

!public/
!public/app/
!public/app/code/
!public/app/code/community/
!public/app/code/community/Laposta/
# Except for connect-magento project files
!public/app/code/community/Laposta/*
!public/app/code/community/Laposta/*/*
!public/app/code/community/Laposta/*/*/*
!public/app/code/community/Laposta/*/*/*/*
!public/app/code/community/Laposta/*/*/*/*/*
!public/app/code/community/Laposta/*/*/*/*/*/*
!public/app/code/community/Laposta/*/*/*/*/*/*/*
!public/app/code/community/Laposta/*/*/*/*/*/*/*/*
!public/app/code/community/Laposta/*/*/*/*/*/*/*/*/*
!public/app/locale/
!public/app/locale/en_US/
!public/app/locale/en_US/Laposta_Connect.csv
!public/app/etc/
!public/app/etc/modules/
!public/app/etc/modules/Laposta_Connect.xml
!public/app/design/
!public/app/design/frontend/
!public/app/design/frontend/base/
!public/app/design/frontend/base/default/
!public/app/design/frontend/base/default/layout/
!public/app/design/frontend/base/default/layout/lapostaconnect.xml
!public/lib/
!public/lib/Laposta/
!public/lib/Laposta/*
!public/lib/Laposta/*/*
6 changes: 6 additions & 0 deletions public/app/code/community/Laposta/Connect/Helper/Sync.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,15 +83,21 @@ public function syncList(Laposta_Connect_Model_List $list)
if (empty($listName)) {
$listName = '(Empty List Name - Magento)';

$this->log('Creating new list', $listName);

$list->setListName($listName);
}

if (empty($lapostaId)) {
$this->log("Creating new list", $listName);

$lapostaId = $laposta->addGroup($listName);

$list->setLapostaId($lapostaId);
}
else {
$this->log('Updating list', array('listName' => $listName, 'lapostId' => $lapostaId));

$laposta->updateGroup($lapostaId, $listName);
}

Expand Down
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
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public static function connect($data)

// check for CURL error
if ($response['error']) {
throw new Laposta_Error('Connection error: ' . $response['error_msg'], $response['status'], $response['body']);
throw new Laposta_Error('Connection error: ' . $response['error_msg'] . '(' . json_encode($data) . ')', $response['status'], $response['body']);
}

// decode JSON
Expand Down

0 comments on commit b197f8e

Please sign in to comment.