-
Notifications
You must be signed in to change notification settings - Fork 81
Expand file tree
/
Copy pathSpcTokenSyncStatus.php
More file actions
82 lines (67 loc) · 2.58 KB
/
SpcTokenSyncStatus.php
File metadata and controls
82 lines (67 loc) · 2.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
<?php
namespace Amazon\Pay\Block\Adminhtml\System\Config;
use Magento\Backend\Block\Template\Context;
use Magento\Framework\Data\Form\Element\AbstractElement;
use Magento\Store\Api\StoreRepositoryInterface;
use Magento\Framework\App\ProductMetadataInterface;
class SpcTokenSyncStatus extends \Magento\Config\Block\System\Config\Form\Field
{
protected $_template = 'Amazon_Pay::system/config/sync-status.phtml';
protected $storeRepository;
public function __construct(
Context $context,
StoreRepositoryInterface $storeRepository,
ProductMetadataInterface $productMetadata,
array $data = []
)
{
// Special case for lower than Magento 2.4 version
if ($productMetadata->getVersion() < '2.4') {
parent::__construct($context, $data);
}
// Magento 2.4.0+
else {
parent::__construct($context, $data, null);
}
$this->storeRepository = $storeRepository;
}
/**
* @param AbstractElement $element
* @return mixed
*/
public function render(AbstractElement $element)
{
$element->unsScope()->unsCanUseWebsiteValue()->unsCanUseDefaultValue();
return parent::render($element);
}
/**
* @param AbstractElement $element
* @return mixed
*/
protected function _getElementHtml(AbstractElement $element)
{
return $this->_toHtml();
}
public function getConfigForAllStores()
{
$storeValues = [];
$noSyncMessage = __($this->_scopeConfig->getValue('payment/amazon_payment_v2/spc_tokens_sync_status_no'));
$successSyncMessage = __($this->_scopeConfig->getValue('payment/amazon_payment_v2/spc_tokens_sync_status_success'));
$failedSyncMessage = __($this->_scopeConfig->getValue('payment/amazon_payment_v2/spc_tokens_sync_status_failed'));
foreach ($this->storeRepository->getList() as $store) {
if ($store->getId() == 0) {
continue;
}
$syncTime = $this->_scopeConfig->getValue('payment/amazon_pay/spc_tokens_last_sync', 'store', $store->getId());
$syncStatus = $this->_scopeConfig->getValue('payment/amazon_pay/spc_tokens_sync_status', 'store', $store->getId());
$value = $syncTime
? (strpos($syncStatus, 'failed') !== false ? $failedSyncMessage : $successSyncMessage) .' '. $syncTime
: $noSyncMessage;
$storeValues[] = [
'store_name' => $store->getName(),
'value' => $value
];
}
return $storeValues;
}
}