Skip to content

Commit ea2b642

Browse files
committed
refactor
1 parent 5a915fe commit ea2b642

File tree

6 files changed

+5
-182
lines changed

6 files changed

+5
-182
lines changed

Model/Mautic/AbstractApi.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
1-
<?php
1+
<?php declare(strict_types=1);
22

33
namespace Lof\Mautic\Model\Mautic;
44

5-
use Mautic\Auth\ApiAuth;
6-
use Mautic\MauticApi;
7-
use Lof\Mautic\Model\Config\Source\OauthVersion;
85
use Magento\Framework\Model\Context;
96
use Magento\Framework\Registry;
107

Model/Mautic/Campaign.php

Lines changed: 1 addition & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
1-
<?php
1+
<?php declare(strict_types=1);
22

33
namespace Lof\Mautic\Model\Mautic;
44

5-
use Mautic\Auth\ApiAuth;
6-
use Mautic\MauticApi;
7-
use Lof\Mautic\Model\Config\Source\OauthVersion;
85
use Magento\Framework\Model\Context;
96
use Magento\Framework\Registry;
107

@@ -45,89 +42,7 @@ public function __construct(
4542
*/
4643
public function export()
4744
{
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-
8045
return true;
8146
}
8247

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-
}
13348
}

Model/Mautic/Company.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
1-
<?php
1+
<?php declare(strict_types=1);
22

33
namespace Lof\Mautic\Model\Mautic;
44

5-
use Mautic\Auth\ApiAuth;
6-
use Mautic\MauticApi;
7-
use Lof\Mautic\Model\Config\Source\OauthVersion;
85
use Magento\Framework\Model\Context;
96
use Magento\Framework\Registry;
107

Model/Mautic/Contact.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<?php
1+
<?php declare(strict_types=1);
22

33
namespace Lof\Mautic\Model\Mautic;
44

Model/Mautic/Segment.php

Lines changed: 0 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@
22

33
namespace Lof\Mautic\Model\Mautic;
44

5-
use Mautic\Auth\ApiAuth;
6-
use Mautic\MauticApi;
7-
use Lof\Mautic\Model\Config\Source\OauthVersion;
85
use Magento\Framework\Model\Context;
96
use Magento\Framework\Registry;
107

@@ -45,89 +42,6 @@ public function __construct(
4542
*/
4643
public function export()
4744
{
48-
$customers = $this->customerFactory->create()->getCollection()
49-
->addAttributeToSelect('*');
50-
51-
foreach ($customers as $customer) {
52-
$this->exportCustomer($customer);
53-
}
54-
5545
return true;
5646
}
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-
return true;
81-
}
82-
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('segments');
130-
}
131-
return $this->_contactApi;
132-
}
13347
}

Queue/QueueProcessorInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<?php
1+
<?php declare(strict_types=1);
22

33
namespace Lof\Mautic\Queue;
44

0 commit comments

Comments
 (0)