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
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Catalog\Block;
use Magento\Catalog\Model\FrontendStorageConfigurationPool;
use Magento\Catalog\Model\Product\ProductFrontendAction\Synchronizer;
use Magento\Framework\App\Config;
use Magento\Framework\View\Element\Template\Context;
/**
* Provide information to frontend storage manager
*
* @api
* @since 102.0.0
*/
class FrontendStorageManager extends \Magento\Framework\View\Element\Template
{
/**
* @var FrontendStorageConfigurationPool
*/
private $storageConfigurationPool;
/**
* @var Config
*/
private $appConfig;
/**
* @param Context $context
* @param FrontendStorageConfigurationPool $storageConfigurationPool
* @param Config $appConfig
* @param array $data
*/
public function __construct(
Context $context,
FrontendStorageConfigurationPool $storageConfigurationPool,
Config $appConfig,
array $data = []
) {
parent::__construct($context, $data);
$this->storageConfigurationPool = $storageConfigurationPool;
$this->appConfig = $appConfig;
}
/**
* Merge and retrieve configuration of storages like ids_storage or product_storage
* in json format
*
* @return string
* @since 102.0.0
*/
public function getConfigurationJson()
{
$configuration = $this->getData('configuration') ?: [];
foreach ($configuration as $namespace => & $storageConfig) {
$dynamicStorage = $this->storageConfigurationPool->get($namespace);
if ($dynamicStorage) {
$storageConfig = array_replace_recursive($storageConfig, $dynamicStorage->get());
}
$storageConfig['allowToSendRequest'] = $this->appConfig->getValue(
Synchronizer::ALLOW_SYNC_WITH_BACKEND_PATH
);
}
return json_encode($configuration);
}
}