Success.php 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. /**
  7. * Downloadable checkout success page
  8. *
  9. * @author Magento Core Team <core@magentocommerce.com>
  10. */
  11. namespace Magento\Downloadable\Block\Checkout;
  12. use Magento\Framework\View\Element\Template;
  13. /**
  14. * @api
  15. * @since 100.0.2
  16. */
  17. class Success extends \Magento\Checkout\Block\Onepage\Success
  18. {
  19. /**
  20. * @var \Magento\Customer\Helper\Session\CurrentCustomer
  21. */
  22. protected $currentCustomer;
  23. /**
  24. * @param Template\Context $context
  25. * @param \Magento\Checkout\Model\Session $checkoutSession
  26. * @param \Magento\Sales\Model\Order\Config $orderConfig
  27. * @param \Magento\Framework\App\Http\Context $httpContext
  28. * @param \Magento\Customer\Helper\Session\CurrentCustomer $currentCustomer
  29. * @param array $data
  30. */
  31. public function __construct(
  32. \Magento\Framework\View\Element\Template\Context $context,
  33. \Magento\Checkout\Model\Session $checkoutSession,
  34. \Magento\Sales\Model\Order\Config $orderConfig,
  35. \Magento\Framework\App\Http\Context $httpContext,
  36. \Magento\Customer\Helper\Session\CurrentCustomer $currentCustomer,
  37. array $data = []
  38. ) {
  39. parent::__construct(
  40. $context,
  41. $checkoutSession,
  42. $orderConfig,
  43. $httpContext,
  44. $data
  45. );
  46. $this->currentCustomer = $currentCustomer;
  47. }
  48. /**
  49. * Return true if order(s) has one or more downloadable products
  50. *
  51. * @return bool
  52. */
  53. private function orderHasDownloadableProducts()
  54. {
  55. return $this->isVisible($this->_checkoutSession->getLastRealOrder())
  56. && $this->currentCustomer->getCustomerId()
  57. ? $this->_checkoutSession->getHasDownloadableProducts(true)
  58. : false;
  59. }
  60. /**
  61. * Prepares block data
  62. *
  63. * @return void
  64. */
  65. protected function prepareBlockData()
  66. {
  67. parent::prepareBlockData();
  68. $this->addData(
  69. [
  70. 'order_has_downloadable' => $this->orderHasDownloadableProducts()
  71. ]
  72. );
  73. }
  74. /**
  75. * Return url to list of ordered downloadable products of customer
  76. *
  77. * @return string
  78. */
  79. public function getDownloadableProductsUrl()
  80. {
  81. return $this->getUrl('downloadable/customer/products', ['_secure' => true]);
  82. }
  83. }