├── docs
├── frontend.png
└── admin-panel.png
├── view
└── frontend
│ ├── requirejs-config.js
│ ├── web
│ ├── css
│ │ └── source
│ │ │ └── _module.less
│ └── js
│ │ └── newsletter.js
│ ├── templates
│ └── newsletter
│ │ ├── popup.phtml
│ │ └── form.phtml
│ └── layout
│ └── default.xml
├── registration.php
├── etc
├── module.xml
└── adminhtml
│ └── system.xml
├── composer.json
├── Helper
└── Config.php
├── README.md
└── Block
└── NewsletterPopup.php
/docs/frontend.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bitbull-team/magento2-module-newsletterpopup/HEAD/docs/frontend.png
--------------------------------------------------------------------------------
/docs/admin-panel.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bitbull-team/magento2-module-newsletterpopup/HEAD/docs/admin-panel.png
--------------------------------------------------------------------------------
/view/frontend/requirejs-config.js:
--------------------------------------------------------------------------------
1 | var config = {
2 | map: {
3 | '*': {
4 | newsletterPopup: 'Bitbull_NewsletterPopup/js/newsletter'
5 | }
6 | }
7 | };
8 |
--------------------------------------------------------------------------------
/registration.php:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/view/frontend/web/css/source/_module.less:
--------------------------------------------------------------------------------
1 | & when (@media-common = true) {
2 |
3 | .popup-newsletter {
4 |
5 | h4 {
6 | font-size: 2rem;
7 | }
8 |
9 | .action.primary {
10 | margin-top: 10px;
11 | width: 100%;
12 | }
13 |
14 | }
15 | .newsletter-modal {
16 |
17 | .modal-inner-wrap {
18 | max-width: 500px;
19 | }
20 |
21 | .modal-content {
22 | padding: 1rem 3rem 3rem;
23 | }
24 | .action-close {
25 | padding: 2rem;
26 | }
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/view/frontend/templates/newsletter/popup.phtml:
--------------------------------------------------------------------------------
1 |
8 |
9 |
15 |
16 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/composer.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "bitbull/magento2-module-newsletter-popup",
3 | "description": "Newsletter popup",
4 | "license": "Open Software License (OSL)",
5 | "authors": [
6 | {
7 | "name": "Irene Iaccio",
8 | "email": "irene.iaccio@bitbull.it"
9 | },
10 | {
11 | "name": "Lorena Ramonda",
12 | "email": "lorena.ramonda@bitbull.it"
13 | }
14 | ],
15 | "repositories":[
16 | {
17 | "type": "vcs",
18 | "url":"git@github.com:bitbull-team/magento2-module-bitbull-common.git"
19 | }
20 | ],
21 | "require": {
22 | "php": "~5.5.0|~5.6.0|~7.0.0",
23 | "bitbull/common-m2": "*"
24 | },
25 | "type": "magento2-module",
26 | "autoload": {
27 | "files": [ "registration.php" ],
28 | "psr-4": {
29 | "Bitbull\\NewsletterPopup\\": ""
30 | }
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/view/frontend/layout/default.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
10 |
11 |
16 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/view/frontend/templates/newsletter/form.phtml:
--------------------------------------------------------------------------------
1 |
--------------------------------------------------------------------------------
/Helper/Config.php:
--------------------------------------------------------------------------------
1 | scopeConfig->getValue(
35 | sprintf(self::BASE_CONFIG_XML_PREFIX, $configField),
36 | \Magento\Store\Model\ScopeInterface::SCOPE_STORE
37 | );
38 |
39 | }
40 |
41 | }
42 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Magento2 newsletter subscribe #
2 |
3 | A newsletter subscribing form that appears **once** after a certain number of seconds until set cookie expire.
4 |
5 | 
6 |
7 | Installation Instructions
8 | --------------------------
9 | Add these lines to the composer.json of your project
10 |
11 | ```
12 | "require":{
13 | ...
14 | "bitbull/magento2-module-newsletter-popup": "2.0.0"
15 | }
16 | ```
17 |
18 | ```
19 | "repositories":[
20 | ...
21 | {
22 | "type": "vcs",
23 | "url":"https://github.com/bitbull-team/magento2-module-newsletterpopup.git"
24 | }
25 | ]
26 | ```
27 |
28 | Settings
29 | --------
30 |
31 | After install go to **Stores -> Configuration -> Bitbull -> Newsletter Popup** and set _Display popup_ to yes.
32 |
33 | 
34 |
35 |
36 | Changelog
37 | ----------
38 |
39 | * 2.0.0 - Moved module under Bitbull tab and refactoring module name occurrences
40 | * 1.0.1 - Added single validation id
41 | * 1.0.0 - First release
42 |
43 |
44 | Licence
45 | -------
46 |
47 | [OSL - Open Software Licence 3.0](http://opensource.org/licenses/osl-3.0.php)
48 |
49 |
50 | Copyright
51 | ---------
52 | (c) 2016 Bitbull Srl
53 |
--------------------------------------------------------------------------------
/Block/NewsletterPopup.php:
--------------------------------------------------------------------------------
1 | configHelper = $configHelper;
29 | }
30 |
31 | /**
32 | * Returns Newsletter Popup config
33 | *
34 | * @return array
35 | */
36 | public function getConfig()
37 | {
38 | return [
39 | 'delay' => $this->_getPopupDelay(),
40 | 'title' => $this->_getPopupTitle()
41 | ];
42 | }
43 |
44 | /**
45 | * Newsletter Popup Text.
46 | *
47 | * @return string
48 | */
49 | public function getPopupText()
50 | {
51 | return $this->configHelper->getConfigParam(NewsletterPopupConfig::POPUP_TEXT);
52 | }
53 |
54 | /**
55 | * Newsletter Popup Delay.
56 | *
57 | * @return string
58 | */
59 | protected function _getPopupDelay()
60 | {
61 | return (string) $this->escapeHtml($this->configHelper->getConfigParam(NewsletterPopupConfig::POPUP_DELAY));
62 | }
63 |
64 | /**
65 | * Newsletter Popup Title.
66 | *
67 | * @return string
68 | */
69 | protected function _getPopupTitle()
70 | {
71 | return (string) $this->escapeHtml($this->configHelper->getConfigParam(NewsletterPopupConfig::POPUP_TITLE));
72 | }
73 | }
--------------------------------------------------------------------------------
/etc/adminhtml/system.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
29 |
30 |
31 |
--------------------------------------------------------------------------------
/view/frontend/web/js/newsletter.js:
--------------------------------------------------------------------------------
1 | define([
2 | "jquery",
3 | "Magento_Ui/js/modal/modal",
4 | "mage/cookies",
5 | "domReady!"
6 |
7 | ], function($,modal) {
8 | "use strict";
9 |
10 | $.widget('bitbull.popupNewsletter', {
11 |
12 | /**
13 | * @private
14 | */
15 |
16 | _init: function() {
17 |
18 | var $widget = this,
19 | delay = this.options.delay,
20 | time = this._getDelay(delay),
21 | cookie = 'newsletter',
22 | options = {
23 | type: 'popup',
24 | innerScroll: true,
25 | title: $.mage.__(this.options.title),
26 | modalClass: "newsletter-modal",
27 | buttons: ''
28 | };
29 |
30 | if (this._isCookieSet (cookie) != true ) {
31 |
32 | this._logTime(time, function(){
33 | $widget._openModal(options, cookie);
34 | });
35 | }
36 |
37 | },
38 |
39 | /**
40 | * Open Modal and set cookie
41 | *
42 | * @param options
43 | * @param cookie
44 | * @private
45 | */
46 |
47 | _openModal: function (options, cookie) {
48 |
49 | var html = this.element,
50 | popup = modal(options, html);
51 |
52 | html.modal('openModal');
53 | this._setCookie(cookie);
54 | },
55 |
56 | /**
57 | * Return the remaining time
58 | * for the modal opening
59 | *
60 | * @param delay
61 | * @returns {*}
62 | * @private
63 | */
64 |
65 | _getDelay: function (delay) {
66 |
67 | var cookie = $.mage.cookies.get('popup-timing');
68 | if (cookie > 0 ) {
69 | return delay - cookie
70 | } else {
71 | return delay
72 | }
73 | },
74 |
75 | /**
76 | * Set remaining time cookie
77 | *
78 | * @param i
79 | * @param callback
80 | * @private
81 | */
82 |
83 | _logTime: function (i, callback) {
84 |
85 | callback = callback || function(){};
86 | var int = setInterval(function() {
87 | $.mage.cookies.set('popup-timing', i);
88 | i-- || (clearInterval(int), callback());
89 | }, 1000);
90 | },
91 |
92 | /**
93 | * Set cookie
94 | *
95 | * @param cookie
96 | * @private
97 | */
98 |
99 | _setCookie: function (cookie) {
100 | $.mage.cookies.set(cookie, 'yes',
101 | {lifetime: 342342342342});
102 | },
103 |
104 | /**
105 | * Check if cookie is set
106 | *
107 | * @param cookie
108 | * @returns {boolean}
109 | * @private
110 | */
111 |
112 | _isCookieSet: function (cookie) {
113 | if ($.mage.cookies.get(cookie) == 'yes') {
114 | return true;
115 | }
116 | }
117 |
118 | });
119 |
120 | return $.bitbull.popupNewsletter;
121 | });
122 |
--------------------------------------------------------------------------------