ShipButton.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. declare(strict_types=1);
  7. namespace Magento\InventoryShippingAdminUi\Block\Adminhtml\Order\View;
  8. use Magento\Backend\Block\Widget\Container;
  9. use Magento\Backend\Block\Widget\Context;
  10. use Magento\Framework\Registry;
  11. use Magento\InventoryShippingAdminUi\Model\IsWebsiteInMultiSourceMode;
  12. /**
  13. * Update order_ship button to redirect to Source Selection page
  14. *
  15. * @api
  16. */
  17. class ShipButton extends Container
  18. {
  19. /**
  20. * @var Registry
  21. */
  22. private $registry;
  23. /**
  24. * @var IsWebsiteInMultiSourceMode
  25. */
  26. private $isWebsiteInMultiSourceMode;
  27. /**
  28. * @param Context $context
  29. * @param Registry $registry
  30. * @param IsWebsiteInMultiSourceMode $isWebsiteInMultiSourceMode
  31. * @param array $data
  32. */
  33. public function __construct(
  34. Context $context,
  35. Registry $registry,
  36. IsWebsiteInMultiSourceMode $isWebsiteInMultiSourceMode,
  37. array $data = []
  38. ) {
  39. parent::__construct($context, $data);
  40. $this->registry = $registry;
  41. $this->isWebsiteInMultiSourceMode = $isWebsiteInMultiSourceMode;
  42. }
  43. /**
  44. * @inheritdoc
  45. */
  46. protected function _prepareLayout()
  47. {
  48. parent::_prepareLayout();
  49. $order = $this->registry->registry('current_order');
  50. $websiteId = (int)$order->getStore()->getWebsiteId();
  51. if ($this->isWebsiteInMultiSourceMode->execute($websiteId)) {
  52. $this->buttonList->update(
  53. 'order_ship',
  54. 'onclick',
  55. 'setLocation(\'' . $this->getSourceSelectionUrl() . '\')'
  56. );
  57. }
  58. return $this;
  59. }
  60. /**
  61. * Source Selection URL getter
  62. *
  63. * @return string
  64. */
  65. public function getSourceSelectionUrl()
  66. {
  67. return $this->getUrl(
  68. 'inventoryshipping/SourceSelection/index',
  69. [
  70. 'order_id' => $this->getRequest()->getParam('order_id')
  71. ]
  72. );
  73. }
  74. }