1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* TechDivision\Import\Product\Observers\ProductUpdateObserver |
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
|
|
|
/** |
24
|
|
|
* Observer that add's/update's the product itself. |
25
|
|
|
* |
26
|
|
|
* @author Tim Wagner <[email protected]> |
27
|
|
|
* @copyright 2016 TechDivision GmbH <[email protected]> |
28
|
|
|
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) |
29
|
|
|
* @link https://github.com/techdivision/import-product |
30
|
|
|
* @link http://www.techdivision.com |
31
|
|
|
*/ |
32
|
|
|
class ProductUpdateObserver extends ProductObserver |
33
|
|
|
{ |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* Initialize the product with the passed data and returns an instance. |
37
|
|
|
* |
38
|
|
|
* @param string $sku The product's SKU |
39
|
|
|
* @param string $createdAt The product's creation date |
40
|
|
|
* @param string $updatedAt The product's last update date |
41
|
|
|
* @param integer $hasOptions Marks the product to has options |
42
|
|
|
* @param integer $requiredOptions Marks the product that some of the options are required |
43
|
|
|
* @param string $typeId The product's type ID |
44
|
|
|
* @param integer $attributeSetId The product's attribute set ID |
45
|
|
|
* |
46
|
|
|
* @return array The initialized product |
47
|
|
|
*/ |
48
|
2 |
|
public function initializeProduct( |
49
|
|
|
$sku, |
50
|
|
|
$createdAt, |
51
|
|
|
$updatedAt, |
52
|
|
|
$hasOptions, |
53
|
|
|
$requiredOptions, |
54
|
|
|
$typeId, |
55
|
|
|
$attributeSetId |
56
|
|
|
) { |
57
|
|
|
|
58
|
|
|
// initialize and the product data |
59
|
2 |
|
$data = parent::initializeProduct( |
60
|
2 |
|
$sku, |
61
|
2 |
|
$createdAt, |
62
|
2 |
|
$updatedAt, |
63
|
2 |
|
$hasOptions, |
64
|
2 |
|
$requiredOptions, |
65
|
2 |
|
$typeId, |
66
|
|
|
$attributeSetId |
67
|
2 |
|
); |
68
|
|
|
|
69
|
|
|
// load the product with the passed SKU and merge it with the data |
70
|
2 |
|
if ($product = $this->loadProduct($sku)) { |
71
|
1 |
|
return array_merge($product, $data); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
// otherwise simply return the data |
75
|
1 |
|
return $data; |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* Load's and return's the product with the passed SKU. |
80
|
|
|
* |
81
|
|
|
* @param string $sku The SKU of the product to load |
82
|
|
|
* |
83
|
|
|
* @return array The product |
84
|
|
|
*/ |
85
|
2 |
|
public function loadProduct($sku) |
86
|
|
|
{ |
87
|
2 |
|
return $this->getSubject()->loadProduct($sku); |
88
|
|
|
} |
89
|
|
|
} |
90
|
|
|
|