1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* TechDivision\Import\Product\Bundle\Observers\BundleSelectionPriceUpdateObserver |
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-bundle |
18
|
|
|
* @link http://www.techdivision.com |
19
|
|
|
*/ |
20
|
|
|
|
21
|
|
|
namespace TechDivision\Import\Product\Bundle\Observers; |
22
|
|
|
|
23
|
|
|
use TechDivision\Import\Utils\StoreViewCodes; |
24
|
|
|
use TechDivision\Import\Product\Bundle\Utils\ColumnKeys; |
25
|
|
|
use TechDivision\Import\Product\Bundle\Utils\MemberNames; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* Oberserver that provides functionality for the bundle selection price add/update operation. |
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-bundle |
34
|
|
|
* @link http://www.techdivision.com |
35
|
|
|
*/ |
36
|
|
View Code Duplication |
class BundleSelectionPriceUpdateObserver extends BundleSelectionPriceObserver |
|
|
|
|
37
|
|
|
{ |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* Initialize the bundle selection price with the passed attributes and returns an instance. |
41
|
|
|
* |
42
|
|
|
* @param array $attr The bundle selection price attributes |
43
|
|
|
* |
44
|
|
|
* @return array The initialized bundle selection price |
45
|
|
|
*/ |
46
|
|
|
protected function initializeBundleSelectionPrice(array $attr) |
47
|
|
|
{ |
48
|
|
|
|
49
|
|
|
// load the store view code |
50
|
|
|
$storeViewCode = $this->getStoreViewCode(StoreViewCodes::ADMIN); |
51
|
|
|
|
52
|
|
|
// load the store/website ID |
53
|
|
|
$store = $this->getStoreByStoreCode($storeViewCode); |
54
|
|
|
$websiteId = $store[MemberNames::WEBSITE_ID]; |
55
|
|
|
|
56
|
|
|
// load the selection ID for the child SKU |
57
|
|
|
$selectionId = $this->getChildSkuSelectionMapping($this->getValue(ColumnKeys::BUNDLE_VALUE_SKU)); |
|
|
|
|
58
|
|
|
|
59
|
|
|
// try to load the bundle selection price with the passed selection/website ID |
60
|
|
|
if ($entity = $this->loadBundleSelectionPrice($selectionId, $websiteId)) { |
61
|
|
|
return $this->mergeEntity($entity, $attr); |
|
|
|
|
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
// simply return the attributes |
65
|
|
|
return $attr; |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* Load's the bundle selection price with the passed selection/website ID. |
70
|
|
|
* |
71
|
|
|
* @param integer $selectionId The selection ID of the bundle selection price to be returned |
72
|
|
|
* @param integer $websiteId The website ID of the bundle selection price to be returned |
73
|
|
|
* |
74
|
|
|
* @return array The bundle selection price |
75
|
|
|
*/ |
76
|
|
|
protected function loadBundleSelectionPrice($selectionId, $websiteId) |
77
|
|
|
{ |
78
|
|
|
return $this->getSubject()->loadBundleSelectionPrice($selectionId, $websiteId); |
79
|
|
|
} |
80
|
|
|
} |
81
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.