Created
October 7, 2020 05:28
-
-
Save DariaUshaeva/2d53e7669744f135a233886834506eb5 to your computer and use it in GitHub Desktop.
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
diff --git a/app/addons/email_marketing/controllers/frontend/checkout.post.php b/app/addons/email_marketing/controllers/frontend/checkout.post.php | |
index eadcb6c..60f4c80 100644 | |
--- a/app/addons/email_marketing/controllers/frontend/checkout.post.php | |
+++ b/app/addons/email_marketing/controllers/frontend/checkout.post.php | |
@@ -13,6 +13,7 @@ | |
****************************************************************************/ | |
use Tygh\Registry; | |
+use Tygh\Enum\YesNo; | |
if (!defined('BOOTSTRAP')) { die('Access denied'); } | |
@@ -37,8 +38,16 @@ if ($_SERVER['REQUEST_METHOD'] == 'POST') { | |
} | |
if ($mode == 'checkout') { | |
- | |
- if (Registry::get('addons.email_marketing.em_show_on_checkout') == 'Y' && !empty(Tygh::$app['session']['cart']['user_data']['email']) && !fn_em_is_email_subscribed(Tygh::$app['session']['cart']['user_data']['email'])) { | |
+ $user_email = isset($_REQUEST['user_email']) ? $_REQUEST['user_email'] : ''; | |
+ | |
+ if ( | |
+ Registry::get('addons.email_marketing.em_show_on_checkout') === YesNo::YES | |
+ && ( | |
+ !empty($user_email) | |
+ || !empty(Tygh::$app['session']['cart']['user_data']['email']) | |
+ ) | |
+ && !fn_em_is_email_subscribed($user_email ?: Tygh::$app['session']['cart']['user_data']['email']) | |
+ ) { | |
Tygh::$app['view']->assign('show_subscription_checkbox', true); | |
} | |
} |
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
diff --git a/design/themes/responsive/templates/addons/email_marketing/hooks/checkout/final_section_customer_notes.post.tpl b/design/themes/responsive/templates/addons/email_marketing/hooks/checkout/final_section_customer_notes.post.tpl | |
index 795b9a6..290e7ca 100644 | |
--- a/design/themes/responsive/templates/addons/email_marketing/hooks/checkout/final_section_customer_notes.post.tpl | |
+++ b/design/themes/responsive/templates/addons/email_marketing/hooks/checkout/final_section_customer_notes.post.tpl | |
@@ -1,6 +1,5 @@ | |
{if $show_subscription_checkbox} | |
-<div class="ty-control-group ty-checkout__terms"> | |
- <label><input type="checkbox" name="subscribe_customer" value="1" class="checkbox" {if $addons.email_marketing.em_checkout_enabled != "Y"}checked="checked"{/if} />{__("email_marketing.text_subscribe")}</label> | |
-</div> | |
- | |
-{/if} | |
\ No newline at end of file | |
+ <div class="ty-control-group ty-checkout__terms ty-checkout__terms--subscribe-customer"> | |
+ <label><input type="checkbox" name="subscribe_customer" value="1" class="checkbox" {if $addons.email_marketing.em_checkout_enabled != "Y"}checked="checked"{/if} />{__("email_marketing.text_subscribe")}</label> | |
+ </div> | |
+{/if} |
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
diff --git a/design/themes/responsive/templates/addons/email_marketing/hooks/index/scripts.post.tpl b/design/themes/responsive/templates/addons/email_marketing/hooks/index/scripts.post.tpl | |
new file mode 100644 | |
index 0000000..0079bf2 | |
--- /dev/null | |
+++ b/design/themes/responsive/templates/addons/email_marketing/hooks/index/scripts.post.tpl | |
@@ -0,0 +1 @@ | |
+{script src="js/addons/email_marketing/func.js"} | |
\ No newline at end of file |
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
diff --git a/js/addons/email_marketing/func.js b/js/addons/email_marketing/func.js | |
new file mode 100644 | |
index 0000000..ead985e | |
--- /dev/null | |
+++ b/js/addons/email_marketing/func.js | |
@@ -0,0 +1,19 @@ | |
+(function(_, $) { | |
+ $.ceEvent('on', 'ce.commoninit', function (context) { | |
+ if ($(context).is(document)) { | |
+ | |
+ $(_.doc).on('change', '.litecheckout__form [name="user_data[email]"]', function () { | |
+ let userEmail = this.value; | |
+ | |
+ $.ceAjax('request', fn_url('checkout.checkout'), { | |
+ result_ids: 'litecheckout_final_section', | |
+ method: 'get', | |
+ full_render: true, | |
+ data: { | |
+ user_email: userEmail | |
+ } | |
+ }); | |
+ }); | |
+ } | |
+ }); | |
+}(Tygh, Tygh.$)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment