OrderButton.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Customer\Block\Adminhtml\Edit;
  7. use Magento\Framework\View\Element\UiComponent\Control\ButtonProviderInterface;
  8. /**
  9. * Class OrderButton
  10. */
  11. class OrderButton extends GenericButton implements ButtonProviderInterface
  12. {
  13. /**
  14. * @var \Magento\Framework\AuthorizationInterface
  15. */
  16. protected $authorization;
  17. /**
  18. * Constructor
  19. *
  20. * @param \Magento\Backend\Block\Widget\Context $context
  21. * @param \Magento\Framework\Registry $registry
  22. */
  23. public function __construct(
  24. \Magento\Backend\Block\Widget\Context $context,
  25. \Magento\Framework\Registry $registry
  26. ) {
  27. $this->authorization = $context->getAuthorization();
  28. parent::__construct($context, $registry);
  29. }
  30. /**
  31. * @return array
  32. */
  33. public function getButtonData()
  34. {
  35. $customerId = $this->getCustomerId();
  36. $data = [];
  37. if ($customerId && $this->authorization->isAllowed('Magento_Sales::create')) {
  38. $data = [
  39. 'label' => __('Create Order'),
  40. 'on_click' => sprintf("location.href = '%s';", $this->getCreateOrderUrl()),
  41. 'class' => 'add',
  42. 'sort_order' => 40,
  43. ];
  44. }
  45. return $data;
  46. }
  47. /**
  48. * Retrieve the Url for creating an order.
  49. *
  50. * @return string
  51. */
  52. public function getCreateOrderUrl()
  53. {
  54. return $this->getUrl('sales/order_create/start', ['customer_id' => $this->getCustomerId()]);
  55. }
  56. }