Completed
Pull Request — master (#5)
by Tim
02:21
created

AttributeLabelUpdateObserver   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 2
dl 0
loc 41
c 0
b 0
f 0
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A initializeAttribute() 0 17 2
A loadAttributeLabelByAttributeCodeAndStoreId() 0 4 1
1
<?php
2
3
/**
4
 * TechDivision\Import\Attribute\Observers\AttributeLabelUpdateObserver
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-attribute
18
 * @link      http://www.techdivision.com
19
 */
20
21
namespace TechDivision\Import\Attribute\Observers;
22
23
use TechDivision\Import\Attribute\Utils\ColumnKeys;
24
use TechDivision\Import\Attribute\Utils\MemberNames;
25
26
/**
27
 * Observer that update's the EAV attribute label.
28
 *
29
 * @author    Tim Wagner <[email protected]>
30
 * @copyright 2016 TechDivision GmbH <[email protected]>
31
 * @license   http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
32
 * @link      https://github.com/techdivision/import-attribute
33
 * @link      http://www.techdivision.com
34
 */
35
class AttributeLabelUpdateObserver extends AttributeLabelObserver
36
{
37
38
    /**
39
     * Initialize the attribute with the passed attributes and returns an instance.
40
     *
41
     * @param array $attr The attribute attributes
42
     *
43
     * @return array The initialized attribute
44
     */
45
    protected function initializeAttribute(array $attr)
46
    {
47
48
        // load value, store ID
49
        $storeId = $attr[MemberNames::STORE_ID];
50
51
        // load the attribute code from the row
52
        $attributeCode = $this->getValue(ColumnKeys::ATTRIBUTE_CODE);
53
54
        // query whether or not an attribute label
55
        if ($attributeLabel = $this->loadAttributeLabelByAttributeCodeAndStoreId($attributeCode, $storeId)) {
56
            return $this->mergeEntity($attributeLabel, $attr);
57
        }
58
59
        // simply return the attributes
60
        return $attr;
61
    }
62
63
    /**
64
     * Return's the EAV attribute label with the passed attribute code and store ID.
65
     *
66
     * @param string  $attributeCode The attribute code of the EAV attribute label to return
67
     * @param integer $storeId       The store ID of the EAV attribute label to return
68
     *
69
     * @return array The EAV attribute label
70
     */
71
    protected function loadAttributeLabelByAttributeCodeAndStoreId($attributeCode, $storeId)
72
    {
73
        return $this->getAttributeBunchProcessor()->loadAttributeLabelByAttributeCodeAndStoreId($attributeCode, $storeId);
74
    }
75
}
76