Completed
Pull Request — master (#1)
by
unknown
12:05
created

StockbaseConfiguration::getOrderPrefix()   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
cc 1
eloc 2
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 4
rs 10
ccs 0
cts 0
cp 0
crap 2
1
<?php
2
3
namespace Stockbase\Integration\Model\Config;
4
5
use Magento\Framework\App\Config\ScopeConfigInterface;
6
use Magento\Framework\App\Config\Storage\WriterInterface;
7
use Stockbase\Integration\Model\Config\Source\Environment;
8
9
/**
10
 * Stockbase main mobule configuration resource wrapper.
11
 */
12
class StockbaseConfiguration
13
{
14
15
    const CONFIG_MODULE_ENABLED = 'stockbase/integration/module_enabled';
16
    const CONFIG_ENVIRONMENT = 'stockbase/integration/environment';
17
    const CONFIG_USERNAME = 'stockbase/integration/username';
18
    const CONFIG_PASSWORD = 'stockbase/integration/password';
19
    const CONFIG_EAN_FIELD = 'stockbase/integration/ean_field';
20
    const CONFIG_ORDER_PREFIX = 'stockbase/integration/order_prefix';
21
    const CONFIG_IMAGES_SYNC = 'stockbase/integration/images_sync_enabled';
22
    const CONFIG_IMAGES_EANS = 'stockbase/integration/images_eans';
23
24
    /**
25
     * @var ScopeConfigInterface
26
     */
27
    private $scopeConfig;
28
29
    /**
30 2
     *  @var WriterInterface
31
     */
32 2
    protected $configWriter;
33 2
34
    /**
35
     * StockbaseConfiguration constructor.
36
     * @param ScopeConfigInterface $scopeConfig
37
     */
38 2
    public function __construct(
39
        ScopeConfigInterface $scopeConfig,
40 2
        WriterInterface $configWriter
41
    ) {
42
        $this->scopeConfig = $scopeConfig;
43
        $this->configWriter = $configWriter;
44
    }
45
46
    /**
47
     * @return bool
48 2
     */
49
    public function isModuleEnabled()
50 2
    {
51
        return (bool) $this->scopeConfig->getValue(self::CONFIG_MODULE_ENABLED);
52
    }
53
54
    /**
55
     * Gets Stockbase environment name.
56 2
     *
57
     * @return string
58 2
     */
59
    public function getEnvironment()
60
    {
61
        return $this->scopeConfig->getValue(self::CONFIG_ENVIRONMENT) ?: Environment::STAGING;
62
    }
63
64 2
    /**
65
     * @return string
66 2
     */
67
    public function getUsername()
68
    {
69
        return $this->scopeConfig->getValue(self::CONFIG_USERNAME);
70
    }
71
72 2
    /**
73
     * @return string
74 2
     */
75
    public function getPassword()
76
    {
77
        return $this->scopeConfig->getValue(self::CONFIG_PASSWORD);
78
    }
79
80 2
    /**
81
     * @return string
82 2
     */
83
    public function getEanFieldName()
84
    {
85
        return $this->scopeConfig->getValue(self::CONFIG_EAN_FIELD);
86
    }
87
88
    /**
89
     * @return string
90
     */
91
    public function getOrderPrefix()
92
    {
93
        return $this->scopeConfig->getValue(self::CONFIG_ORDER_PREFIX);
94
    }
95
96
    /**
97
     * @return bool
98
     */
99
    public function isImagesSyncEnabled()
100
    {
101
        return (bool) $this->scopeConfig->getValue(self::CONFIG_IMAGES_SYNC);
102
    }
103
104
    /**
105
     * @return mixed
106
     */
107
    public function getImagesEans()
108
    {
109
        return $this->scopeConfig->getValue(self::CONFIG_IMAGES_EANS);
110
    }
111
112
    /**
113
     * @return mixed
114
     */
115
    public function saveImagesEans($eans)
116
    {
117
        return $this->configWriter->save(self::CONFIG_IMAGES_EANS, $eans, 'default', 0);
118
    }
119
120
}
121