-
Notifications
You must be signed in to change notification settings - Fork 110
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0e2e6ca
commit 7f18269
Showing
16 changed files
with
330 additions
and
57 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?php | ||
|
||
namespace Ebizmarts\MailChimp\Controller\Subscriber; | ||
|
||
use Magento\Customer\Api\AccountManagementInterface as CustomerAccountManagement; | ||
use Magento\Customer\Api\CustomerRepositoryInterface; | ||
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\Newsletter\Model\SubscriptionManagerInterface; | ||
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, | ||
SubscriptionManagerInterface $subscriptionManager, | ||
EmailValidator $emailValidator = null, | ||
CustomerRepositoryInterface $customerRepository = null | ||
) | ||
{ | ||
$this->session = $customerSession; | ||
parent::__construct($context, $subscriberFactory, $customerSession, $storeManager, $customerUrl, $customerAccountManagement, $subscriptionManager, $emailValidator, $customerRepository); | ||
} | ||
|
||
public function execute() | ||
{ | ||
if($this->getRequest()->isPost() && $this->getRequest()->getPost('phone')) { | ||
$email = (string)$this->getRequest()->getPost('email'); | ||
$phone = (string)$this->getRequest()->getPost('phone'); | ||
$this->session->setPhone($phone); | ||
} | ||
return parent::execute(); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
<?php | ||
|
||
namespace Ebizmarts\MailChimp\Model\Config\Source; | ||
|
||
use Magento\Framework\Data\OptionSourceInterface; | ||
use Ebizmarts\MailChimp\Helper\Data as MailchimpHelper; | ||
use Magento\Framework\App\RequestInterface; | ||
class Maps implements OptionSourceInterface | ||
{ | ||
private $options = null; | ||
public function __construct( | ||
RequestInterface $request, | ||
MailchimpHelper $helper | ||
) | ||
{ | ||
$storeId = (int) $request->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; | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php | ||
|
||
namespace Ebizmarts\MailChimp\Observer\Subscriber; | ||
|
||
use Magento\Framework\Event\Observer; | ||
use Magento\Customer\Model\Session; | ||
|
||
class SaveBefore implements \Magento\Framework\Event\ObserverInterface | ||
{ | ||
/** | ||
* @var Session | ||
*/ | ||
private $customerSession; | ||
|
||
/** | ||
* @param Session $customerSession | ||
*/ | ||
public function __construct( | ||
Session $customerSession | ||
) | ||
{ | ||
$this->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; | ||
} | ||
} |
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
Oops, something went wrong.