diff --git a/Block/Subscribe.php b/Block/Subscribe.php
index 1012a305..656b9c82 100644
--- a/Block/Subscribe.php
+++ b/Block/Subscribe.php
@@ -2,6 +2,8 @@
namespace Ebizmarts\MailChimp\Block;
+use Magento\Customer\Model\Session;
+use Magento\Customer\Model\CustomerFactory;
use Magento\Framework\View\Element\Template;
use \Ebizmarts\MailChimp\Helper\Data as MailchimpHelper;
@@ -15,21 +17,35 @@ class Subscribe extends \Magento\Newsletter\Block\Subscribe
* @var MailchimpHelper
*/
protected $helper;
+ /**
+ * @var Session
+ */
+ protected $customerSession;
+ /**
+ * @var CustomerFactory
+ */
+ protected $customerFactory;
/**
* @param Template\Context $context
* @param MailchimpHelper $helper
+ * @param Session $customerSession
+ * @param CustomerFactory $customerFactory
* @param array $data
*/
public function __construct(
Template\Context $context,
MailchimpHelper $helper,
+ Session $customerSession,
+ CustomerFactory $customerFactory,
array $data = []
)
{
parent::__construct($context, $data);
$this->context = $context;
$this->helper = $helper;
+ $this->customerSession = $customerSession;
+ $this->customerFactory = $customerFactory;
}
public function getPopupUrl()
@@ -38,4 +54,23 @@ public function getPopupUrl()
$storeId = $this->context->getStoreManager()->getStore()->getId();
return $this->helper->getConfigValue(MailchimpHelper::XML_POPUP_URL,$storeId);
}
+ public function getFormActionUrl()
+ {
+ return $this->getUrl('mailchimp/subscriber/subscribe', ['_secure' => true]);
+ }
+ public function showMobilePhone()
+ {
+ $ret = true;
+ if ($this->customerSession->getCustomerId()) {
+ /**
+ * @var $customer \Magento\Customer\Model\Customer
+ */
+ $customer = $this->customerFactory->create()->load($this->customerSession->getCustomerId());
+ $mobilePhone = $customer->getData('mobile_phone');
+ if ($mobilePhone&&$mobilePhone!='') {
+ $ret = false;
+ }
+ }
+ return $ret;
+ }
}
\ No newline at end of file
diff --git a/Controller/Subscriber/Subscribe.php b/Controller/Subscriber/Subscribe.php
new file mode 100644
index 00000000..600c4379
--- /dev/null
+++ b/Controller/Subscriber/Subscribe.php
@@ -0,0 +1,39 @@
+session = $customerSession;
+ parent::__construct($context, $subscriberFactory, $customerSession, $storeManager, $customerUrl, $customerAccountManagement, $emailValidator);
+ }
+
+ public function execute()
+ {
+ if($this->getRequest()->isPost() && $this->getRequest()->getPost('phone')) {
+ $phone = (string)$this->getRequest()->getPost('phone');
+ $this->session->setPhone($phone);
+ }
+ return parent::execute();
+ }
+}
\ No newline at end of file
diff --git a/Controller/WebHook/Index.php b/Controller/WebHook/Index.php
index 881cb736..070da4a6 100644
--- a/Controller/WebHook/Index.php
+++ b/Controller/WebHook/Index.php
@@ -85,6 +85,8 @@ public function execute()
$this->_helper->log($e->getMessage());
$this->_helper->log($request['data']);
}
+ } else {
+ $this->_helper->log("The two way is off");
}
} else {
$this->_helper->log('An empty request comes from ip: '.$this->_remoteAddress->getRemoteAddress());
diff --git a/Cron/Webhook.php b/Cron/Webhook.php
index e4a37fd0..1a56672c 100644
--- a/Cron/Webhook.php
+++ b/Cron/Webhook.php
@@ -150,7 +150,8 @@ protected function _subscribe($data)
if (count($storeIds) > 0) {
foreach ($storeIds as $storeId) {
$sub = $this->_subscriberFactory->create();
- $sub->setStoreId($storeId);
+ $websiteId = $this->storeManager->getStore($storeId)->getWebsiteId();
+ $sub->setStoreId($websiteId);
$sub->setSubscriberEmail($email);
$this->_subscribeMember($sub, \Magento\Newsletter\Model\Subscriber::STATUS_SUBSCRIBED);
}
@@ -247,7 +248,8 @@ protected function _profile($data)
$stores = $this->_helper->getMagentoStoreIdsByListId($listId);
if (count($stores)) {
- $subscriber->setStoreId($stores[0]);
+ $websiteId = $this->storeManager->getStore($stores[0])->getWebsiteId();
+ $subscriber->setStoreId($websiteId);
try {
$api = $this->_helper->getApi($stores[0]);
$member = $api->lists->members->get($listId, hash('md5', strtolower($email)));
diff --git a/Helper/Data.php b/Helper/Data.php
index 3c86cb7c..edae66da 100755
--- a/Helper/Data.php
+++ b/Helper/Data.php
@@ -11,11 +11,31 @@
namespace Ebizmarts\MailChimp\Helper;
-use Magento\Framework\App\ResourceConnection;
-use Magento\Framework\Exception\ValidatorException;
-use Magento\Store\Model\Store;
+use Magento\Customer\Api\Data\CustomerInterface;
use Symfony\Component\Config\Definition\Exception\Exception;
-
+use Magento\Framework\App\ResourceConnection;
+use Magento\Framework\App\DeploymentConfig;
+use Magento\Framework\App\Cache\TypeListInterface;
+use Magento\Framework\App\Helper\Context;
+use Magento\Framework\Stdlib\DateTime\DateTime;
+use Magento\Framework\Module\ModuleList\Loader;
+use Magento\Framework\Encryption\Encryptor;
+use Magento\Directory\Api\CountryInformationAcquirerInterface;
+use Magento\Directory\Model\CountryFactory;
+use Magento\Customer\Model\Session;
+use Magento\Customer\Api\CustomerRepositoryInterface;
+use Magento\Customer\Model\CustomerFactory;
+use Magento\Customer\Model\ResourceModel\Attribute\CollectionFactory as AttributeCollectionFactory;
+use Magento\Customer\Model\ResourceModel\Customer\CollectionFactory as CustomerCollectionFactory;
+use Magento\Newsletter\Model\ResourceModel\Subscriber\CollectionFactory as SubscriberCollectionFactory;
+use Magento\Store\Model\StoreManagerInterface;
+use Magento\Config\Model\ResourceModel\Config;
+use Ebizmarts\MailChimp\Model\Logger\Logger;
+use Ebizmarts\MailChimp\Model\MailChimpSyncBatches;
+use Ebizmarts\MailChimp\Model\MailChimpStoresFactory;
+use Ebizmarts\MailChimp\Model\MailChimpStores;
+use Ebizmarts\MailChimp\Model\MailChimpInterestGroupFactory;
+use Magento\Framework\App\Config\ScopeConfigInterface;
class Data extends \Magento\Framework\App\Helper\AbstractHelper
{
const XML_PATH_ACTIVE = 'mailchimp/general/active';
@@ -52,7 +72,8 @@ class Data extends \Magento\Framework\App\Helper\AbstractHelper
const XML_POPUP_FORM = 'mailchimp/general/popup_form';
const XML_POPUP_URL = 'mailchimp/general/popup_url';
const XML_CLEAN_ERROR_MONTHS = 'mailchimp/ecommerce/clean_errors_months';
-
+ const XML_FOOTER_PHONE = 'mailchimp/general/footer_phone';
+ const XML_FOOTER_MAP = 'mailchimp/general/footer_phone_map';
const ORDER_STATE_OK = 'complete';
@@ -96,19 +117,15 @@ class Data extends \Magento\Framework\App\Helper\AbstractHelper
protected $counters = [];
/**
- * @var \Magento\Store\Model\StoreManagerInterface
+ * @var StoreManagerInterface
*/
private $_storeManager;
/**
- * @var \Ebizmarts\MailChimp\Model\Logger\Logger
+ * @var Logger
*/
private $_mlogger;
/**
- * @var \Magento\Customer\Model\GroupRegistry
- */
- private $_groupRegistry;
- /**
- * @var \Magento\Framework\App\Config\ScopeConfigInterface
+ * @var ScopeConfigInterface
*/
private $_scopeConfig;
/**
@@ -116,176 +133,156 @@ class Data extends \Magento\Framework\App\Helper\AbstractHelper
*/
protected $_request;
/**
- * @var \Magento\Framework\App\State
- */
- private $_state;
- /**
- * @var \Magento\Framework\Module\ModuleList\Loader
+ * @var Loader
*/
private $_loader;
/**
- * @var \Magento\Config\Model\ResourceModel\Config
+ * @var Config
*/
private $_config;
/**
* @var \Mailchimp
*/
private $_api;
-
- /**
- * @var \Magento\Customer\Model\ResourceModel\Customer\CustomerRepository
- */
- private $_customer;
/**
- * @var \Ebizmarts\MailChimp\Model\MailChimpSyncBatches
+ * @var MailChimpSyncBatches
*/
private $_syncBatches;
/**
- * @var \Ebizmarts\MailChimp\Model\MailChimpStoresFactory
+ * @var MailChimpStoresFactory
*/
private $_mailChimpStoresFactory;
/**
- * @var \Ebizmarts\MailChimp\Model\MailChimpStores
+ * @var MailChimpStores
*/
private $_mailChimpStores;
/**
- * @var \Magento\Framework\Encryption\Encryptor
+ * @var Encryptor
*/
private $_encryptor;
/**
- * @var \Magento\Newsletter\Model\ResourceModel\Subscriber\CollectionFactory
+ * @var SubscriberCollectionFactory
*/
private $_subscriberCollection;
/**
- * @var \Magento\Customer\Model\ResourceModel\Customer\CollectionFactory
+ * @var CustomerCollectionFactory
*/
private $_customerCollection;
- private $_addressRepositoryInterface;
- /**
- * @var \Magento\Framework\DB\Adapter\AdapterInterface
- */
- private $connection;
/**
- * @var \Magento\Framework\App\ResourceConnection
+ * @var ResourceConnection
*/
private $_resource;
/**
- * @var \Magento\Framework\App\Cache\TypeListInterface
+ * @var TypeListInterface
*/
private $_cacheTypeList;
/**
- * @var \Magento\Customer\Model\ResourceModel\Attribute\CollectionFactory
+ * @var AttributeCollectionFactory
*/
private $_attCollection;
/**
- * @var \Magento\Customer\Model\CustomerFactory
+ * @var CustomerFactory
*/
protected $_customerFactory;
/**
- * @var \Magento\Directory\Api\CountryInformationAcquirerInterface
+ * @var CountryInformationAcquirerInterface
*/
protected $_countryInformation;
/**
- * @var \Ebizmarts\MailChimp\Model\MailChimpInterestGroupFactory
+ * @var MailChimpInterestGroupFactory
*/
protected $_interestGroupFactory;
/**
- * @var \Magento\Framework\Stdlib\DateTime\DateTime
+ * @var DateTime
*/
protected $_date;
/**
- * @var \Magento\Directory\Model\CountryFactory
+ * @var CountryFactory
*/
protected $countryFactory;
/**
- * @var \Magento\Framework\Locale\Resolver
+ * @var DeploymentConfig
*/
- protected $resolver;
+ protected $_deploymentConfig;
/**
- * @var \Magento\Framework\App\DeploymentConfig
+ * @var Session
*/
- protected $_deploymentConfig;
+ protected $customerSession;
+ /**
+ * @var CustomerFactory
+ */
+ protected $customerFactory;
+
private $customerAtt = null;
private $addressAtt = null;
private $_mapFields = null;
/**
- * @param \Magento\Framework\App\Helper\Context $context
- * @param \Magento\Store\Model\StoreManagerInterface $storeManager
- * @param \Ebizmarts\MailChimp\Model\Logger\Logger $logger
- * @param \Magento\Customer\Model\GroupRegistry $groupRegistry
- * @param \Magento\Framework\App\State $state
- * @param \Magento\Framework\Module\ModuleList\Loader $loader
- * @param \Magento\Config\Model\ResourceModel\Config $config
+ * @param Context $context
+ * @param StoreManagerInterface $storeManager
+ * @param Logger $logger
+ * @param Loader $loader
+ * @param Config $config
* @param \Mailchimp $api
- * @param \Magento\Framework\App\Cache\TypeListInterface $cacheTypeList
- * @param \Magento\Customer\Model\ResourceModel\CustomerRepository $customer
- * @param \Ebizmarts\MailChimp\Model\MailChimpSyncBatches $syncBatches
- * @param \Ebizmarts\MailChimp\Model\MailChimpStoresFactory $mailChimpStoresFactory
- * @param \Ebizmarts\MailChimp\Model\MailChimpStores $mailChimpStores
- * @param \Magento\Customer\Model\ResourceModel\Attribute\CollectionFactory $attCollection
- * @param \Magento\Framework\Encryption\Encryptor $encryptor
- * @param \Magento\Newsletter\Model\ResourceModel\Subscriber\CollectionFactory $subscriberCollection
- * @param \Magento\Customer\Model\ResourceModel\Customer\CollectionFactory $customerCollection
- * @param \Magento\Customer\Api\AddressRepositoryInterface $addressRepositoryInterface
- * @param \Magento\Customer\Model\CustomerFactory $customerFactory
- * @param \Magento\Directory\Api\CountryInformationAcquirerInterface $countryInformation
+ * @param TypeListInterface $cacheTypeList
+ * @param MailChimpSyncBatches $syncBatches
+ * @param MailChimpStoresFactory $mailChimpStoresFactory
+ * @param MailChimpStores $mailChimpStores
+ * @param AttributeCollectionFactory $attCollection
+ * @param Encryptor $encryptor
+ * @param SubscriberCollectionFactory $subscriberCollection
+ * @param CustomerCollectionFactory $customerCollection
+ * @param CustomerRepositoryInterface $customerRepository
+ * @param CountryInformationAcquirerInterface $countryInformation
* @param ResourceConnection $resource
- * @param \Ebizmarts\MailChimp\Model\MailChimpInterestGroupFactory $interestGroupFactory
- * @param \Magento\Framework\App\DeploymentConfig $deploymentConfig
- * @param \Magento\Framework\Stdlib\DateTime\DateTime $date
- * @param \Magento\Directory\Model\CountryFactory $countryFactory
- * @param \Magento\Framework\Locale\Resolver $resolver
+ * @param MailChimpInterestGroupFactory $interestGroupFactory
+ * @param DeploymentConfig $deploymentConfig
+ * @param DateTime $date
+ * @param CountryFactory $countryFactory
+ * @param Session $customerSession
+ * @param CustomerFactory $customerFactory
*/
public function __construct(
- \Magento\Framework\App\Helper\Context $context,
- \Magento\Store\Model\StoreManagerInterface $storeManager,
- \Ebizmarts\MailChimp\Model\Logger\Logger $logger,
- \Magento\Customer\Model\GroupRegistry $groupRegistry,
- \Magento\Framework\App\State $state,
- \Magento\Framework\Module\ModuleList\Loader $loader,
- \Magento\Config\Model\ResourceModel\Config $config,
+ Context $context,
+ StoreManagerInterface $storeManager,
+ Logger $logger,
+ Loader $loader,
+ Config $config,
\Mailchimp $api,
- \Magento\Framework\App\Cache\TypeListInterface $cacheTypeList,
- \Magento\Customer\Model\ResourceModel\CustomerRepository $customer,
- \Ebizmarts\MailChimp\Model\MailChimpSyncBatches $syncBatches,
- \Ebizmarts\MailChimp\Model\MailChimpStoresFactory $mailChimpStoresFactory,
- \Ebizmarts\MailChimp\Model\MailChimpStores $mailChimpStores,
- \Magento\Customer\Model\ResourceModel\Attribute\CollectionFactory $attCollection,
- \Magento\Framework\Encryption\Encryptor $encryptor,
- \Magento\Newsletter\Model\ResourceModel\Subscriber\CollectionFactory $subscriberCollection,
- \Magento\Customer\Model\ResourceModel\Customer\CollectionFactory $customerCollection,
- \Magento\Customer\Api\AddressRepositoryInterface $addressRepositoryInterface,
- \Magento\Customer\Model\CustomerFactory $customerFactory,
- \Magento\Directory\Api\CountryInformationAcquirerInterface $countryInformation,
- \Magento\Framework\App\ResourceConnection $resource,
- \Ebizmarts\MailChimp\Model\MailChimpInterestGroupFactory $interestGroupFactory,
- \Magento\Framework\App\DeploymentConfig $deploymentConfig,
- \Magento\Framework\Stdlib\DateTime\DateTime $date,
- \Magento\Directory\Model\CountryFactory $countryFactory,
- \Magento\Framework\Locale\Resolver $resolver
+ TypeListInterface $cacheTypeList,
+ MailChimpSyncBatches $syncBatches,
+ MailChimpStoresFactory $mailChimpStoresFactory,
+ MailChimpStores $mailChimpStores,
+ AttributeCollectionFactory $attCollection,
+ Encryptor $encryptor,
+ SubscriberCollectionFactory $subscriberCollection,
+ CustomerCollectionFactory $customerCollection,
+ CustomerRepositoryInterface $customerRepository,
+ CountryInformationAcquirerInterface $countryInformation,
+ ResourceConnection $resource,
+ MailChimpInterestGroupFactory $interestGroupFactory,
+ DeploymentConfig $deploymentConfig,
+ DateTime $date,
+ CountryFactory $countryFactory,
+ Session $customerSession,
+ CustomerFactory $customerFactory
) {
$this->_storeManager = $storeManager;
$this->_mlogger = $logger;
- $this->_groupRegistry = $groupRegistry;
$this->_scopeConfig = $context->getScopeConfig();
$this->_request = $context->getRequest();
- $this->_state = $state;
$this->_loader = $loader;
$this->_config = $config;
$this->_api = $api;
- $this->_customer = $customer;
$this->_syncBatches = $syncBatches;
$this->_mailChimpStores = $mailChimpStores;
$this->_mailChimpStoresFactory = $mailChimpStoresFactory;
$this->_encryptor = $encryptor;
$this->_subscriberCollection = $subscriberCollection;
$this->_customerCollection = $customerCollection;
- $this->_addressRepositoryInterface = $addressRepositoryInterface;
$this->_resource = $resource;
- $this->connection = $resource->getConnection();
$this->_cacheTypeList = $cacheTypeList;
$this->_attCollection = $attCollection;
$this->_customerFactory = $customerFactory;
@@ -294,7 +291,8 @@ public function __construct(
$this->_date = $date;
$this->_deploymentConfig = $deploymentConfig;
$this->countryFactory = $countryFactory;
- $this->resolver = $resolver;
+ $this->customerSession = $customerSession;
+ $this->customerFactory = $customerFactory;
parent::__construct($context);
}
@@ -406,7 +404,7 @@ private function getAddressAtt()
$ret[$item] = [
'attCode' => $item,
'isDate' => false,
- 'isAddress' => false,
+ 'isAddress' => true,
'options' => []
];
}
@@ -755,23 +753,37 @@ private function _getAddressValues(\Magento\Customer\Model\Address\AbstractAddre
public function getMergeVarsBySubscriber(\Magento\Newsletter\Model\Subscriber $subscriber, $email = null)
{
$mergeVars = [];
- $storeId = $subscriber->getStoreId();
$webSiteId = $this->getWebsiteId($subscriber->getStoreId());
+ if ($this->getConfigValue(self::XML_FOOTER_PHONE, $webSiteId, "websites")) {
+ $phone_field = $this->getConfigValue(self::XML_FOOTER_MAP , $webSiteId, "websites");
+ $phone = $subscriber->getPhone();
+ if ($phone_field && $phone) {
+ $mergeVars[$phone_field] = $phone;
+ }
+ }
if (!$email) {
$email = $subscriber->getEmail();
}
- try {
- /**
- * @var $customer \Magento\Customer\Model\Customer
- */
- $customer = $this->_customerFactory->create();
- $customer->setWebsiteId($webSiteId);
- $customer->loadByEmail($email);
- if ($customer->getData('email') == $email) {
- $mergeVars = $this->getMergeVars($customer, $storeId);
+ if ($this->customerSession->getCustomerId()) {
+ try {
+ /**
+ * @var $customer CustomerInterface
+ */
+ $customer = $this->customerFactory->create()->load($this->customerSession->getCustomerId());
+ $this->log("Customer ".$customer->getId());
+ if ($customer->getData('mobile_phone')) {
+ $this->log($customer->getData('mobile_phone'));
+ } else {
+ $this->log('no mobile phone');
+ }
+ if ($customer->getData('email') == $email) {
+ $mergeVars = array_merge($mergeVars, $this->getMergeVars($customer, $customer->getStoreId()));
+ }
+ } catch (\Exception $e) {
+ $this->log($e->getMessage());
}
- } catch (\Exception $e) {
- $this->log($e->getMessage());
+ } else {
+ $this->log("Subscriber is not a customer");
}
return $mergeVars;
}
@@ -1007,11 +1019,14 @@ public function loadListSubscribers($listId, $mail)
{
$collection = null;
$storeIds = $this->getMagentoStoreIdsByListId($listId);
- $storeIds[] = 0;
+ $websiteIds = [];
+ foreach($storeIds as $storeId) {
+ $websiteIds[] =$this->_storeManager->getStore($storeId)->getWebsiteId();
+ }
if (count($storeIds) > 0) {
$collection = $this->_subscriberCollection->create();
$collection
- ->addFieldToFilter('store_id', ['in'=>$storeIds])
+ ->addFieldToFilter('store_id', ['in'=>$websiteIds])
->addFieldToFilter('subscriber_email', ['eq'=>$mail]);
}
return $collection;
diff --git a/Model/Config/Source/Maps.php b/Model/Config/Source/Maps.php
new file mode 100644
index 00000000..563b428a
--- /dev/null
+++ b/Model/Config/Source/Maps.php
@@ -0,0 +1,53 @@
+getParam("store", 0);
+ if ($request->getParam('website', 0)) {
+ $scope = 'website';
+ $storeId = $request->getParam('website', 0);
+ } elseif ($request->getParam('store', 0)) {
+ $scope = 'stores';
+ $storeId = $request->getParam('store', 0);
+ } else {
+ $scope = 'default';
+ }
+
+ if ($helper->getApiKey($storeId, $scope)) {
+ try {
+ $this->options = $helper->getApi($storeId, $scope)->lists->mergeFields->getAll(
+ $helper->getConfigValue(\Ebizmarts\MailChimp\Helper\Data::XML_PATH_LIST, $storeId, $scope),
+ null,
+ null,
+ MailchimpHelper::MAX_MERGEFIELDS
+ );
+ } catch (\Mailchimp_Error $e) {
+ $helper->log($e->getFriendlyMessage());
+ }
+ }
+
+ }
+ public function toOptionArray()
+ {
+ if (is_array($this->options)&&key_exists('merge_fields', $this->options)) {
+ $rc = [];
+ foreach ($this->options['merge_fields'] as $item) {
+ $rc[$item['tag']] = $item['tag'] . ' (' . $item['name'] . ' : ' . $item['type'] . ')';
+ }
+ } else {
+ $rc[] = ['value' => 0, 'label' => __('---No Data---')];
+ }
+ return $rc;
+ }
+}
\ No newline at end of file
diff --git a/Model/Plugin/Subscriber.php b/Model/Plugin/Subscriber.php
index d6461271..8d2b0522 100644
--- a/Model/Plugin/Subscriber.php
+++ b/Model/Plugin/Subscriber.php
@@ -29,12 +29,6 @@ class Subscriber
* @var \Magento\Store\Model\StoreManagerInterface
*/
protected $_storeManager;
- /**
- * @param \Ebizmarts\MailChimp\Helper\Data $helper
- * @param \Magento\Customer\Model\ResourceModel\CustomerRepository $customer
- * @param \Magento\Customer\Model\Session $customerSession
- */
- protected $_api = null;
/**
* Subscriber constructor.
@@ -49,7 +43,7 @@ public function __construct(
\Magento\Customer\Model\Session $customerSession,
\Magento\Store\Model\StoreManagerInterface $storeManager
) {
-
+
$this->_helper = $helper;
$this->_customer = $customer;
$this->_customerSession = $customerSession;
@@ -57,17 +51,16 @@ public function __construct(
}
/**
- * @param $subscriber
+ * @param \Magento\Newsletter\Model\Subscriber $subscriber
* @param $customerId
* @return array
* @throws \Magento\Framework\Exception\LocalizedException
*/
public function beforeUnsubscribeCustomerById(
- $subscriber,
- $customerId
+ \Magento\Newsletter\Model\Subscriber $subscriber,
+ $customerId
) {
-
- $storeId = $this->getStoreIdFromSubscriber($subscriber);
+ $storeId = $this->_storeManager->getStore()->getId();
if ($this->_helper->isMailChimpEnabled($storeId)) {
if (!$this->_helper->getConfigValue(\Ebizmarts\MailChimp\Helper\Data::XML_MAGENTO_MAIL, $storeId)) {
$subscriber->setImportMode(true);
@@ -76,8 +69,13 @@ public function beforeUnsubscribeCustomerById(
if ($subscriber->isSubscribed()) {
$api = $this->_helper->getApi($storeId);
try {
- $md5HashEmail = md5(strtolower($subscriber->getSubscriberEmail()));
- $api->lists->members->update($this->_helper->getDefaultList($storeId), $md5HashEmail, null, 'unsubscribed');
+ $md5HashEmail = hash('md5', strtolower($subscriber->getSubscriberEmail()));
+ $api->lists->members->update(
+ $this->_helper->getDefaultList($storeId),
+ $md5HashEmail,
+ null,
+ 'unsubscribed'
+ );
} catch (\Mailchimp_Error $e) {
$this->_helper->log($e->getFriendlyMessage());
}
@@ -87,25 +85,23 @@ public function beforeUnsubscribeCustomerById(
}
/**
- * @param $subscriber
+ * @param \Magento\Newsletter\Model\Subscriber $subscriber
* @param $customerId
* @return array
* @throws \Magento\Framework\Exception\LocalizedException
* @throws \Magento\Framework\Exception\NoSuchEntityException
*/
public function beforeSubscribeCustomerById(
- $subscriber,
- $customerId
+ \Magento\Newsletter\Model\Subscriber $subscriber,
+ $customerId
) {
-
- $storeId = $this->getStoreIdFromSubscriber($subscriber);
+ $storeId = $this->_storeManager->getStore()->getId();
if ($this->_helper->isMailChimpEnabled($storeId)) {
$subscriber->loadByCustomerId($customerId);
if (!$subscriber->isSubscribed()) {
if (!$this->_helper->getConfigValue(\Ebizmarts\MailChimp\Helper\Data::XML_MAGENTO_MAIL, $storeId)) {
$subscriber->setImportMode(true);
}
-
if ($this->_helper->isMailChimpEnabled($storeId)) {
$customer = $this->_customer->getById($customerId);
$email = $customer->getEmail();
@@ -117,8 +113,20 @@ public function beforeSubscribeCustomerById(
$status = 'subscribed';
}
try {
- $emailHash = md5(strtolower($customer->getEmail()));
- $api->lists->members->addOrUpdate($this->_helper->getDefaultList($storeId), $emailHash, null, $status, $mergeVars, null, null, null, null, $email, $status);
+ $emailHash = hash('md5', strtolower($customer->getEmail()));
+ $api->lists->members->addOrUpdate(
+ $this->_helper->getDefaultList($storeId),
+ $emailHash,
+ null,
+ $status,
+ $mergeVars,
+ null,
+ null,
+ null,
+ null,
+ $email,
+ $status
+ );
} catch (\Mailchimp_Error $e) {
$this->_helper->log($e->getFriendlyMessage());
}
@@ -129,21 +137,24 @@ public function beforeSubscribeCustomerById(
}
/**
- * @param $subscriber
+ * @param \Magento\Newsletter\Model\Subscriber $subscriber
* @param $email
* @return array
* @throws \Magento\Framework\Exception\LocalizedException
+ * @throws \Magento\Framework\Exception\NoSuchEntityException
*/
public function beforeSubscribe(
- $subscriber,
- $email
+ \Magento\Newsletter\Model\Subscriber $subscriber,
+ $email
) {
-
- $storeId = $this->getStoreIdFromSubscriber($subscriber);
+ $storeId = $this->_storeManager->getStore()->getId();
if ($this->_helper->isMailChimpEnabled($storeId)) {
if (!$this->_helper->getConfigValue(\Ebizmarts\MailChimp\Helper\Data::XML_MAGENTO_MAIL, $storeId)) {
$subscriber->setImportMode(true);
}
+ if ($this->_customerSession->getPhone()) {
+ $subscriber->setPhone($this->_customerSession->getPhone());
+ }
if ($this->_helper->isMailChimpEnabled($storeId)) {
$api = $this->_helper->getApi($storeId);
@@ -154,8 +165,20 @@ public function beforeSubscribe(
}
$mergeVars = $this->_helper->getMergeVarsBySubscriber($subscriber, $email);
try {
- $md5HashEmail = md5(strtolower($email));
- $return = $api->lists->members->addOrUpdate($this->_helper->getDefaultList($storeId), $md5HashEmail, null, $status, $mergeVars, null, null, null, null, $email, $status);
+ $md5HashEmail = hash('md5', strtolower($email));
+ $return = $api->lists->members->addOrUpdate(
+ $this->_helper->getDefaultList($storeId),
+ $md5HashEmail,
+ null,
+ $status,
+ $mergeVars,
+ null,
+ null,
+ null,
+ null,
+ $email,
+ $status
+ );
} catch (\Mailchimp_Error $e) {
$this->_helper->log($e->getFriendlyMessage());
}
@@ -172,21 +195,23 @@ public function beforeSubscribe(
public function beforeUnsubscribe(
\Magento\Newsletter\Model\Subscriber $subscriber
) {
-
- $storeId = $this->getStoreIdFromSubscriber($subscriber);
+ $storeId = $this->_storeManager->getStore()->getId();
if ($this->_helper->isMailChimpEnabled($storeId)) {
if (!$this->_helper->getConfigValue(\Ebizmarts\MailChimp\Helper\Data::XML_MAGENTO_MAIL, $storeId)) {
$subscriber->setImportMode(true);
- }
- $api = $this->_helper->getApi($this->getStoreIdFromSubscriber($subscriber));
+ } $api = $this->_helper->getApi($storeId);
try {
- $md5HashEmail = md5(strtolower($subscriber->getSubscriberEmail()));
- $api->lists->members->update($this->_helper->getDefaultList($storeId), $md5HashEmail, null, 'unsubscribed');
+ $md5HashEmail = hash('md5', strtolower($subscriber->getSubscriberEmail()));
+ $api->lists->members->update(
+ $this->_helper->getDefaultList($storeId),
+ $md5HashEmail,
+ null,
+ 'unsubscribed'
+ );
} catch (\Mailchimp_Error $e) {
$this->_helper->log($e->getFriendlyMessage());
}
}
- return null;
}
/**
@@ -197,15 +222,19 @@ public function beforeUnsubscribe(
public function afterDelete(
\Magento\Newsletter\Model\Subscriber $subscriber
) {
-
- $storeId = $this->getStoreIdFromSubscriber($subscriber);
+ $storeId = $this->_storeManager->getStore()->getId();
if ($this->_helper->isMailChimpEnabled($storeId)) {
$api = $this->_helper->getApi($storeId);
if ($subscriber->isSubscribed()) {
try {
- $md5HashEmail = md5(strtolower($subscriber->getSubscriberEmail()));
+ $md5HashEmail = hash('md5', strtolower($subscriber->getSubscriberEmail()));
if ($subscriber->getCustomerId()) {
- $api->lists->members->update($this->_helper->getDefaultList($storeId), $md5HashEmail, null, 'unsubscribed');
+ $api->lists->members->update(
+ $this->_helper->getDefaultList($storeId),
+ $md5HashEmail,
+ null,
+ 'unsubscribed'
+ );
} else {
$api->lists->members->delete($this->_helper->getDefaultList($storeId), $md5HashEmail);
}
@@ -216,13 +245,4 @@ public function afterDelete(
}
return null;
}
-
- /**
- * @param $subscriber
- * @return mixed
- */
- protected function getStoreIdFromSubscriber($subscriber)
- {
- return $subscriber->getStoreId();
- }
}
diff --git a/Model/ResourceModel/Newsletter/Collection.php b/Model/ResourceModel/Newsletter/Collection.php
new file mode 100644
index 00000000..38d12daa
--- /dev/null
+++ b/Model/ResourceModel/Newsletter/Collection.php
@@ -0,0 +1,14 @@
+showCustomerInfo(true)->addSubscriberTypeField()->showStoreInfo();
+ $this->_map['fields']['phone'] = 'main_table.phone';
+ return $this;
+ }
+}
\ No newline at end of file
diff --git a/Observer/Subscriber/SaveBefore.php b/Observer/Subscriber/SaveBefore.php
new file mode 100644
index 00000000..4bd10496
--- /dev/null
+++ b/Observer/Subscriber/SaveBefore.php
@@ -0,0 +1,34 @@
+customerSession = $customerSession;
+ }
+ public function execute(Observer $observer)
+ {
+ // TODO: Implement execute() method.
+ $subscriber = $observer->getSubscriber();
+ if ($this->customerSession->getPhone()) {
+ $subscriber->setPhone($this->customerSession->getPhone());
+ $this->customerSession->unsPhone();
+ }
+ return $subscriber;
+ }
+}
\ No newline at end of file
diff --git a/Setup/UpgradeData.php b/Setup/UpgradeData.php
index a0b4d470..fbaf6fd3 100644
--- a/Setup/UpgradeData.php
+++ b/Setup/UpgradeData.php
@@ -17,6 +17,12 @@
use Magento\Framework\Setup\UpgradeDataInterface;
use Magento\Framework\App\ResourceConnection;
use Magento\Framework\App\DeploymentConfig;
+use Magento\Sales\Model\OrderFactory;
+use Magento\Customer\Setup\CustomerSetupFactory;
+use Magento\Eav\Model\Entity\Attribute\SetFactory as AttributeSetFactory;
+use Magento\Eav\Model\Entity\Attribute\Set as AttributeSet;
+use Magento\Customer\Model\Customer;
+use Ebizmarts\MailChimp\Model\ResourceModel\MailChimpSyncEcommerce\CollectionFactory as SyncCollectionFactory;
class UpgradeData implements UpgradeDataInterface
{
@@ -44,14 +50,23 @@ class UpgradeData implements UpgradeDataInterface
* @var \Magento\Config\Model\ResourceModel\Config\Data\CollectionFactory
*/
protected $configFactory;
+ /**
+ * @var CustomerSetupFactory
+ */
+ protected $customerSetupFactory;
+ /**
+ * @var AttributeSetFactory
+ */
+ private $attributeSetFactory;
/**
- * UpgradeData constructor.
* @param ResourceConnection $resource
* @param DeploymentConfig $deploymentConfig
* @param \Ebizmarts\MailChimp\Model\ResourceModel\MailChimpInterestGroup\CollectionFactory $interestGroupCollectionFactory
* @param \Ebizmarts\MailChimp\Model\ResourceModel\MailChimpWebhookRequest\CollectionFactory $webhookCollectionFactory
* @param \Magento\Config\Model\ResourceModel\Config\Data\CollectionFactory $configFactory
+ * @param CustomerSetupFactory $customerSetupFactory
+ * @param AttributeSetFactory $attributeSetFactory
* @param \Ebizmarts\MailChimp\Helper\Data $helper
*/
public function __construct(
@@ -60,14 +75,17 @@ public function __construct(
\Ebizmarts\MailChimp\Model\ResourceModel\MailChimpInterestGroup\CollectionFactory $interestGroupCollectionFactory,
\Ebizmarts\MailChimp\Model\ResourceModel\MailChimpWebhookRequest\CollectionFactory $webhookCollectionFactory,
\Magento\Config\Model\ResourceModel\Config\Data\CollectionFactory $configFactory,
+ CustomerSetupFactory $customerSetupFactory,
+ AttributeSetFactory $attributeSetFactory,
\Ebizmarts\MailChimp\Helper\Data $helper
) {
-
$this->_resource = $resource;
$this->_deploymentConfig = $deploymentConfig;
$this->_insterestGroupCollectionFactory = $interestGroupCollectionFactory;
$this->_webhookCollectionFactory = $webhookCollectionFactory;
$this->configFactory = $configFactory;
+ $this->customerSetupFactory = $customerSetupFactory;
+ $this->attributeSetFactory = $attributeSetFactory;
$this->_helper = $helper;
}
@@ -197,5 +215,30 @@ public function upgrade(ModuleDataSetupInterface $setup, ModuleContextInterface
$config->getResource()->delete($config);
}
}
+ if (version_compare($context->getVersion(), '100.1.58')){
+ $customerSetup = $this->customerSetupFactory->create(['setup' => $setup]);
+ $customerEntity = $customerSetup->getEavConfig()->getEntityType('customer');
+ $attributeSetId = $customerEntity->getDefaultAttributeSetId();
+ /** @var $attributeSet AttributeSet */
+ $attributeSet = $this->attributeSetFactory->create();
+ $attributeGroupId = $attributeSet->getDefaultGroupId($attributeSetId);
+ $customerSetup->addAttribute(Customer::ENTITY, 'mobile_phone', [
+ 'type' => 'varchar',
+ 'label' => 'Mobile Phone',
+ 'input' => 'text',
+ 'required' => false,
+ 'visible' => true,
+ 'user_defined' => true,
+ 'position' => 999,
+ 'system' => 0,
+ ]);
+ $attribute = $customerSetup->getEavConfig()->getAttribute(Customer::ENTITY, 'mobile_phone')
+ ->addData([
+ 'attribute_set_id' => $attributeSetId,
+ 'attribute_group_id' => $attributeGroupId,
+ 'used_in_forms' => ['adminhtml_customer', 'customer_account_edit'],
+ ]);
+ $attribute->save();
+ }
}
}
diff --git a/Setup/UpgradeSchema.php b/Setup/UpgradeSchema.php
index 592785e1..2baa484c 100644
--- a/Setup/UpgradeSchema.php
+++ b/Setup/UpgradeSchema.php
@@ -742,5 +742,17 @@ public function upgrade(SchemaSetupInterface $setup, ModuleContextInterface $con
'mailchimp_sent'
);
}
+ if (version_compare($context->getVersion(), '100.1.58') < 0) {
+ $connection->addColumn(
+ $setup->getTable('newsletter_subscriber'),
+ 'phone',
+ [
+ 'type' => \Magento\Framework\DB\Ddl\Table::TYPE_TEXT,
+ 'default' => null,
+ 'length' => 128,
+ 'comment' => 'Phone'
+ ]
+ );
+ }
}
}
diff --git a/etc/adminhtml/di.xml b/etc/adminhtml/di.xml
new file mode 100644
index 00000000..23d781f6
--- /dev/null
+++ b/etc/adminhtml/di.xml
@@ -0,0 +1,15 @@
+
+
+
+
+
\ No newline at end of file
diff --git a/etc/adminhtml/system.xml b/etc/adminhtml/system.xml
index fd070a60..4ecee603 100644
--- a/etc/adminhtml/system.xml
+++ b/etc/adminhtml/system.xml
@@ -69,7 +69,7 @@
-
+
+
+
Magento\Config\Model\Config\Source\Yesno
diff --git a/etc/events.xml b/etc/events.xml
index 1e8c1ae3..817721ca 100644
--- a/etc/events.xml
+++ b/etc/events.xml
@@ -26,6 +26,9 @@
+
+
+
diff --git a/etc/module.xml b/etc/module.xml
index 5d749804..43939712 100644
--- a/etc/module.xml
+++ b/etc/module.xml
@@ -11,7 +11,7 @@
*/
-->
-
+
diff --git a/view/adminhtml/layout/newsletter_subscriber_block.xml b/view/adminhtml/layout/newsletter_subscriber_block.xml
new file mode 100644
index 00000000..94b769af
--- /dev/null
+++ b/view/adminhtml/layout/newsletter_subscriber_block.xml
@@ -0,0 +1,15 @@
+
+
+
+
+
+
+ Phone
+ phone
+ phone
+ phone
+
+
+
+
+
\ No newline at end of file
diff --git a/view/adminhtml/web/js/configapikey.js b/view/adminhtml/web/js/configapikey.js
index 69f49d51..05b72997 100644
--- a/view/adminhtml/web/js/configapikey.js
+++ b/view/adminhtml/web/js/configapikey.js
@@ -85,6 +85,20 @@ define(
if (ecommerceEnabled == 0 && abandonedCartEnabled == 1) {
self._changeAbandonedCart();
}
+ $('#mailchimp_general_popup_form').change(function () {
+ var popupformEnabled = $('#mailchimp_general_popup_form').find(':selected').val();
+ var footerphoneEnabled = $('#mailchimp_general_footer_phone').find(':selected').val();
+ if (popupformEnabled == 1 && footerphoneEnabled == 1) {
+ self._disableFooterPhone();
+ }
+ });
+ $('#mailchimp_general_footer_phone').change(function () {
+ var popupformEnabled = $('#mailchimp_general_popup_form').find(':selected').val();
+ var footerphoneEnabled = $('#mailchimp_general_footer_phone').find(':selected').val();
+ if (popupformEnabled == 1 && footerphoneEnabled == 1) {
+ self._disablePopupForm();
+ }
+ });
},
_changeEcommerce: function () {
var self = this;
@@ -397,6 +411,36 @@ define(
}
});
});
+ },
+ _disableFooterPhone: function () {
+ var tag = '#mailchimp_general_footer_phone'
+ $(tag).empty();
+ $(tag).append($('