Completed
Push — master ( 235157...2175ac )
by Tim
10s
created

initializeBundleOptionValue()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 18
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 18
ccs 0
cts 10
cp 0
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 7
nc 2
nop 1
crap 6
1
<?php
2
3
/**
4
 * TechDivision\Import\Product\Bundle\Observers\BundleOptionValueUpdateObserver
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
26
/**
27
 * Oberserver that provides functionality for the bundle option value add/update operation.
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-product-bundle
33
 * @link      http://www.techdivision.com
34
 */
35
class BundleOptionValueUpdateObserver extends BundleOptionValueObserver
36
{
37
38
    /**
39
     * Initialize the bundle option value with the passed attributes and returns an instance.
40
     *
41
     * @param array $attr The bundle option value attributes
42
     *
43
     * @return array|null The initialized bundle option value, or NULL if the option value already exists
44
     */
45
    protected function initializeBundleOptionValue(array $attr)
46
    {
47
48
        // load and map the parent option ID
49
        $parentId = $this->mapSku($this->getValue(ColumnKeys::BUNDLE_PARENT_SKU));
0 ignored issues
show
Bug introduced by
The method getValue() does not seem to exist on object<TechDivision\Impo...ionValueUpdateObserver>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
50
51
        // load the parent ID, the name and the store ID
52
        $name = $this->getValue(ColumnKeys::BUNDLE_VALUE_NAME);
0 ignored issues
show
Bug introduced by
The method getValue() does not seem to exist on object<TechDivision\Impo...ionValueUpdateObserver>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
53
        $storeId = $this->getRowStoreId(StoreViewCodes::ADMIN);
54
55
        // try to load the bundle option value with the passed name/store/parent ID
56
        if ($this->loadBundleOptionValue($name, $storeId, $parentId)) {
57
            return;
58
        }
59
60
        // simply return the attributes
61
        return $attr;
62
    }
63
64
    /**
65
     * Load's the bundle option value with the passed name, store + parent ID.
66
     *
67
     * @param string  $title    The title of the bundle option value to be returned
68
     * @param integer $storeId  The store ID of the bundle option value to be returned
69
     * @param integer $parentId The entity of the product the bundle option value is related with
70
     *
71
     * @return array The bundle option
72
     */
73
    protected function loadBundleOptionValue($title, $storeId, $parentId)
74
    {
75
        return $this->getSubject()->loadBundleOptionValue($title, $storeId, $parentId);
76
    }
77
78
    /**
79
     * Return the entity ID for the passed SKU.
80
     *
81
     * @param string $sku The SKU to return the entity ID for
82
     *
83
     * @return integer The mapped entity ID
84
     * @throws \Exception Is thrown if the SKU is not mapped yet
85
     */
86
    protected function mapSku($sku)
87
    {
88
        return $this->getSubject()->mapSkuToEntityId($sku);
89
    }
90
91
    /**
92
     * Return's the store ID of the actual row, or of the default store
93
     * if no store view code is set in the CSV file.
94
     *
95
     * @param string|null $default The default store view code to use, if no store view code is set in the CSV file
96
     *
97
     * @return integer The ID of the actual store
98
     * @throws \Exception Is thrown, if the store with the actual code is not available
99
     */
100
    protected function getRowStoreId($default = null)
101
    {
102
        return $this->getSubject()->getRowStoreId($default);
103
    }
104
}
105