Total.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Msrp\Block;
  7. /**
  8. * @api
  9. * @method string getOriginalBlockName()
  10. * @since 100.0.2
  11. */
  12. class Total extends \Magento\Framework\View\Element\Template
  13. {
  14. /**
  15. * @var \Magento\Msrp\Model\Config
  16. */
  17. protected $config;
  18. /**
  19. * @var \Magento\Msrp\Model\Quote\Msrp
  20. */
  21. protected $msrp;
  22. /**
  23. * @param \Magento\Framework\View\Element\Template\Context $context
  24. * @param \Magento\Msrp\Model\Config $config
  25. * @param \Magento\Msrp\Model\Quote\Msrp $msrp
  26. * @param array $data
  27. */
  28. public function __construct(
  29. \Magento\Framework\View\Element\Template\Context $context,
  30. \Magento\Msrp\Model\Config $config,
  31. \Magento\Msrp\Model\Quote\Msrp $msrp,
  32. array $data = []
  33. ) {
  34. parent::__construct($context, $data);
  35. $this->config = $config;
  36. $this->msrp = $msrp;
  37. }
  38. /**
  39. * @return string
  40. */
  41. protected function _toHtml()
  42. {
  43. /** @var \Magento\Checkout\Block\Cart\AbstractCart $originalBlock */
  44. $originalBlock = $this->getLayout()->getBlock($this->getOriginalBlockName());
  45. $quote = $originalBlock->getQuote();
  46. if (!$this->msrp->getCanApplyMsrp($quote->getId()) && $this->config->isEnabled()) {
  47. $quote->collectTotals();
  48. }
  49. if ($this->msrp->getCanApplyMsrp($quote->getId())) {
  50. $originalBlock->setTemplate('');
  51. return parent::_toHtml();
  52. } else {
  53. return '';
  54. }
  55. }
  56. }