Completed
Push — 13.x ( 89717a )
by Tim
05:33
created

initializeProductMediaGallery()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 15

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 15
ccs 0
cts 9
cp 0
rs 9.7666
c 0
b 0
f 0
cc 2
nc 2
nop 1
crap 6
1
<?php
2
3
/**
4
 * TechDivision\Import\Product\Media\Ee\Observers\EeMediaGalleryUpdateObserver
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-media-ee
18
 * @link      http://www.techdivision.com
19
 */
20
21
namespace TechDivision\Import\Product\Media\Ee\Observers;
22
23
use TechDivision\Import\Product\Media\Ee\Utils\MemberNames;
24
25
/**
26
 * Observer that provides extended mapping functionality to map a SKU to a row ID (EE Feature).
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-media-ee
32
 * @link      http://www.techdivision.com
33
 */
34
class EeMediaGalleryUpdateObserver extends EeMediaGalleryObserver
35
{
36
37
    /**
38
     * Initialize the product media gallery with the passed attributes and returns an instance.
39
     *
40
     * @param array $attr The product media gallery attributes
41
     *
42
     * @return array The initialized product media gallery
43
     */
44
    protected function initializeProductMediaGallery(array $attr)
45
    {
46
47
        // load the value and the attribute ID
48
        $value = $attr[MemberNames::VALUE];
49
        $attributeId = $attr[MemberNames::ATTRIBUTE_ID];
50
51
        // query whether the product media gallery entity already exists or not
52
        if ($entity = $this->loadProductMediaGallery($attributeId, $value)) {
53
            return $this->mergeEntity($entity, $attr);
54
        }
55
56
        // simply return the attributes
57
        return $attr;
58
    }
59
60
    /**
61
     * Initialize the product media gallery value to entity with the passed attributes and returns an instance.
62
     *
63
     * @param array $attr The product media gallery value to entity attributes
64
     *
65
     * @return array|null The initialized product media gallery value to entity, or NULL if the product media gallery value to entity already exists
66
     */
67
    protected function initializeProductMediaGalleryValueToEntity(array $attr)
68
    {
69
70
        // load the row/value ID
71
        $rowId = $attr[MemberNames::ROW_ID];
72
        $valueId = $attr[MemberNames::VALUE_ID];
73
74
        // query whether the product media gallery value to entity entity already exists or not
75
        if ($this->loadProductMediaGalleryValueToEntityByValueIdAndRowId($valueId, $rowId)) {
76
            return;
77
        }
78
79
        // simply return the attributes
80
        return $attr;
81
    }
82
83
    /**
84
     * Load's the product media gallery with the passed attribute ID + value.
85
     *
86
     * @param integer $attributeId The attribute ID of the product media gallery to load
87
     * @param string  $value       The value of the product media gallery to load
88
     *
89
     * @return array The product media gallery
90
     */
91
    protected function loadProductMediaGallery($attributeId, $value)
92
    {
93
        return $this->getProductMediaProcessor()->loadProductMediaGallery($attributeId, $value);
94
    }
95
96
    /**
97
     * Load's the product media gallery with the passed value/entity ID.
98
     *
99
     * @param integer $valueId The value ID of the product media gallery value to entity to load
100
     * @param integer $rowId   The row ID of the product media gallery value to entity to load
101
     *
102
     * @return array The product media gallery
103
     */
104
    protected function loadProductMediaGalleryValueToEntityByValueIdAndRowId($valueId, $rowId)
105
    {
106
        return $this->getProductMediaProcessor()->loadProductMediaGalleryValueToEntityByValueIdAndRowId($valueId, $rowId);
0 ignored issues
show
Bug introduced by
The method loadProductMediaGalleryV...tityByValueIdAndRowId() does not exist on TechDivision\Import\Prod...MediaProcessorInterface. Did you maybe mean loadProductMediaGallery()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
107
    }
108
}
109