|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* TechDivision\Import\Product\Magic360\Observers\ProductMagic360Observer |
|
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
|
|
|
* @author Bernhard Wick <[email protected]> |
|
16
|
|
|
* @copyright 2017 TechDivision GmbH <[email protected]> |
|
17
|
|
|
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) |
|
18
|
|
|
* @link https://github.com/techdivision/import-product-magic360 |
|
19
|
|
|
* @link http://www.techdivision.com |
|
20
|
|
|
*/ |
|
21
|
|
|
|
|
22
|
|
|
namespace TechDivision\Import\Product\Magic360\Observers; |
|
23
|
|
|
|
|
24
|
|
|
use TechDivision\Import\Product\Magic360\Utils\ColumnKeys; |
|
25
|
|
|
use TechDivision\Import\Product\Observers\AbstractProductImportObserver; |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* Prepares the artefacts for the generic Magic360 gallery type import. |
|
29
|
|
|
* |
|
30
|
|
|
* @author Tim Wagner <[email protected]> |
|
31
|
|
|
* @author Bernhard Wick <[email protected]> |
|
32
|
|
|
* @copyright 2017 TechDivision GmbH <[email protected]> |
|
33
|
|
|
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) |
|
34
|
|
|
* @link https://github.com/techdivision/import-product-magic360 |
|
35
|
|
|
* @link http://www.techdivision.com |
|
36
|
|
|
*/ |
|
37
|
|
|
class ProductMagic360Observer extends AbstractProductImportObserver |
|
38
|
|
|
{ |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* The artefact type. |
|
42
|
|
|
* |
|
43
|
|
|
* @var string |
|
44
|
|
|
*/ |
|
45
|
|
|
const ARTEFACT_TYPE = 'magic360'; |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* Process the observer's business logic. |
|
49
|
|
|
* |
|
50
|
|
|
* @return array The processed row |
|
51
|
|
|
*/ |
|
52
|
|
|
protected function process() |
|
53
|
|
|
{ |
|
54
|
|
|
// we will only look for the image path if the row is flagged as having 360 images |
|
55
|
|
|
if ($this->hasValue(ColumnKeys::IS_360)) { |
|
56
|
|
|
$this->addArtefacts( |
|
57
|
|
|
array( |
|
58
|
|
|
array( |
|
59
|
|
|
ColumnKeys::SKU => $this->getValue(ColumnKeys::SKU), |
|
60
|
|
|
ColumnKeys::IMAGES_PATH => $this->getValue(ColumnKeys::IMAGES_360) |
|
61
|
|
|
) |
|
62
|
|
|
) |
|
63
|
|
|
); |
|
64
|
|
|
} |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
/** |
|
68
|
|
|
* Add the passed artefacts to the product with the |
|
69
|
|
|
* last entity ID. |
|
70
|
|
|
* |
|
71
|
|
|
* @param array $artefacts The product type artefacts |
|
72
|
|
|
* |
|
73
|
|
|
* @return void |
|
74
|
|
|
*/ |
|
75
|
|
|
protected function addArtefacts(array $artefacts) |
|
76
|
|
|
{ |
|
77
|
|
|
$this->getSubject()->addArtefacts(ProductMagic360Observer::ARTEFACT_TYPE, $artefacts); |
|
|
|
|
|
|
78
|
|
|
} |
|
79
|
|
|
} |
|
80
|
|
|
|
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: