Bar.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Backend\Block\Dashboard;
  7. /**
  8. * Adminhtml dashboard bar block
  9. *
  10. * @author Magento Core Team <core@magentocommerce.com>
  11. */
  12. class Bar extends \Magento\Backend\Block\Dashboard\AbstractDashboard
  13. {
  14. /**
  15. * @var array
  16. */
  17. protected $_totals = [];
  18. /**
  19. * @var \Magento\Directory\Model\Currency|null
  20. */
  21. protected $_currentCurrencyCode = null;
  22. /**
  23. * @return array
  24. */
  25. public function getTotals()
  26. {
  27. return $this->_totals;
  28. }
  29. /**
  30. * @param string $label
  31. * @param float $value
  32. * @param bool $isQuantity
  33. * @return $this
  34. */
  35. public function addTotal($label, $value, $isQuantity = false)
  36. {
  37. if (!$isQuantity) {
  38. $value = $this->format($value);
  39. }
  40. $decimals = '';
  41. $this->_totals[] = ['label' => $label, 'value' => $value, 'decimals' => $decimals];
  42. return $this;
  43. }
  44. /**
  45. * Formatting value specific for this store
  46. *
  47. * @param float $price
  48. * @return string
  49. */
  50. public function format($price)
  51. {
  52. return $this->getCurrency()->format($price);
  53. }
  54. /**
  55. * Setting currency model
  56. *
  57. * @param \Magento\Directory\Model\Currency $currency
  58. * @return void
  59. */
  60. public function setCurrency($currency)
  61. {
  62. $this->_currency = $currency;
  63. }
  64. /**
  65. * Retrieve currency model if not set then return currency model for current store
  66. *
  67. * @return \Magento\Directory\Model\Currency
  68. */
  69. public function getCurrency()
  70. {
  71. if ($this->_currentCurrencyCode === null) {
  72. if ($this->getRequest()->getParam('store')) {
  73. $this->_currentCurrencyCode = $this->_storeManager->getStore(
  74. $this->getRequest()->getParam('store')
  75. )->getBaseCurrency();
  76. } elseif ($this->getRequest()->getParam('website')) {
  77. $this->_currentCurrencyCode = $this->_storeManager->getWebsite(
  78. $this->getRequest()->getParam('website')
  79. )->getBaseCurrency();
  80. } elseif ($this->getRequest()->getParam('group')) {
  81. $this->_currentCurrencyCode = $this->_storeManager->getGroup(
  82. $this->getRequest()->getParam('group')
  83. )->getWebsite()->getBaseCurrency();
  84. } else {
  85. $this->_currentCurrencyCode = $this->_storeManager->getStore()->getBaseCurrency();
  86. }
  87. }
  88. return $this->_currentCurrencyCode;
  89. }
  90. }