Passed
Push — master ( d7c002...75ad7f )
by Tim
14:22 queued 04:48
created

CustomerAddressExportObserver::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * TechDivision\Import\Customer\Address\Observers\CustomerAddressExportObserver
5
 *
6
 * NOTICE OF LICENSE
7
 *
8
 * This source file is subject to the Open Software License (OSL 3.0)
9
 * that is available through the world-wide-web at this URL:
10
 * http://opensource.org/licenses/osl-3.0.php
11
 *
12
 * PHP version 5
13
 *
14
 * @author    Tim Wagner <[email protected]>
15
 * @copyright 2018 TechDivision GmbH <[email protected]>
16
 * @license   http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
17
 * @link      https://github.com/techdivision/import-customer-address
18
 * @link      http://www.techdivision.com
19
 */
20
21
namespace TechDivision\Import\Customer\Address\Observers;
22
23
use TechDivision\Import\Customer\Address\Utils\ColumnKeys;
24
use TechDivision\Import\Customer\Address\Services\CustomerAddressBunchProcessorInterface;
25
26
/**
27
 * Prepares the artefacts for the customer address export.
28
 *
29
 * @author    Tim Wagner <[email protected]>
30
 * @copyright 2018 TechDivision GmbH <[email protected]>
31
 * @license   http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
32
 * @link      https://github.com/techdivision/import-customer-address
33
 * @link      http://www.techdivision.com
34
 */
