-
Notifications
You must be signed in to change notification settings - Fork 94
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #411 from mailchimp/develop
Merge release to master
- Loading branch information
Showing
38 changed files
with
1,537 additions
and
735 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
123 changes: 123 additions & 0 deletions
123
app/code/community/Ebizmarts/MailChimp/Block/Checkout/Subscribe.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
<?php | ||
|
||
/** | ||
* Checkout subscribe checkbox block renderer | ||
* | ||
* @category Ebizmarts | ||
* @package Ebizmarts_MageMonkey | ||
* @author Ebizmarts Team <[email protected]> | ||
* @license http://opensource.org/licenses/osl-3.0.php | ||
*/ | ||
class Ebizmarts_MailChimp_Block_Checkout_Subscribe extends Mage_Core_Block_Template | ||
{ | ||
|
||
protected $_lists = array(); | ||
protected $_info = array(); | ||
protected $_myLists = array(); | ||
protected $_generalList = array(); | ||
protected $_form; | ||
protected $_api; | ||
protected $helper; | ||
protected $storeId; | ||
|
||
public function __construct() | ||
{ | ||
parent::__construct(); | ||
$this->helper = Mage::helper('mailchimp'); | ||
$this->storeId = Mage::app()->getStore()->getId(); | ||
} | ||
|
||
/** | ||
* Render block HTML | ||
* | ||
* @return string | ||
*/ | ||
protected function _toHtml() | ||
{ | ||
$helper = $this->helper; | ||
$storeId = $this->storeId; | ||
|
||
$alreadySubscribed = Mage::getModel('newsletter/subscriber') | ||
->loadByEmail($this->getQuote()->getCustomerEmail()) | ||
->isSubscribed(); | ||
|
||
if ($helper->isCheckoutSubscribeEnabled($storeId) && !$alreadySubscribed) { | ||
return parent::_toHtml(); | ||
} else { | ||
return ''; | ||
} | ||
} | ||
|
||
/** | ||
* Retrieve current quote object from session | ||
* | ||
* @return Mage_Sales_Model_Quote | ||
*/ | ||
protected function getQuote() | ||
{ | ||
return Mage::getSingleton('checkout/session') | ||
->getQuote(); | ||
} | ||
|
||
protected function getCurrentCheckoutSubscribeValue() | ||
{ | ||
return $this->helper->getCheckoutSubscribeValue($this->storeId); | ||
} | ||
|
||
protected function isForceHidden($currentValue = null) | ||
{ | ||
if (!$currentValue) { | ||
$currentValue = $this->getCurrentCheckoutSubscribeValue(); | ||
} | ||
return ($currentValue == Ebizmarts_MailChimp_Model_System_Config_Source_Checkoutsubscribe::FORCE_HIDDEN); | ||
} | ||
|
||
protected function isForceVisible($currentValue) | ||
{ | ||
return ($currentValue == Ebizmarts_MailChimp_Model_System_Config_Source_Checkoutsubscribe::FORCE_VISIBLE); | ||
} | ||
|
||
protected function isCheckedByDefault($currentValue) | ||
{ | ||
return ($currentValue == Ebizmarts_MailChimp_Model_System_Config_Source_Checkoutsubscribe::CHECKED_BY_DEFAULT); | ||
} | ||
|
||
public function isForceEnabled() | ||
{ | ||
$currentValue = $this->getCurrentCheckoutSubscribeValue(); | ||
if ($this->isForceHidden($currentValue) || $this->isForceVisible($currentValue)) { | ||
return true; | ||
} | ||
return false; | ||
} | ||
|
||
public function isChecked() | ||
{ | ||
$currentValue = $this->getCurrentCheckoutSubscribeValue(); | ||
if ($this->isCheckedByDefault($currentValue) || $this->isForceVisible($currentValue)) { | ||
return true; | ||
} | ||
return false; | ||
} | ||
|
||
public function addToPostOnLoad() | ||
{ | ||
return ($this->isChecked() || $this->isForceHidden()); | ||
} | ||
|
||
/** | ||
* Get list data from MC | ||
* | ||
* @return array | ||
*/ | ||
public function getGeneralList() | ||
{ | ||
$storeId = $this->storeId; | ||
$helper = $this->helper; | ||
$listId = $helper->getGeneralList($storeId); | ||
|
||
//@Todo add support for intetest groups | ||
|
||
return $listId; | ||
} | ||
} |
Oops, something went wrong.