Completed
Push — 9.x ( 2209b0 )
by Tim
03:29
created

BundleOptionValueUpdateObserver::mapSku()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 4
cp 0
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
crap 2
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));
50
51
        // load the parent ID, the name and the store ID
52
        $name = $this->getValue(ColumnKeys::BUNDLE_VALUE_NAME);
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->getProductBundleProcessor()->loadBundleOptionValue($title, $storeId, $parentId);
76
    }
77
78
    /**
79
     * Return's the store ID of the actual row, or of the default store
80
     * if no store view code is set in the CSV file.
81
     *
82
     * @param string|null $default The default store view code to use, if no store view code is set in the CSV file
83
     *
84
     * @return integer The ID of the actual store
85
     * @throws \Exception Is thrown, if the store with the actual code is not available
86
     */
87
    protected function getRowStoreId($default = null)
88
    {
89
        return $this->getSubject()->getRowStoreId($default);
0 ignored issues
show
Bug introduced by
The method getRowStoreId() does not exist on TechDivision\Import\Subjects\SubjectInterface. Did you maybe mean getRow()?

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...
90
    }
91
}
92