-
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 branch 'develop' into webhook-error-fix
- Loading branch information
Showing
11 changed files
with
337 additions
and
16 deletions.
There are no files selected for viewing
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; | ||
} | ||
} |
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
35 changes: 35 additions & 0 deletions
35
app/code/community/Ebizmarts/MailChimp/Model/System/Config/Source/Checkoutsubscribe.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,35 @@ | ||
<?php | ||
|
||
/** | ||
* Checkout subscribe available status options source | ||
* | ||
* @category Ebizmarts | ||
* @package Ebizmarts_MailChimp | ||
* @author Ebizmarts Team <[email protected]> | ||
* @license http://opensource.org/licenses/osl-3.0.php | ||
*/ | ||
class Ebizmarts_MailChimp_Model_System_Config_Source_Checkoutsubscribe | ||
{ | ||
const DISABLED = 0; | ||
const CHECKED_BY_DEFAULT = 1; | ||
const NOT_CHECKED_BY_DEFAULT = 2; | ||
const FORCE_HIDDEN = 3; | ||
const FORCE_VISIBLE = 4; | ||
|
||
/** | ||
* Options getter | ||
* | ||
* @return array | ||
*/ | ||
public function toOptionArray() | ||
{ | ||
$helper = Mage::helper('mailchimp'); | ||
return array( | ||
array('value' => self::CHECKED_BY_DEFAULT, 'label' => $helper->__('Enabled - Checked by default')), | ||
array('value' => self::NOT_CHECKED_BY_DEFAULT, 'label' => $helper->__('Enabled - Not Checked by default')), | ||
array('value' => self::FORCE_HIDDEN, 'label' => $helper->__('Enabled - Force subscription hidden')), | ||
array('value' => self::FORCE_VISIBLE, 'label' => $helper->__('Enabled - Force subscription')), | ||
array('value' => self::DISABLED, 'label' => $helper->__('-- Disabled --')) | ||
); | ||
} | ||
} |
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
102 changes: 102 additions & 0 deletions
102
app/design/frontend/base/default/template/ebizmarts/mailchimp/checkout/subscribe.phtml
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,102 @@ | ||
<?php | ||
$force = $this->isForceEnabled(); | ||
$check = $this->isChecked(); | ||
$hidden = $this->isForceHidden(); | ||
$addToPostOnLoad = $this->addToPostOnLoad(); | ||
$generalList = $this->getGeneralList(); | ||
?> | ||
<script type="text/javascript"> | ||
addSubscribeToPost = function (element) { | ||
|
||
//save old clicked lists and then removes element | ||
var subscribeValue = ''; | ||
var checkedLists = ''; | ||
<?php if (!$force) : ?> | ||
if ($('mailchimp-subscribe')) { | ||
checkedLists = $('mailchimp-subscribe').getValue(); | ||
subscribeValue = checkedLists + ','; | ||
$('mailchimp-subscribe').remove(); | ||
} | ||
<?php endif; ?> | ||
|
||
var hidden = false; | ||
<?php if ($hidden) : ?> | ||
hidden = true; | ||
<?php endif; ?> | ||
//if checked add this element else remove it | ||
if (element.checked || hidden) { | ||
var inputer = new Element('input', { | ||
name: "mailchimp_subscribe", | ||
id: "mailchimp-subscribe", | ||
value: subscribeValue + element.readAttribute('value'), | ||
type: "hidden" | ||
}); | ||
// var listValue = new Element('input', { | ||
// name: element.readAttribute('name'), | ||
// id: "subscribe-" + element.readAttribute('value'), | ||
// value: element.readAttribute('value'), | ||
// type: "hidden" | ||
// }); | ||
try { | ||
Element.insert(Form.findFirstElement(payment.form), inputer); | ||
// Element.insert(Form.findFirstElement(payment.form), listValue); | ||
|
||
} catch (notelem) { | ||
$("co-payment-form").insert(inputer); | ||
// $("co-payment-form").insert(listValue); | ||
} | ||
} else { | ||
alert(element.readAttribute('value')); | ||
var arrCheckedLists = checkedLists.split(','); | ||
var pos = arrCheckedLists.indexOf(element.readAttribute('value')); | ||
alert(pos); | ||
if (pos != -1) { | ||
arrCheckedLists.splice(pos, 1); | ||
checkedLists = arrCheckedLists.join(','); | ||
var inputer = new Element('input', { | ||
name: "mailchimp_subscribe", | ||
id: "mailchimp-subscribe", | ||
value: checkedLists, | ||
type: "hidden" | ||
}); | ||
if (inputer.value) { | ||
try { | ||
Element.insert(Form.findFirstElement(payment.form), inputer); | ||
} catch (notelem) { | ||
$("co-payment-form").insert(inputer); | ||
} | ||
} | ||
} | ||
} | ||
|
||
}; | ||
</script> | ||
<div class="buttons-set"<?php if ($hidden) : ?> style="display:none;"<?php endif; ?>> | ||
<!-- General Subscription --> | ||
<div class="page-title"> | ||
<h1><?php echo $this->__('Newsletter Subscription'); ?></h1> | ||
</div> | ||
<?php echo $this->getBlockHtml('formkey'); ?> | ||
<div class="mailchimp-multisubscribe"> | ||
<ul class="mailchimp-general-list"> | ||
<li class="listdata"> | ||
<input<?php if ($check): ?> checked="checked"<?php endif; ?> type="checkbox" | ||
onchange="addSubscribeToPost(this);" | ||
name="list[<?php echo $generalList; ?>][subscribed]" | ||
id="mailchimp-trigger" | ||
value="<?php echo $generalList; ?>" | ||
title="<?php echo $generalList; ?>" | ||
class="mailchimp-list-subscriber"/> | ||
<label style="padding-left: 6px;" | ||
for="mailchimp-trigger"><?php echo $this->__('General Subscription'); ?></label> | ||
</li> | ||
</ul> | ||
</div> | ||
<!-- General Subscription --> | ||
</div> | ||
|
||
<script type="text/javascript"> | ||
//If force subscription or checked by default set the elements as clicked | ||
<?php if($addToPostOnLoad):?>addSubscribeToPost($('mailchimp-trigger')); | ||
<?php endif; ?> | ||
</script> |
Oops, something went wrong.