Completed
Pull Request — master (#24)
by Tim
01:47
created

BunchSubject::persistUrlRewrite()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
c 0
b 0
f 0
rs 10
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
/**
4
 * TechDivision\Import\Category\Subjects\BunchSubject
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-category
18
 * @link      http://www.techdivision.com
19
 */
20
21
namespace TechDivision\Import\Category\Subjects;
22
23
use TechDivision\Import\Subjects\ExportableTrait;
24
use TechDivision\Import\Subjects\ExportableSubjectInterface;
25
use TechDivision\Import\Category\Utils\PageLayoutKeys;
26
use TechDivision\Import\Category\Utils\DisplayModeKeys;
27
28
/**
29
 * The subject implementation that handles the business logic to persist products.
30
 *
31
 * @author    Tim Wagner <[email protected]>
32
 * @copyright 2016 TechDivision GmbH <[email protected]>
33
 * @license   http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
34
 * @link      https://github.com/techdivision/import-category
35
 * @link      http://www.techdivision.com
36
 */
37
class BunchSubject extends AbstractCategorySubject implements ExportableSubjectInterface
0 ignored issues
show
Bug introduced by
There is one abstract method loadEavAttributeOptionVa...eCodeAndStoreIdAndValue in this class; you could implement it, or declare this class as abstract.
Loading history...
38
{
39
40
    /**
41
     * The trait that implements the export functionality.
42
     *
43
     * @var \TechDivision\Import\Subjects\ExportableTrait
44
     */
45
    use ExportableTrait;
46
47
    /**
48
     * The array with the available display mode keys.
49
     *
50
     * @var array
51
     */
52
    protected $availableDisplayModes = array(
53
        'Products only'             => DisplayModeKeys::DISPLAY_MODE_PRODUCTS_ONLY,
54
        'Static block only'         => DisplayModeKeys::DISPLAY_MODE_STATIC_BLOCK_ONLY,
55
        'Static block and products' => DisplayModeKeys::DISPLAY_MODE_BOTH
56
    );
57
58
    /**
59
     * The array with the available page layout keys.
60
     *
61
     * @var array
62
     */
63
    protected $availablePageLayouts = array(
64
        '1 column'                 => PageLayoutKeys::PAGE_LAYOUT_1_COLUMN,
65
        '2 columns with left bar'  => PageLayoutKeys::PAGE_LAYOUT_2_COLUMNS_LEFT,
66
        '2 columns with right bar' => PageLayoutKeys::PAGE_LAYOUT_2_COLUMNS_RIGHT,
67
        '3 columns'                => PageLayoutKeys::PAGE_LAYOUT_3_COLUMNS,
68
        'Empty'                    => PageLayoutKeys::PAGE_LAYOUT_EMPTY
69
    );
70
    /**
71
     * The default callback mappings for the Magento standard category attributes.
72
     *
73
     * @var array
74
     */
75
    protected $defaultCallbackMappings = array(
76
        'display_mode' => array('import_category.callback.display.mode'),
77
        'page_layout'  => array('import_category.callback.page.layout'),
78
    );
79
80
    /**
81
     * Return's the default callback mappings.
82
     *
83
     * @return array The default callback mappings
84
     */
85
    public function getDefaultCallbackMappings()
86
    {
87
        return $this->defaultCallbackMappings;
88
    }
89
90
    /**
91
     * Return's the display mode for the passed display mode string.
92
     *
93
     * @param string $displayMode The display mode string to return the key for
94
     *
95
     * @return integer The requested display mode
96
     * @throws \Exception Is thrown, if the requested display mode is not available
97
     */
98
    public function getDisplayModeByValue($displayMode)
99
    {
100
101
        // query whether or not, the requested display mode is available
102
        if (isset($this->availableDisplayModes[$displayMode])) {
103
            return $this->availableDisplayModes[$displayMode];
104
        }
105
106
        // throw an exception, if not
107
        throw new \Exception(
108
            $this->appendExceptionSuffix(
109
                sprintf(
110
                    'Found invalid display mode %s',
111
                    $displayMode
112
                )
113
            )
114
        );
115
    }
116
117
    /**
118
     * Return's the page layout for the passed page layout string.
119
     *
120
     * @param string $pageLayout The page layout string to return the key for
121
     *
122
     * @return integer The requested page layout
123
     * @throws \Exception Is thrown, if the requested page layout is not available
124
     */
125
    public function getPageLayoutByValue($pageLayout)
126
    {
127
128
        // query whether or not, the requested display mode is available
129
        if (isset($this->availablePageLayouts[$pageLayout])) {
130
            return $this->availablePageLayouts[$pageLayout];
131
        }
132
133
        // throw an exception, if not
134
        throw new \Exception(
135
            $this->appendExceptionSuffix(
136
                sprintf(
137
                    'Found invalid page layout %s',
138
                    $pageLayout
139
                )
140
            )
141
        );
142
    }
143
}
144