1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* TechDivision\Import\Product\Variant\Observers\VariantSuperLinkUpdateObserver |
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-variant |
18
|
|
|
* @link http://www.techdivision.com |
19
|
|
|
*/ |
20
|
|
|
|
21
|
|
|
namespace TechDivision\Import\Product\Variant\Observers; |
22
|
|
|
|
23
|
|
|
use TechDivision\Import\Product\Variant\Utils\MemberNames; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* Oberserver that provides functionality for the product variant super link add/update operation. |
27
|
|
|
* |
28
|
|
|
* @author Tim Wagner <[email protected]> |
29
|
|
|
* @copyright 2016 TechDivision GmbH <[email protected]> |
30
|
|
|
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) |
31
|
|
|
* @link https://github.com/techdivision/import-product-variant |
32
|
|
|
* @link http://www.techdivision.com |
33
|
|
|
*/ |
34
|
|
|
class VariantSuperLinkUpdateObserver extends VariantSuperLinkObserver |
35
|
|
|
{ |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* Initialize the product super link with the passed attributes and returns an instance. |
39
|
|
|
* |
40
|
|
|
* @param array $attr The product super link attributes |
41
|
|
|
* |
42
|
|
|
* @return array|null The initialized product super link, or null if the super link already exsist |
43
|
|
|
*/ |
44
|
|
|
protected function initializeProductSuperLink(array $attr) |
45
|
|
|
{ |
46
|
|
|
|
47
|
|
|
// laod parent/product ID |
48
|
|
|
$parentId = $attr[MemberNames::PARENT_ID]; |
49
|
|
|
$productId = $attr[MemberNames::PRODUCT_ID]; |
50
|
|
|
|
51
|
|
|
// query whether or not the product super link already exists |
52
|
|
|
if ($this->loadProductSuperLink($productId, $parentId)) { |
53
|
|
|
return; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
// simply return the attributes |
57
|
|
|
return $attr; |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* Load's the product super link with the passed product/parent ID. |
62
|
|
|
* |
63
|
|
|
* @param integer $productId The entity ID of the product super link's product |
64
|
|
|
* @param integer $parentId The entity ID of the product super link's parent product |
65
|
|
|
* |
66
|
|
|
* @return array The product super link |
67
|
|
|
*/ |
68
|
|
|
protected function loadProductSuperLink($productId, $parentId) |
69
|
|
|
{ |
70
|
|
|
return $this->getProductVariantProcessor()->loadProductSuperLink($productId, $parentId); |
71
|
|
|
} |
72
|
|
|
} |
73
|
|
|
|