|
1 | | -<?php |
| 1 | +<?php declare(strict_types=1); |
2 | 2 |
|
3 | 3 | namespace Lof\Mautic\Model\Mautic; |
4 | 4 |
|
5 | | -use Mautic\Auth\ApiAuth; |
6 | | -use Mautic\MauticApi; |
7 | | -use Lof\Mautic\Model\Config\Source\OauthVersion; |
8 | 5 | use Magento\Framework\Model\Context; |
9 | 6 | use Magento\Framework\Registry; |
10 | 7 |
|
@@ -45,89 +42,7 @@ public function __construct( |
45 | 42 | */ |
46 | 43 | public function export() |
47 | 44 | { |
48 | | - $customers = $this->customerFactory->create()->getCollection() |
49 | | - ->addAttributeToSelect('*'); |
50 | | - |
51 | | - foreach ($customers as $customer) { |
52 | | - $this->exportCustomer($customer); |
53 | | - } |
54 | | - |
55 | | - return true; |
56 | | - } |
57 | | - |
58 | | - /** |
59 | | - * Export customer |
60 | | - * |
61 | | - * @param \Magento\Customer\Model\Customer $customer |
62 | | - * @return bool |
63 | | - */ |
64 | | - public function exportCustomer($customer) |
65 | | - { |
66 | | - $data = $customer->getData(); |
67 | | - $address = $this->_getCustomerAddress($customer); |
68 | | - if ($address) { |
69 | | - $data = array_merge($data, $address); |
70 | | - } |
71 | | - $response = $this->_getContactApi()->create($data); |
72 | | - |
73 | | - if (isset($response['errors']) && count($response['errors'])) { |
74 | | - $this->mauticModel |
75 | | - ->executeErrorResponse($response); |
76 | | - |
77 | | - return false; |
78 | | - } |
79 | | - |
80 | 45 | return true; |
81 | 46 | } |
82 | 47 |
|
83 | | - /** |
84 | | - * Retrieve customer address |
85 | | - * |
86 | | - * @param \Magento\Customer\Model\Customer $customer |
87 | | - * @return array|mixed|bool |
88 | | - */ |
89 | | - protected function _getCustomerAddress($customer) |
90 | | - { |
91 | | - $address = false; |
92 | | - if ($customer->getPrimaryBillingAddress()) { |
93 | | - $address = $customer->getPrimaryBillingAddress(); |
94 | | - } elseif ($customer->getPrimaryShippingAddress()) { |
95 | | - $address = $customer->getPrimaryShippingAddress(); |
96 | | - } elseif ($customer->getAddresses()) { |
97 | | - $addresses = $customer->getAddresses(); |
98 | | - $address = array_shift($addresses); |
99 | | - } |
100 | | - |
101 | | - if ($address) { |
102 | | - |
103 | | - $country = $this->countryFactory->create()->loadByCode($address->getCountry()); |
104 | | - |
105 | | - return array( |
106 | | - self::MAUTIC_CUSTOMER_ADRESS1 => $address->getStreet1(), |
107 | | - self::MAUTIC_CUSTOMER_ADRESS2 => $address->getStreet2(), |
108 | | - self::MAUTIC_CUSTOMER_ZIPCODE => $address->getPostcode(), |
109 | | - self::MAUTIC_CUSTOMER_COUNTRY => $country->getName(), |
110 | | - self::MAUTIC_CUSTOMER_STATE => $address->getRegion(), |
111 | | - self::MAUTIC_CUSTOMER_CITY => $address->getCity(), |
112 | | - self::MAUTIC_CUSTOMER_COMPANY => $address->getCompany(), |
113 | | - self::MAUTIC_CUSTOMER_PHONE => $address->getTelephone() |
114 | | - ); |
115 | | - } |
116 | | - |
117 | | - return false; |
118 | | - } |
119 | | - |
120 | | - /** |
121 | | - * Retrieve contact api |
122 | | - * |
123 | | - * @return \Mautic\Api\Api |
124 | | - */ |
125 | | - protected function _getContactApi() |
126 | | - { |
127 | | - if ($this->_contactApi == null) { |
128 | | - $mautic = $this->mauticModel; |
129 | | - $this->_contactApi = $mautic->getApi('campaigns'); |
130 | | - } |
131 | | - return $this->_contactApi; |
132 | | - } |
133 | 48 | } |
0 commit comments