Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Data.php
Go to the documentation of this file.
1 <?php
9 
15 {
19  const XML_PATH_LANGUAGES = 'google/adwords/languages';
20 
21  const XML_PATH_LANGUAGE_CONVERT = 'google/adwords/language_convert';
22 
28  const XML_PATH_CONVERSION_JS_SRC = 'google/adwords/conversion_js_src';
29 
30  const XML_PATH_CONVERSION_IMG_SRC = 'google/adwords/conversion_img_src';
31 
37  const CONVERSION_VALUE_REGISTRY_NAME = 'google_adwords_conversion_value';
38 
42  const CONVERSION_VALUE_CURRENCY_REGISTRY_NAME = 'google_adwords_conversion_value_currency';
43 
48 
52  const XML_PATH_ACTIVE = 'google/adwords/active';
53 
54  const XML_PATH_CONVERSION_ID = 'google/adwords/conversion_id';
55 
56  const XML_PATH_CONVERSION_LANGUAGE = 'google/adwords/conversion_language';
57 
58  const XML_PATH_CONVERSION_FORMAT = 'google/adwords/conversion_format';
59 
60  const XML_PATH_CONVERSION_COLOR = 'google/adwords/conversion_color';
61 
62  const XML_PATH_CONVERSION_LABEL = 'google/adwords/conversion_label';
63 
64  const XML_PATH_CONVERSION_VALUE_TYPE = 'google/adwords/conversion_value_type';
65 
66  const XML_PATH_CONVERSION_VALUE = 'google/adwords/conversion_value';
67 
71  const XML_PATH_SEND_CURRENCY = 'google/adwords/send_currency';
72 
79 
81 
85  protected $_registry;
86 
91  public function __construct(
92  \Magento\Framework\App\Helper\Context $context,
93  \Magento\Framework\Registry $registry
94  ) {
95  parent::__construct($context);
96  $this->_registry = $registry;
97  }
98 
104  public function isGoogleAdwordsActive()
105  {
106  return $this->scopeConfig->isSetFlag(
107  self::XML_PATH_ACTIVE,
108  \Magento\Store\Model\ScopeInterface::SCOPE_STORE
109  ) &&
110  $this->getConversionId() &&
111  $this->getConversionLanguage() &&
112  $this->getConversionFormat() &&
113  $this->getConversionColor() &&
114  $this->getConversionLabel();
115  }
116 
122  public function getLanguageCodes()
123  {
124  return (array)$this->scopeConfig->getValue(self::XML_PATH_LANGUAGES, 'default');
125  }
126 
133  public function convertLanguageCodeToLocaleCode($language)
134  {
135  $convertArray = (array)$this->scopeConfig->getValue(self::XML_PATH_LANGUAGE_CONVERT, 'default');
136  return isset($convertArray[$language]) ? $convertArray[$language] : $language;
137  }
138 
144  public function getConversionJsSrc()
145  {
146  return (string)$this->scopeConfig->getValue(self::XML_PATH_CONVERSION_JS_SRC, 'default');
147  }
148 
154  public function getConversionImgSrc()
155  {
156  return sprintf(
157  $this->scopeConfig->getValue(self::XML_PATH_CONVERSION_IMG_SRC, 'default'),
158  $this->getConversionId(),
159  $this->getConversionLabel()
160  );
161  }
162 
168  public function getConversionId()
169  {
170  return (int)$this->scopeConfig->getValue(
171  self::XML_PATH_CONVERSION_ID,
172  \Magento\Store\Model\ScopeInterface::SCOPE_STORE
173  );
174  }
175 
181  public function getConversionLanguage()
182  {
183  return $this->scopeConfig->getValue(
184  self::XML_PATH_CONVERSION_LANGUAGE,
185  \Magento\Store\Model\ScopeInterface::SCOPE_STORE
186  );
187  }
188 
194  public function getConversionFormat()
195  {
196  return $this->scopeConfig->getValue(
197  self::XML_PATH_CONVERSION_FORMAT,
198  \Magento\Store\Model\ScopeInterface::SCOPE_STORE
199  );
200  }
201 
207  public function getConversionColor()
208  {
209  return $this->scopeConfig->getValue(
210  self::XML_PATH_CONVERSION_COLOR,
211  \Magento\Store\Model\ScopeInterface::SCOPE_STORE
212  );
213  }
214 
220  public function getConversionLabel()
221  {
222  return $this->scopeConfig->getValue(
223  self::XML_PATH_CONVERSION_LABEL,
224  \Magento\Store\Model\ScopeInterface::SCOPE_STORE
225  );
226  }
227 
233  public function getConversionValueType()
234  {
235  return $this->scopeConfig->getValue(
236  self::XML_PATH_CONVERSION_VALUE_TYPE,
237  \Magento\Store\Model\ScopeInterface::SCOPE_STORE
238  );
239  }
240 
246  public function isDynamicConversionValue()
247  {
249  }
250 
256  public function getConversionValueConstant()
257  {
258  return (double)$this->scopeConfig->getValue(
259  self::XML_PATH_CONVERSION_VALUE,
260  \Magento\Store\Model\ScopeInterface::SCOPE_STORE
261  );
262  }
263 
269  public function getConversionValue()
270  {
271  if ($this->isDynamicConversionValue()) {
272  $conversionValue = (double)$this->_registry->registry(self::CONVERSION_VALUE_REGISTRY_NAME);
273  } else {
274  $conversionValue = $this->getConversionValueConstant();
275  }
276  return empty($conversionValue) ? self::CONVERSION_VALUE_DEFAULT : $conversionValue;
277  }
278 
285  {
286  return $this->scopeConfig->isSetFlag(
287  self::XML_PATH_SEND_CURRENCY,
288  \Magento\Store\Model\ScopeInterface::SCOPE_STORE
289  );
290  }
291 
297  public function getConversionValueCurrency()
298  {
299  if ($this->hasSendConversionValueCurrency()) {
300  return (string) $this->_registry->registry(self::CONVERSION_VALUE_CURRENCY_REGISTRY_NAME);
301  }
302  return false;
303  }
304 }
convertLanguageCodeToLocaleCode($language)
Definition: Data.php:133
const CONVERSION_VALUE_CURRENCY_REGISTRY_NAME
Definition: Data.php:42
__construct(\Magento\Framework\App\Helper\Context $context, \Magento\Framework\Registry $registry)
Definition: Data.php:91