1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Richdynamix\PersonalisedProducts\Helper; |
4
|
|
|
|
5
|
|
|
use \Magento\Framework\App\Config\ScopeConfigInterface as ScopeConfigInterface; |
6
|
|
|
use \Magento\Store\Model\ScopeInterface as ScopeInterface; |
7
|
|
|
use \Magento\Framework\App\Helper\Context as Context; |
8
|
|
|
|
9
|
|
|
/** |
10
|
|
|
* Configuration class to retrieve module options from the database |
11
|
|
|
* |
12
|
|
|
* @category Richdynamix |
13
|
|
|
* @package PersonalisedProducts |
14
|
|
|
* @author Steven Richardson ([email protected]) @mage_gizmo |
15
|
|
|
*/ |
16
|
|
|
class Config extends \Magento\Framework\App\Helper\AbstractHelper |
17
|
|
|
{ |
18
|
|
|
/** |
19
|
|
|
* @var ScopeConfigInterface |
20
|
|
|
*/ |
21
|
|
|
private $_scopeConfig; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @var ScopeInterface |
25
|
|
|
*/ |
26
|
|
|
private $_storeScope; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* Is the module enabled |
30
|
|
|
*/ |
31
|
|
|
const ENABLED = 'personalised_products/general/enabled'; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* The event server access key |
35
|
|
|
*/ |
36
|
|
|
const EVENT_SERVER_ACCESS_KEY = 'personalised_products/general/access_key'; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* The event server URL |
40
|
|
|
*/ |
41
|
|
|
const EVENT_SERVER_URL = 'personalised_products/general/url'; |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* The event server port |
45
|
|
|
*/ |
46
|
|
|
const EVENT_SERVER_PORT = 'personalised_products/general/port'; |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* Similarity engine URL (Upsell engine) |
50
|
|
|
*/ |
51
|
|
|
const SIMILARITY_ENGINE_URL = 'personalised_products/similarity_engine/url'; |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* Similarity engine port (Upsell engine) |
55
|
|
|
*/ |
56
|
|
|
const SIMILARITY_ENGINE_PORT = 'personalised_products/similarity_engine/port'; |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* Similarity engine products to return count |
60
|
|
|
*/ |
61
|
|
|
const SIMILARITY_PRODUCT_COUNT = 'personalised_products/similarity_engine/product_count'; |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* Similarity engine category filter check |
65
|
|
|
*/ |
66
|
|
|
const SIMILARITY_USE_CATEGORY_FILTER = 'personalised_products/similarity_engine/use_categories'; |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* Switch to replace Rule Based Upsells (enterprise edition only) |
70
|
|
|
*/ |
71
|
|
|
const SIMILARITY_REPLACE_RULES = 'personalised_products/similarity_engine/replace_rules'; |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* Complementary engine URL (Crosssell engine) |
75
|
|
|
*/ |
76
|
|
|
const COMPLEMENTARY_ENGINE_URL = 'personalised_products/complementary_engine/url'; |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* Complementary engine port (Crosssell engine) |
80
|
|
|
*/ |
81
|
|
|
const COMPLEMENTARY_ENGINE_PORT = 'personalised_products/complementary_engine/port'; |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* Complementary engine product to return count |
85
|
|
|
*/ |
86
|
|
|
const COMPLEMENTARY_PRODUCT_COUNT = 'personalised_products/complementary_engine/product_count'; |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* Switch to replace Rule Based Cross sells (enterprise edition only) |
90
|
|
|
*/ |
91
|
|
|
const COMPLEMENTARY_REPLACE_RULES = 'personalised_products/complementary_engine/replace_rules'; |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* Config constructor. |
95
|
|
|
* @param ScopeConfigInterface $scopeConfig |
96
|
|
|
* @param Context $context |
97
|
|
|
*/ |
98
|
|
|
public function __construct(ScopeConfigInterface $scopeConfig, Context $context) |
99
|
|
|
{ |
100
|
|
|
$this->_scopeConfig = $scopeConfig; |
101
|
|
|
$this->_storeScope = \Magento\Store\Model\ScopeInterface::SCOPE_STORE; |
102
|
|
|
parent::__construct($context); |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* Global method for getting configuration value |
107
|
|
|
* |
108
|
|
|
* @param $itemPath |
109
|
|
|
* @return mixed |
110
|
|
|
*/ |
111
|
|
|
public function getItem($itemPath) |
112
|
|
|
{ |
113
|
|
|
return $this->scopeConfig->getValue($itemPath, $this->_storeScope); |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
/** |
117
|
|
|
* Check the module is enabled |
118
|
|
|
* |
119
|
|
|
* @return mixed |
120
|
|
|
*/ |
121
|
|
|
public function isEnabled() |
122
|
|
|
{ |
123
|
|
|
return $this->getItem(self::ENABLED); |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
/** |
127
|
|
|
* Get a product count for the engine (default to 4) |
128
|
|
|
* |
129
|
|
|
* @param $engineProductCount |
130
|
|
|
* @return mixed|string |
131
|
|
|
*/ |
132
|
|
|
public function getProductCount($engineProductCount) |
133
|
|
|
{ |
134
|
|
|
return $this->getItem($engineProductCount) ? $this->getItem($engineProductCount) : '4'; |
135
|
|
|
} |
136
|
|
|
} |
137
|
|
|
|