FrontendStorageManager.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Catalog\Block;
  7. use Magento\Catalog\Model\FrontendStorageConfigurationPool;
  8. use Magento\Catalog\Model\Product\ProductFrontendAction\Synchronizer;
  9. use Magento\Framework\App\Config;
  10. use Magento\Framework\View\Element\Template\Context;
  11. /**
  12. * Provide information to frontend storage manager
  13. *
  14. * @api
  15. * @since 102.0.0
  16. */
  17. class FrontendStorageManager extends \Magento\Framework\View\Element\Template
  18. {
  19. /**
  20. * @var FrontendStorageConfigurationPool
  21. */
  22. private $storageConfigurationPool;
  23. /**
  24. * @var Config
  25. */
  26. private $appConfig;
  27. /**
  28. * @param Context $context
  29. * @param FrontendStorageConfigurationPool $storageConfigurationPool
  30. * @param Config $appConfig
  31. * @param array $data
  32. */
  33. public function __construct(
  34. Context $context,
  35. FrontendStorageConfigurationPool $storageConfigurationPool,
  36. Config $appConfig,
  37. array $data = []
  38. ) {
  39. parent::__construct($context, $data);
  40. $this->storageConfigurationPool = $storageConfigurationPool;
  41. $this->appConfig = $appConfig;
  42. }
  43. /**
  44. * Merge and retrieve configuration of storages like ids_storage or product_storage
  45. * in json format
  46. *
  47. * @return string
  48. * @since 102.0.0
  49. */
  50. public function getConfigurationJson()
  51. {
  52. $configuration = $this->getData('configuration') ?: [];
  53. foreach ($configuration as $namespace => & $storageConfig) {
  54. $dynamicStorage = $this->storageConfigurationPool->get($namespace);
  55. if ($dynamicStorage) {
  56. $storageConfig = array_replace_recursive($storageConfig, $dynamicStorage->get());
  57. }
  58. $storageConfig['allowToSendRequest'] = $this->appConfig->getValue(
  59. Synchronizer::ALLOW_SYNC_WITH_BACKEND_PATH
  60. );
  61. }
  62. return json_encode($configuration);
  63. }
  64. }