AbstractTotalsProcessor.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Checkout\Model\Layout;
  7. use Magento\Framework\App\Config\ScopeConfigInterface;
  8. /**
  9. * Abstract totals processor.
  10. *
  11. * Can be used to process totals information that will be rendered during checkout.
  12. * Abstract class provides sorting routing to sort total information based on configuration settings.
  13. *
  14. * @api
  15. * @since 100.0.2
  16. */
  17. abstract class AbstractTotalsProcessor
  18. {
  19. /**
  20. * Core store config
  21. *
  22. * @var ScopeConfigInterface
  23. */
  24. protected $scopeConfig;
  25. /**
  26. * @param ScopeConfigInterface $scopeConfig
  27. * @codeCoverageIgnore
  28. */
  29. public function __construct(
  30. ScopeConfigInterface $scopeConfig
  31. ) {
  32. $this->scopeConfig = $scopeConfig;
  33. }
  34. /**
  35. * @param array $totals
  36. * @return array
  37. */
  38. public function sortTotals($totals)
  39. {
  40. $configData = $this->scopeConfig->getValue('sales/totals_sort');
  41. foreach ($totals as $code => &$total) {
  42. //convert JS naming style to config naming style
  43. $code = str_replace('-', '_', $code);
  44. if (array_key_exists($code, $configData)) {
  45. $total['sortOrder'] = $configData[$code];
  46. }
  47. }
  48. return $totals;
  49. }
  50. }