Totals.php 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Sales\Block\Adminhtml\Order\Create;
  7. use Magento\Framework\Pricing\PriceCurrencyInterface;
  8. /**
  9. * Adminhtml sales order create totals block
  10. *
  11. * @api
  12. * @author Magento Core Team <core@magentocommerce.com>
  13. * @since 100.0.2
  14. */
  15. class Totals extends \Magento\Sales\Block\Adminhtml\Order\Create\AbstractCreate
  16. {
  17. /**
  18. * Total renderers
  19. *
  20. * @var array
  21. */
  22. protected $_totalRenderers;
  23. /**
  24. * Default renderer
  25. *
  26. * @var string
  27. */
  28. protected $_defaultRenderer = \Magento\Sales\Block\Adminhtml\Order\Create\Totals\DefaultTotals::class;
  29. /**
  30. * Sales data
  31. *
  32. * @var \Magento\Sales\Helper\Data
  33. */
  34. protected $_salesData = null;
  35. /**
  36. * Sales config
  37. *
  38. * @var \Magento\Sales\Model\Config
  39. */
  40. protected $_salesConfig;
  41. /**
  42. * @param \Magento\Backend\Block\Template\Context $context
  43. * @param \Magento\Backend\Model\Session\Quote $sessionQuote
  44. * @param \Magento\Sales\Model\AdminOrder\Create $orderCreate
  45. * @param PriceCurrencyInterface $priceCurrency
  46. * @param \Magento\Sales\Helper\Data $salesData
  47. * @param \Magento\Sales\Model\Config $salesConfig
  48. * @param array $data
  49. */
  50. public function __construct(
  51. \Magento\Backend\Block\Template\Context $context,
  52. \Magento\Backend\Model\Session\Quote $sessionQuote,
  53. \Magento\Sales\Model\AdminOrder\Create $orderCreate,
  54. PriceCurrencyInterface $priceCurrency,
  55. \Magento\Sales\Helper\Data $salesData,
  56. \Magento\Sales\Model\Config $salesConfig,
  57. array $data = []
  58. ) {
  59. $this->_salesData = $salesData;
  60. $this->_salesConfig = $salesConfig;
  61. parent::__construct($context, $sessionQuote, $orderCreate, $priceCurrency, $data);
  62. }
  63. /**
  64. * Constructor
  65. *
  66. * @return void
  67. */
  68. protected function _construct()
  69. {
  70. parent::_construct();
  71. $this->setId('sales_order_create_totals');
  72. }
  73. /**
  74. * Get totals
  75. *
  76. * @return array
  77. */
  78. public function getTotals()
  79. {
  80. $this->getQuote()->collectTotals();
  81. if ($this->getQuote()->isVirtual()) {
  82. $totals = $this->getQuote()->getBillingAddress()->getTotals();
  83. } else {
  84. $totals = $this->getQuote()->getShippingAddress()->getTotals();
  85. }
  86. return $totals;
  87. }
  88. /**
  89. * Get header text
  90. *
  91. * @return \Magento\Framework\Phrase
  92. */
  93. public function getHeaderText()
  94. {
  95. return __('Order Totals');
  96. }
  97. /**
  98. * Get header css class
  99. *
  100. * @return string
  101. */
  102. public function getHeaderCssClass()
  103. {
  104. return 'head-money';
  105. }
  106. /**
  107. * Get total renderer
  108. *
  109. * @param string $code
  110. * @return bool|\Magento\Framework\View\Element\BlockInterface
  111. */
  112. protected function _getTotalRenderer($code)
  113. {
  114. $blockName = $code . '_total_renderer';
  115. $block = $this->getLayout()->getBlock($blockName);
  116. if (!$block) {
  117. $configRenderer = $this->_salesConfig->getTotalsRenderer('quote', 'totals', $code);
  118. if (empty($configRenderer)) {
  119. $block = $this->_defaultRenderer;
  120. } else {
  121. $block = $configRenderer;
  122. }
  123. $block = $this->getLayout()->createBlock($block, $blockName);
  124. }
  125. /**
  126. * Transfer totals to renderer
  127. */
  128. $block->setTotals($this->getTotals());
  129. return $block;
  130. }
  131. /**
  132. * Render total
  133. *
  134. * @param \Magento\Framework\DataObject $total
  135. * @param string|null $area
  136. * @param int $colspan
  137. * @return mixed
  138. */
  139. public function renderTotal($total, $area = null, $colspan = 1)
  140. {
  141. return $this->_getTotalRenderer(
  142. $total->getCode()
  143. )->setTotal(
  144. $total
  145. )->setColspan(
  146. $colspan
  147. )->setRenderingArea(
  148. $area === null ? -1 : $area
  149. )->toHtml();
  150. }
  151. /**
  152. * Render totals
  153. *
  154. * @param null $area
  155. * @param int $colspan
  156. * @return string
  157. */
  158. public function renderTotals($area = null, $colspan = 1)
  159. {
  160. $html = '';
  161. foreach ($this->getTotals() as $total) {
  162. if ($total->getArea() != $area && $area != -1) {
  163. continue;
  164. }
  165. $html .= $this->renderTotal($total, $area, $colspan);
  166. }
  167. return $html;
  168. }
  169. /**
  170. * Check allow to send new order confirmation email
  171. *
  172. * @return bool
  173. */
  174. public function canSendNewOrderConfirmationEmail()
  175. {
  176. return $this->_salesData->canSendNewOrderConfirmationEmail($this->getQuote()->getStoreId());
  177. }
  178. /**
  179. * Get note notification
  180. *
  181. * @return bool
  182. * @SuppressWarnings(PHPMD.BooleanGetMethodName)
  183. */
  184. public function getNoteNotify()
  185. {
  186. $notify = $this->getQuote()->getCustomerNoteNotify();
  187. if ($notify === null || $notify) {
  188. return true;
  189. }
  190. return false;
  191. }
  192. }