35
class CustomerAddressExportObserver extends AbstractCustomerAddressImportObserver
36
{
37
38
    /**
39
     * The artefact type.
40
     *
41
     * @var string
42
     */
43
    const ARTEFACT_TYPE = 'customer-import-address';
44
45
    /**
46
     * The customer address bunch processor instance.
47
     *
48
     * @var \TechDivision\Import\Customer\Address\Services\CustomerAddressBunchProcessorInterface
49
     */
50
    protected $customerAddressBunchProcessor;
51
52
    /**
53
     * Initialize the observer with the passed customer bunch processor instance.
54
     *
55
     * @param \TechDivision\Import\Customer\Address\Services\CustomerAddressBunchProcessorInterface $customerAddressBunchProcessor The customer address bunch processor instance
56
     */
57
    public function __construct(CustomerAddressBunchProcessorInterface $customerAddressBunchProcessor)
58
    {
59
        $this->customerAddressBunchProcessor = $customerAddressBunchProcessor;
60
    }
61
62
    /**
63
     * Return's the customer address bunch processor instance.
64
     *
65
     * @return \TechDivision\Import\Customer\Address\Services\CustomerAddressBunchProcessorInterface The customer address bunch processor instance
66
     */
67
    protected function getCustomerAddressBunchProcessor()
68
    {
69
        return $this->customerAddressBunchProcessor;
70
    }
71
72
    /**
73
     * Process the observer's business logic.
74
     *
75
     * @return void
76
     */
77
    protected function process()
78
    {
79
80
        // initialize the array for the links
81
        $artefacts = array();
82
83
        $artefacts[] = $this->newArtefact(
84
            array(
85
                ColumnKeys::ENTITY_ID        => null,
86
                ColumnKeys::WEBSITE          => $this->getValue(ColumnKeys::WEBSITE),
87
                ColumnKeys::EMAIL            => $this->getValue(ColumnKeys::EMAIL),
88
                ColumnKeys::CITY             => $this->getValue(ColumnKeys::ADDRESS_CITY),
89
                ColumnKeys::COMPANY          => $this->getValue(ColumnKeys::ADDRESS_COMPANY),
90
                ColumnKeys::COUNTRY_ID       => $this->getValue(ColumnKeys::ADDRESS_COUNTRY_ID),
91
                ColumnKeys::FAX              => $this->getValue(ColumnKeys::ADDRESS_FAX),
92
                ColumnKeys::FIRSTNAME        => $this->getValue(ColumnKeys::ADDRESS_FIRSTNAME),
93
                ColumnKeys::LASTNAME         => $this->getValue(ColumnKeys::ADDRESS_LASTNAME),
94
                ColumnKeys::MIDDLENAME       => $this->getValue(ColumnKeys::ADDRESS_MIDDLENAME),
95
                ColumnKeys::POSTCODE         => $this->getValue(ColumnKeys::ADDRESS_POSTCODE),
96
                ColumnKeys::PREFIX           => $this->getValue(ColumnKeys::ADDRESS_PREFIX),
97
                ColumnKeys::REGION           => $this->getValue(ColumnKeys::ADDRESS_REGION),
98
                ColumnKeys::STREET           => $this->getValue(ColumnKeys::ADDRESS_STREET),
99
                ColumnKeys::SUFFIX           => $this->getValue(ColumnKeys::ADDRESS_SUFFIX),
100
                ColumnKeys::TELEPHONE        => $this->getValue(ColumnKeys::ADDRESS_TELEPHONE),
101
                ColumnKeys::VAT_ID           => $this->getValue(ColumnKeys::ADDRESS_VAT_ID),
102
                ColumnKeys::DEFAULT_BILLING  => $this->getValue(ColumnKeys::ADDRESS_DEFAULT_BILLING),
103
                ColumnKeys::DEFAULT_SHIPPING => $this->getValue(ColumnKeys::ADDRESS_DEFAULT_SHIPPING)
104
            ),
105
            array(
106
                ColumnKeys::ENTITY_ID        => null,
107
                ColumnKeys::WEBSITE          => ColumnKeys::WEBSITE,
108
                ColumnKeys::EMAIL            => ColumnKeys::EMAIL,
109
                ColumnKeys::CITY             => ColumnKeys::ADDRESS_CITY,
110
                ColumnKeys::COMPANY          => ColumnKeys::ADDRESS_COMPANY,
111
                ColumnKeys::COUNTRY_ID       => ColumnKeys::ADDRESS_COUNTRY_ID,
112
                ColumnKeys::FAX              => ColumnKeys::ADDRESS_FAX,
113
                ColumnKeys::FIRSTNAME        => ColumnKeys::ADDRESS_FIRSTNAME,
114
                ColumnKeys::LASTNAME         => ColumnKeys::ADDRESS_LASTNAME,
115
                ColumnKeys::MIDDLENAME       => ColumnKeys::ADDRESS_MIDDLENAME,
116
                ColumnKeys::POSTCODE         => ColumnKeys::ADDRESS_POSTCODE,
117
                ColumnKeys::PREFIX           => ColumnKeys::ADDRESS_PREFIX,
118
                ColumnKeys::REGION           => ColumnKeys::ADDRESS_REGION,
119
                ColumnKeys::STREET           => ColumnKeys::ADDRESS_STREET,
120
                ColumnKeys::SUFFIX           => ColumnKeys::ADDRESS_SUFFIX,
121
                ColumnKeys::TELEPHONE        => ColumnKeys::ADDRESS_TELEPHONE,
122
                ColumnKeys::VAT_ID           => ColumnKeys::ADDRESS_VAT_ID,
123
                ColumnKeys::DEFAULT_BILLING  => ColumnKeys::ADDRESS_DEFAULT_BILLING,
124
                ColumnKeys::DEFAULT_SHIPPING => ColumnKeys::ADDRESS_DEFAULT_SHIPPING
125
            )
126
        );
127
128
        // append the links to the subject
129
        $this->addArtefacts($artefacts);
130
    }
131
132
    /**
133
     * Create's and return's a new empty artefact entity.
134
     *
135
     * @param array $columns             The array with the column data
136
     * @param array $originalColumnNames The array with a mapping from the old to the new column names
137
     *
138
     * @return array The new artefact entity
139
     */
140
    protected function newArtefact(array $columns, array $originalColumnNames)
141
    {
142
        return $this->getSubject()->newArtefact($columns, $originalColumnNames);
143
    }
144
145
    /**
146
     * Add the passed product type artefacts to the product with the
147
     * last entity ID.
148
     *
149
     * @param array $artefacts The product type artefacts
150
     *
151
     * @return void
152
     * @uses \TechDivision\Import\Product\Media\Subjects\MediaSubject::getLastEntityId()
153
     */
154
    protected function addArtefacts(array $artefacts)
155
    {
156
        $this->getSubject()->addArtefacts(CustomerAddressExportObserver::ARTEFACT_TYPE, $artefacts);
157
    }
158
}