Form.php 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. /**
  7. * Sales widget search form for orders and returns block
  8. */
  9. namespace Magento\Sales\Block\Widget\Guest;
  10. use Magento\Customer\Model\Context;
  11. /**
  12. * @api
  13. * @since 100.0.2
  14. */
  15. class Form extends \Magento\Framework\View\Element\Template implements \Magento\Widget\Block\BlockInterface
  16. {
  17. /**
  18. * @var \Magento\Framework\App\Http\Context
  19. */
  20. protected $httpContext;
  21. /**
  22. * @param \Magento\Framework\View\Element\Template\Context $context
  23. * @param \Magento\Framework\App\Http\Context $httpContext
  24. * @param array $data
  25. */
  26. public function __construct(
  27. \Magento\Framework\View\Element\Template\Context $context,
  28. \Magento\Framework\App\Http\Context $httpContext,
  29. array $data = []
  30. ) {
  31. $this->httpContext = $httpContext;
  32. parent::__construct($context, $data);
  33. $this->_isScopePrivate = true;
  34. }
  35. /**
  36. * Check whether module is available
  37. *
  38. * @return bool
  39. */
  40. public function isEnable()
  41. {
  42. return !($this->httpContext->getValue(Context::CONTEXT_AUTH));
  43. }
  44. /**
  45. * Select element for choosing registry type
  46. *
  47. * @return array
  48. */
  49. public function getTypeSelectHtml()
  50. {
  51. $select = $this->getLayout()->createBlock(
  52. \Magento\Framework\View\Element\Html\Select::class
  53. )->setData(
  54. ['id' => 'quick_search_type_id', 'class' => 'select guest-select']
  55. )->setName(
  56. 'oar_type'
  57. )->setOptions(
  58. $this->_getFormOptions()
  59. )->setExtraParams(
  60. 'onchange="showIdentifyBlock(this.value);"'
  61. );
  62. return $select->getHtml();
  63. }
  64. /**
  65. * Get Form Options for Guest
  66. *
  67. * @return array
  68. */
  69. protected function _getFormOptions()
  70. {
  71. $options = $this->getData('identifymeby_options');
  72. if ($options === null) {
  73. $options = [];
  74. $options[] = ['value' => 'email', 'label' => 'Email Address'];
  75. $options[] = ['value' => 'zip', 'label' => 'ZIP Code'];
  76. $this->setData('identifymeby_options', $options);
  77. }
  78. return $options;
  79. }
  80. /**
  81. * Return quick search form action url
  82. *
  83. * @return string
  84. */
  85. public function getActionUrl()
  86. {
  87. return $this->getUrl('sales/guest/view');
  88. }
  89. }