|
1
|
|
|
<?php |
|
2
|
|
|
declare(strict_types=1); |
|
3
|
|
|
/** |
|
4
|
|
|
*/ |
|
5
|
|
|
|
|
6
|
|
|
namespace CommerceLeague\ActiveCampaign\Service\Contact; |
|
7
|
|
|
|
|
8
|
|
|
use CommerceLeague\ActiveCampaign\Gateway\Request\ContactBuilder as ContactRequestBuilder; |
|
9
|
|
|
use CommerceLeague\ActiveCampaign\MessageQueue\Topics; |
|
10
|
|
|
use Magento\Customer\Model\Customer as MagentoCustomer; |
|
11
|
|
|
use Magento\Framework\MessageQueue\PublisherInterface; |
|
12
|
|
|
use Magento\Newsletter\Model\Subscriber; |
|
13
|
|
|
|
|
14
|
|
|
class SyncContactService |
|
15
|
|
|
{ |
|
16
|
|
|
/** |
|
17
|
|
|
* @var ContactRequestBuilder |
|
18
|
|
|
*/ |
|
19
|
|
|
private $contactRequestBuilder; |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* @var PublisherInterface |
|
23
|
|
|
*/ |
|
24
|
|
|
private $publisher; |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* @param ContactRequestBuilder $contactRequestBuilder |
|
28
|
|
|
* @param PublisherInterface $publisher |
|
29
|
|
|
*/ |
|
30
|
|
|
public function __construct( |
|
31
|
|
|
ContactRequestBuilder $contactRequestBuilder, |
|
32
|
|
|
PublisherInterface $publisher |
|
33
|
|
|
) { |
|
34
|
|
|
$this->contactRequestBuilder = $contactRequestBuilder; |
|
35
|
|
|
$this->publisher = $publisher; |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* @param MagentoCustomer $magentoCustomer |
|
40
|
|
|
*/ |
|
41
|
|
|
public function syncWithMagentoCustomer(MagentoCustomer $magentoCustomer): void |
|
42
|
|
|
{ |
|
43
|
|
|
$data = [ |
|
44
|
|
|
'email' => $magentoCustomer->getData('email'), |
|
45
|
|
|
'request' => $this->contactRequestBuilder->buildWithMagentoCustomer($magentoCustomer) |
|
46
|
|
|
]; |
|
47
|
|
|
|
|
48
|
|
|
$this->publisher->publish(Topics::CONTACT_SYNC, json_encode($data)); |
|
|
|
|
|
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* @param Subscriber $subscriber |
|
53
|
|
|
*/ |
|
54
|
|
|
public function syncWithSubscriber(Subscriber $subscriber): void |
|
55
|
|
|
{ |
|
56
|
|
|
$data = [ |
|
57
|
|
|
'email' => $subscriber->getEmail(), |
|
58
|
|
|
'request' => $this->contactRequestBuilder->buildWithSubscriber($subscriber) |
|
59
|
|
|
]; |
|
60
|
|
|
|
|
61
|
|
|
$this->publisher->publish(Topics::CONTACT_SYNC, json_encode($data)); |
|
|
|
|
|
|
62
|
|
|
} |
|
63
|
|
|
} |
|
64
|
|
|
|