Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

closes #1847 for magento 2.3 #1850

Open
wants to merge 2 commits into
base: develop-2.3
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 36 additions & 2 deletions Block/Subscribe.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -15,27 +17,59 @@ 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()
{

$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;
}
}
40 changes: 40 additions & 0 deletions Controller/Subscriber/Subscribe.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

namespace Ebizmarts\MailChimp\Controller\Subscriber;

use Magento\Customer\Api\AccountManagementInterface as CustomerAccountManagement;
use Magento\Customer\Model\Session;
use Magento\Customer\Model\Url as CustomerUrl;
use Magento\Framework\App\Action\Context;
use Magento\Framework\App\Action\HttpPostActionInterface;
use Magento\Framework\Validator\EmailAddress as EmailValidator;
use Magento\Newsletter\Controller\Subscriber\NewAction as SubscriberController;
use Magento\Newsletter\Model\SubscriberFactory;
use Magento\Store\Model\StoreManagerInterface;

class Subscribe extends SubscriberController implements HttpPostActionInterface
{
private $session;
public function __construct(
Context $context,
SubscriberFactory $subscriberFactory,
Session $customerSession,
StoreManagerInterface $storeManager,
CustomerUrl $customerUrl,
CustomerAccountManagement $customerAccountManagement,
EmailValidator $emailValidator = null
)
{
$this->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();
}
}
3 changes: 2 additions & 1 deletion Controller/WebHook/Index.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ public function __construct(
\Ebizmarts\MailChimp\Model\MailChimpWebhookRequestFactory $chimpWebhookRequestFactory,
\Magento\Framework\HTTP\PhpEnvironment\RemoteAddress $remoteAddress
) {

parent::__construct($context);
$this->_resultFactory = $context->getResultFactory();
$this->_helper = $helper;
Expand Down Expand Up @@ -111,6 +110,8 @@ public function execute()
$this->_helper->log($request['data']);
$result->setHttpResponseCode(403);
}
} else {
$this->_helper->log("The two way is off");
}
} else {
$this->_helper->log('An empty request comes from ip: '.$this->_remoteAddress->getRemoteAddress());
Expand Down
6 changes: 4 additions & 2 deletions Cron/Webhook.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -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)));
Expand Down
Loading