Buttons.php 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. /**
  7. * Block of links in Order view page
  8. */
  9. namespace Magento\Sales\Block\Order\Info;
  10. use Magento\Customer\Model\Context;
  11. /**
  12. * @api
  13. * @since 100.0.2
  14. */
  15. class Buttons extends \Magento\Framework\View\Element\Template
  16. {
  17. /**
  18. * @var string
  19. */
  20. protected $_template = 'Magento_Sales::order/info/buttons.phtml';
  21. /**
  22. * Core registry
  23. *
  24. * @var \Magento\Framework\Registry
  25. */
  26. protected $_coreRegistry = null;
  27. /**
  28. * @var \Magento\Framework\App\Http\Context
  29. */
  30. protected $httpContext;
  31. /**
  32. * @param \Magento\Framework\View\Element\Template\Context $context
  33. * @param \Magento\Framework\Registry $registry
  34. * @param \Magento\Framework\App\Http\Context $httpContext
  35. * @param array $data
  36. */
  37. public function __construct(
  38. \Magento\Framework\View\Element\Template\Context $context,
  39. \Magento\Framework\Registry $registry,
  40. \Magento\Framework\App\Http\Context $httpContext,
  41. array $data = []
  42. ) {
  43. $this->_coreRegistry = $registry;
  44. $this->httpContext = $httpContext;
  45. parent::__construct($context, $data);
  46. $this->_isScopePrivate = true;
  47. }
  48. /**
  49. * Retrieve current order model instance
  50. *
  51. * @return \Magento\Sales\Model\Order
  52. */
  53. public function getOrder()
  54. {
  55. return $this->_coreRegistry->registry('current_order');
  56. }
  57. /**
  58. * Get url for printing order
  59. *
  60. * @param \Magento\Sales\Model\Order $order
  61. * @return string
  62. */
  63. public function getPrintUrl($order)
  64. {
  65. if (!$this->httpContext->getValue(Context::CONTEXT_AUTH)) {
  66. return $this->getUrl('sales/guest/print', ['order_id' => $order->getId()]);
  67. }
  68. return $this->getUrl('sales/order/print', ['order_id' => $order->getId()]);
  69. }
  70. /**
  71. * Get url for reorder action
  72. *
  73. * @param \Magento\Sales\Model\Order $order
  74. * @return string
  75. */
  76. public function getReorderUrl($order)
  77. {
  78. if (!$this->httpContext->getValue(Context::CONTEXT_AUTH)) {
  79. return $this->getUrl('sales/guest/reorder', ['order_id' => $order->getId()]);
  80. }
  81. return $this->getUrl('sales/order/reorder', ['order_id' => $order->getId()]);
  82. }
  83. }