Пример #1
0
 public function removeSegment($observer)
 {
     if ($observer->getSegmentCode()) {
         try {
             foreach (Mage::app()->getStores() as $store) {
                 AW_Advancednewsletter_Model_Sync_Mailchimpclient::getInstance($store->getId())->removeSegment($observer->getSegmentCode());
             }
         } catch (Exception $ex) {
         }
     }
 }
Пример #2
0
 public function syncToMailchimp()
 {
     self::$_massSyncFlag = true;
     $syncToParams = Mage::getModel('advancednewsletter/cache')->loadCache('aw_advancednewsletter_mailchimp_to_params');
     if (!$syncToParams) {
         return;
     }
     $syncToParams = unserialize($syncToParams);
     if (!isset($syncToParams['sync_for']) || !isset($syncToParams['include_names']) || !isset($syncToParams['sync_stores'])) {
         return;
     }
     $syncFor = $syncToParams['sync_for'];
     $includeNames = $syncToParams['include_names'];
     $currentPage = Mage::getModel('advancednewsletter/cache')->loadCache('aw_advancednewsletter_mailchimp_to_page');
     if (!$currentPage) {
         $currentPage = 1;
     }
     $subscribersCollection = Mage::getModel('advancednewsletter/subscriber')->getCollection()->addStoreFilter($syncToParams['sync_stores']);
     if ($subscribersCollection->getSize() < ($currentPage - 1) * self::SYNC_TO_MAILCHIMP_PAGE_SIZE) {
         Mage::getModel('advancednewsletter/cache')->removeCache('aw_advancednewsletter_mailchimp_to_params');
         Mage::getModel('advancednewsletter/cache')->removeCache('aw_advancednewsletter_mailchimp_to_page');
         return;
     }
     $subscribers = $subscribersCollection->setPageSize(self::SYNC_TO_MAILCHIMP_PAGE_SIZE)->setCurPage($currentPage);
     switch ($syncFor) {
         case AW_Advancednewsletter_Block_Adminhtml_Synchronization::SYNC_SUBSCRIBED:
             $subscribers->addFilterSubscribed();
             break;
         case AW_Advancednewsletter_Block_Adminhtml_Synchronization::SYNC_UNSUBSCRIBED:
             $subscribers->addFilterUnsubscribed();
             break;
         default:
             $subscribers->addFilterSubscribedUnsubscribed();
             break;
     }
     $syncWithErrorsFlag = false;
     foreach ($subscribers as $subscriber) {
         try {
             if ($subscriber->getStatus() == AW_Advancednewsletter_Model_Subscriber::STATUS_SUBSCRIBED) {
                 AW_Advancednewsletter_Model_Sync_Mailchimpclient::getInstance($subscriber->getStoreId())->setSkipChangesCheck(true)->setIncludeNames($includeNames)->subscribe($subscriber);
             }
             if ($subscriber->getStatus() == AW_Advancednewsletter_Model_Subscriber::STATUS_UNSUBSCRIBED) {
                 AW_Advancednewsletter_Model_Sync_Mailchimpclient::getInstance($subscriber->getStoreId())->setSkipChangesCheck(true)->setIncludeNames($includeNames)->subscribe($subscriber)->unsubscribeFromList($subscriber);
             }
         } catch (Exception $ex) {
             $syncWithErrorsFlag = true;
         }
     }
     Mage::getModel('advancednewsletter/cache')->saveCache($currentPage + 1, 'aw_advancednewsletter_mailchimp_to_page');
     self::$_massSyncFlag = false;
 }
Пример #3
0
 protected function _exportSubsPage($storeId, $type, $page, $pageSize, $includeNames)
 {
     if ($page === 'none') {
         return 'none';
     }
     $subscribers = $this->_getSubscibersPack($storeId, $type, $page, $pageSize);
     if (!count($subscribers)) {
         return 'none';
     }
     switch ($type) {
         case 'subscribed':
             $batch = $this->_getSubsBatch($subscribers, $includeNames, TRUE);
             AW_Advancednewsletter_Model_Sync_Mailchimpclient::getInstance($storeId)->batchSubscribe($batch);
             break;
         case 'unsubscribed':
             /*
              *   1) unsubscribe batch with 'delete_members' to delete old data
              *   2) subscribe batch to list to add new data
              *   3) unsubscribe this batch to change status
              */
             $batch = $this->_getSubsBatch($subscribers, $includeNames);
             $email = array();
             foreach ($batch as $subscriber) {
                 $email[] = $subscriber['EMAIL'];
             }
             AW_Advancednewsletter_Model_Sync_Mailchimpclient::getInstance($storeId)->batchUnsubscribe($email, TRUE);
             AW_Advancednewsletter_Model_Sync_Mailchimpclient::getInstance($storeId)->batchSubscribe($batch);
             AW_Advancednewsletter_Model_Sync_Mailchimpclient::getInstance($storeId)->batchUnsubscribe($email, FALSE);
             break;
         default:
             break;
     }
     return $page + 1;
 }