1
|
|
|
<?php |
2
|
|
|
declare(strict_types=1); |
3
|
|
|
/** |
4
|
|
|
*/ |
5
|
|
|
|
6
|
|
|
namespace CommerceLeague\ActiveCampaign\Service; |
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
|
|
|
/** |
15
|
|
|
* Class ExportContactService |
16
|
|
|
*/ |
17
|
|
|
class ExportContactService |
18
|
|
|
{ |
19
|
|
|
/** |
20
|
|
|
* @var ContactRequestBuilder |
21
|
|
|
*/ |
22
|
|
|
private $contactRequestBuilder; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @var PublisherInterface |
26
|
|
|
*/ |
27
|
|
|
private $publisher; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @param ContactRequestBuilder $contactRequestBuilder |
31
|
|
|
* @param PublisherInterface $publisher |
32
|
|
|
*/ |
33
|
|
|
public function __construct( |
34
|
|
|
ContactRequestBuilder $contactRequestBuilder, |
35
|
|
|
PublisherInterface $publisher |
36
|
|
|
) { |
37
|
|
|
$this->contactRequestBuilder = $contactRequestBuilder; |
38
|
|
|
$this->publisher = $publisher; |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @param MagentoCustomer $magentoCustomer |
43
|
|
|
*/ |
44
|
|
|
public function exportWithMagentoCustomer(MagentoCustomer $magentoCustomer): void |
45
|
|
|
{ |
46
|
|
|
$data = [ |
47
|
|
|
'email' => $magentoCustomer->getData('email'), |
48
|
|
|
'request' => $this->contactRequestBuilder->buildWithMagentoCustomer($magentoCustomer) |
49
|
|
|
]; |
50
|
|
|
|
51
|
|
|
$this->publisher->publish(Topics::CONTACT_EXPORT, json_encode($data)); |
|
|
|
|
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* @param Subscriber $subscriber |
56
|
|
|
*/ |
57
|
|
|
public function exportWithSubscriber(Subscriber $subscriber): void |
58
|
|
|
{ |
59
|
|
|
$data = [ |
60
|
|
|
'email' => $subscriber->getEmail(), |
61
|
|
|
'request' => $this->contactRequestBuilder->buildWithSubscriber($subscriber) |
62
|
|
|
]; |
63
|
|
|
|
64
|
|
|
$this->publisher->publish(Topics::CONTACT_EXPORT, json_encode($data)); |
|
|
|
|
65
|
|
|
} |
66
|
|
|
} |
67
|
|
|
|