Sidebar.php 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Sales\Block\Reorder;
  7. use Magento\Customer\Model\Context;
  8. /**
  9. * Last ordered items sidebar
  10. *
  11. * @api
  12. * @since 100.0.2
  13. */
  14. class Sidebar extends \Magento\Framework\View\Element\Template
  15. {
  16. /**
  17. * @var \Magento\Framework\App\Http\Context
  18. */
  19. protected $httpContext;
  20. /**
  21. * @param \Magento\Framework\View\Element\Template\Context $context
  22. * @param \Magento\Framework\App\Http\Context $httpContext
  23. * @param array $data
  24. */
  25. public function __construct(
  26. \Magento\Framework\View\Element\Template\Context $context,
  27. \Magento\Framework\App\Http\Context $httpContext,
  28. array $data = []
  29. ) {
  30. parent::__construct($context, $data);
  31. $this->httpContext = $httpContext;
  32. }
  33. /**
  34. * Retrieve form action url and set "secure" param to avoid confirm
  35. * message when we submit form from secure page to unsecure
  36. *
  37. * @return string
  38. */
  39. public function getFormActionUrl()
  40. {
  41. return $this->getUrl('checkout/cart/addgroup', ['_secure' => true]);
  42. }
  43. /**
  44. * Render "My Orders" sidebar block
  45. *
  46. * @return string
  47. */
  48. protected function _toHtml()
  49. {
  50. $isValid = $this->httpContext->getValue(Context::CONTEXT_AUTH) || $this->getCustomerId();
  51. return $isValid ? parent::_toHtml() : '';
  52. }
  53. }