1
1
<?php
2
2
/**
3
- * Copyright © 2015 ToBai. All rights reserved.
3
+ * Copyright © 2016 ToBai. All rights reserved.
4
4
*/
5
5
namespace Tobai \GeoStoreSwitcher \Model \Config ;
6
6
7
- use Magento \Framework \ App \ Config \ ScopeConfigInterface ;
7
+ use Magento \Store \ Api \ Data \ StoreInterface ;
8
8
9
9
class General
10
10
{
11
11
/**
12
- * @var \Magento\Framework\App \Config\ScopeConfigInterface
12
+ * @var \Tobai\GeoStoreSwitcher\Model \Config\ScopeConfig
13
13
*/
14
14
protected $ scopeConfig ;
15
15
16
16
/**
17
- * @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
17
+ * @var \Tobai\GeoStoreSwitcher\Helper\Config\AppState
18
+ */
19
+ protected $ appStateHelper ;
20
+
21
+ /**
22
+ * @var \Tobai\GeoStoreSwitcher\Helper\Config\Request
23
+ */
24
+ protected $ requestHelper ;
25
+
26
+ /**
27
+ * @param \Tobai\GeoStoreSwitcher\Model\Config\ScopeConfig $scopeConfig
28
+ * @param \Tobai\GeoStoreSwitcher\Helper\Config\AppState $appStateHelper
29
+ * @param \Tobai\GeoStoreSwitcher\Helper\Config\Request $requestHelper
18
30
*/
19
31
public function __construct (
20
- ScopeConfigInterface $ scopeConfig
32
+ \Tobai \GeoStoreSwitcher \Model \Config \ScopeConfig $ scopeConfig ,
33
+ \Tobai \GeoStoreSwitcher \Helper \Config \AppState $ appStateHelper ,
34
+ \Tobai \GeoStoreSwitcher \Helper \Config \Request $ requestHelper
21
35
) {
22
36
$ this ->scopeConfig = $ scopeConfig ;
37
+ $ this ->appStateHelper = $ appStateHelper ;
38
+ $ this ->requestHelper = $ requestHelper ;
39
+ }
40
+
41
+ /**
42
+ * @param \Magento\Store\Api\Data\StoreInterface $store
43
+ * @return $this
44
+ */
45
+ public function setOriginStore (StoreInterface $ store )
46
+ {
47
+ $ this ->scopeConfig ->setOriginStore ($ store );
48
+ return $ this ;
49
+ }
50
+
51
+ /**
52
+ * @return bool
53
+ */
54
+ public function isAvailable ()
55
+ {
56
+ return $ this ->appStateHelper ->isFrontendArea ()
57
+ && !$ this ->requestHelper ->isCurrentIp ($ this ->getWhiteIps ())
58
+ && !$ this ->requestHelper ->isCurrentUserAgent ($ this ->getWhiteUa ())
59
+ && $ this ->isActive ();
23
60
}
24
61
25
62
/**
26
63
* @return bool
27
64
*/
28
65
public function isActive ()
29
66
{
30
- return $ this ->scopeConfig ->isSetFlag ('tobai_geo_store_switcher/general/active ' );
67
+ return $ this ->scopeConfig ->getFrontendStoreOrBackendValue ('tobai_geo_store_switcher/general/active ' );
68
+ }
69
+
70
+ /**
71
+ * @return array
72
+ */
73
+ public function getWhiteIps ()
74
+ {
75
+ $ whiteIps = $ this ->scopeConfig ->getStoreValue ('tobai_geo_store_switcher/general/white_ips ' );
76
+ return !empty ($ whiteIps ) ? preg_split ('#\s*,\s*# ' , $ whiteIps , null , PREG_SPLIT_NO_EMPTY ) : [];
77
+ }
78
+
79
+ /**
80
+ * @return string
81
+ */
82
+ public function getWhiteUa ()
83
+ {
84
+ return $ this ->scopeConfig ->getStoreValue ('tobai_geo_store_switcher/general/white_ua ' );
31
85
}
32
86
33
87
/**
34
88
* @return bool
35
89
*/
36
90
public function isOverwriteDefault ()
37
91
{
38
- return $ this ->scopeConfig ->isSetFlag ('tobai_geo_store_switcher/general/overwrite_default ' );
92
+ return ( bool ) $ this ->scopeConfig ->getWebsiteValue ('tobai_geo_store_switcher/general/overwrite_default ' );
39
93
}
40
94
41
95
/**
@@ -44,7 +98,7 @@ public function isOverwriteDefault()
44
98
public function getDefaultStore ()
45
99
{
46
100
return $ this ->isOverwriteDefault ()
47
- ? $ this ->scopeConfig ->getValue ('tobai_geo_store_switcher/general/default_store ' )
101
+ ? $ this ->scopeConfig ->getWebsiteValue ('tobai_geo_store_switcher/general/default_store ' )
48
102
: false ;
49
103
}
50
104
@@ -53,23 +107,24 @@ public function getDefaultStore()
53
107
*/
54
108
public function isMappingSore ()
55
109
{
56
- return $ this ->scopeConfig ->isSetFlag ('tobai_geo_store_switcher/general/mapping_sore ' );
110
+ return ( bool ) $ this ->scopeConfig ->getWebsiteValue ('tobai_geo_store_switcher/general/mapping_sore ' );
57
111
}
58
112
59
113
/**
60
114
* @return bool
61
115
*/
62
116
public function isCountries ()
63
117
{
64
- return $ this ->scopeConfig ->isSetFlag ('tobai_geo_store_switcher/general/by_countries ' );
118
+ return $ this ->isActive ()
119
+ && $ this ->scopeConfig ->getFrontendWebsiteOrBackendValue ('tobai_geo_store_switcher/general/by_countries ' );
65
120
}
66
121
67
122
/**
68
123
* @return array
69
124
*/
70
125
public function getCountryList ()
71
126
{
72
- $ countriesData = $ this ->scopeConfig ->getValue ('tobai_geo_store_switcher/general/country_list ' );
127
+ $ countriesData = $ this ->scopeConfig ->getFrontendWebsiteOrBackendValue ('tobai_geo_store_switcher/general/country_list ' );
73
128
$ countries = $ this ->isCountries () && !empty ($ countriesData ) ? explode (', ' , $ countriesData ) : [];
74
129
return $ countries ;
75
130
}
@@ -80,15 +135,17 @@ public function getCountryList()
80
135
*/
81
136
public function getCountryStore ($ countryCode )
82
137
{
83
- return $ this ->scopeConfig ->getValue ("tobai_geo_store_switcher/ {$ countryCode }/store " );
138
+ return $ this ->scopeConfig ->getWebsiteValue ("tobai_geo_store_switcher/ {$ countryCode }/store " );
84
139
}
85
140
86
141
/**
87
142
* @return int
88
143
*/
89
144
public function getGroupCount ()
90
145
{
91
- return (int )$ this ->scopeConfig ->getValue ('tobai_geo_store_switcher/general/by_groups ' );
146
+ return $ this ->isActive ()
147
+ ? (int )$ this ->scopeConfig ->getFrontendWebsiteOrBackendValue ('tobai_geo_store_switcher/general/by_groups ' )
148
+ : 0 ;
92
149
}
93
150
94
151
/**
@@ -97,7 +154,7 @@ public function getGroupCount()
97
154
*/
98
155
public function getGroupCountryList ($ group )
99
156
{
100
- $ countriesData = $ this ->scopeConfig ->getValue ("tobai_geo_store_switcher/group_ {$ group }/country_list " );
157
+ $ countriesData = $ this ->scopeConfig ->getFrontendWebsiteOrBackendValue ("tobai_geo_store_switcher/group_ {$ group }/country_list " );
101
158
$ countries = !empty ($ countriesData ) ? explode (', ' , $ countriesData ) : [];
102
159
return $ countries ;
103
160
}
@@ -108,6 +165,6 @@ public function getGroupCountryList($group)
108
165
*/
109
166
public function getGroupStore ($ group )
110
167
{
111
- return $ this ->scopeConfig ->getValue ("tobai_geo_store_switcher/group_ {$ group }/store " );
168
+ return $ this ->scopeConfig ->getWebsiteValue ("tobai_geo_store_switcher/group_ {$ group }/store " );
112
169
}
113
170
}
0 commit comments