|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* TechDivision\Import\Product\Observers\AbstractProductImportObserver |
|
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 2016 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-product |
|
18
|
|
|
* @link http://www.techdivision.com |
|
19
|
|
|
*/ |
|
20
|
|
|
|
|
21
|
|
|
namespace TechDivision\Import\Product\Observers; |
|
22
|
|
|
|
|
23
|
|
|
use TechDivision\Import\Product\Utils\ColumnKeys; |
|
24
|
|
|
use TechDivision\Import\Subjects\SubjectInterface; |
|
25
|
|
|
use TechDivision\Import\Observers\AbstractObserver; |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* Abstract category observer that handles the process to import product bunches. |
|
29
|
|
|
* |
|
30
|
|
|
* @author Tim Wagner <[email protected]> |
|
31
|
|
|
* @copyright 2016 TechDivision GmbH <[email protected]> |
|
32
|
|
|
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) |
|
33
|
|
|
* @link https://github.com/techdivision/import-product |
|
34
|
|
|
* @link http://www.techdivision.com |
|
35
|
|
|
*/ |
|
36
|
|
|
abstract class AbstractProductImportObserver extends AbstractObserver implements ProductImportObserverInterface |
|
37
|
|
|
{ |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* Will be invoked by the action on the events the listener has been registered for. |
|
41
|
|
|
* |
|
42
|
|
|
* @param \TechDivision\Import\Subjects\SubjectInterface $subject The subject instance |
|
43
|
|
|
* |
|
44
|
|
|
* @return array The modified row |
|
45
|
|
|
* @see \TechDivision\Import\Observers\ObserverInterface::handle() |
|
46
|
|
|
*/ |
|
47
|
13 |
|
public function handle(SubjectInterface $subject) |
|
48
|
|
|
{ |
|
49
|
|
|
|
|
50
|
|
|
// initialize the row |
|
51
|
13 |
|
$this->setSubject($subject); |
|
52
|
13 |
|
$this->setRow($subject->getRow()); |
|
53
|
|
|
|
|
54
|
|
|
// process the functionality and return the row |
|
55
|
13 |
|
$this->process(); |
|
56
|
|
|
|
|
57
|
|
|
// return the processed row |
|
58
|
12 |
|
return $this->getRow(); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
/** |
|
62
|
|
|
* Process the observer's business logic. |
|
63
|
|
|
* |
|
64
|
|
|
* @return void |
|
65
|
|
|
*/ |
|
66
|
|
|
abstract protected function process(); |
|
67
|
|
|
|
|
68
|
|
|
/** |
|
69
|
|
|
* Return's the column name that contains the primary key. |
|
70
|
|
|
* |
|
71
|
|
|
* @return string the column name that contains the primary key |
|
72
|
|
|
*/ |
|
73
|
|
|
protected function getPrimaryKeyColumnName() |
|
74
|
|
|
{ |
|
75
|
|
|
return ColumnKeys::SKU; |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
/** |
|
79
|
|
|
* Queries whether or not the SKU has already been processed. |
|
80
|
|
|
* |
|
81
|
|
|
* @param string $sku The SKU to check been processed |
|
82
|
|
|
* |
|
83
|
|
|
* @return boolean TRUE if the SKU has been processed, else FALSE |
|
84
|
|
|
*/ |
|
85
|
5 |
|
protected function hasBeenProcessed($sku) |
|
86
|
|
|
{ |
|
87
|
5 |
|
return $this->getSubject()->hasBeenProcessed($sku); |
|
|
|
|
|
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
/** |
|
91
|
|
|
* Queries whether or not the passed SKU and store view code has already been processed. |
|
92
|
|
|
* |
|
93
|
|
|
* @param string $sku The SKU to check been processed |
|
94
|
|
|
* @param string $storeViewCode The store view code to check been processed |
|
95
|
|
|
* |
|
96
|
|
|
* @return boolean TRUE if the SKU and store view code has been processed, else FALSE |
|
97
|
|
|
*/ |
|
98
|
|
|
protected function storeViewHasBeenProcessed($sku, $storeViewCode) |
|
99
|
|
|
{ |
|
100
|
|
|
return $this->getSubject()->storeViewHasBeenProcessed($sku, $storeViewCode); |
|
|
|
|
|
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
/** |
|
104
|
|
|
* Add the passed SKU => entity ID mapping. |
|
105
|
|
|
* |
|
106
|
|
|
* @param string $sku The SKU |
|
107
|
|
|
* |
|
108
|
|
|
* @return void |
|
109
|
|
|
*/ |
|
110
|
|
|
protected function addSkuEntityIdMapping($sku) |
|
111
|
|
|
{ |
|
112
|
|
|
$this->getSubject()->addSkuEntityIdMapping($sku); |
|
|
|
|
|
|
113
|
|
|
} |
|
114
|
|
|
|
|
115
|
|
|
/** |
|
116
|
|
|
* Add the passed SKU => store view code mapping. |
|
117
|
|
|
* |
|
118
|
|
|
* @param string $sku The SKU |
|
119
|
|
|
* @param string $storeViewCode The store view code |
|
120
|
|
|
* |
|
121
|
|
|
* @return void |
|
122
|
|
|
*/ |
|
123
|
|
|
protected function addSkuStoreViewCodeMapping($sku, $storeViewCode) |
|
124
|
|
|
{ |
|
125
|
|
|
$this->getSubject()->addSkuStoreViewCodeMapping($sku, $storeViewCode); |
|
|
|
|
|
|
126
|
|
|
} |
|
127
|
|
|
|
|
128
|
|
|
/** |
|
129
|
|
|
* Return's TRUE if the passed SKU is the actual one. |
|
130
|
|
|
* |
|
131
|
|
|
* @param string $sku The SKU to check |
|
132
|
|
|
* |
|
133
|
|
|
* @return boolean TRUE if the passed SKU is the actual one |
|
134
|
|
|
*/ |
|
135
|
5 |
|
protected function isLastSku($sku) |
|
136
|
|
|
{ |
|
137
|
5 |
|
return $this->getSubject()->getLastSku() === $sku; |
|
|
|
|
|
|
138
|
|
|
} |
|
139
|
|
|
} |
|
140
|
|
|
|
Let’s take a look at an example:
In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break.
Available Fixes
Change the type-hint for the parameter:
Add an additional type-check:
Add the method to the interface: