Agreement.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Paypal\Block\Adminhtml\Customer\Edit\Tab;
  7. use Magento\Customer\Controller\RegistryConstants;
  8. use Magento\Ui\Component\Layout\Tabs\TabInterface;
  9. /**
  10. * Adminhtml customer billing agreement tab
  11. *
  12. * @api
  13. * @SuppressWarnings(PHPMD.DepthOfInheritance)
  14. * @since 100.0.2
  15. */
  16. class Agreement extends \Magento\Paypal\Block\Adminhtml\Billing\Agreement\Grid implements TabInterface
  17. {
  18. /**
  19. * Columns, that should be removed from grid
  20. *
  21. * @var array
  22. */
  23. protected $_columnsToRemove = ['customer_email', 'customer_firstname', 'customer_lastname'];
  24. /**
  25. * Core registry
  26. *
  27. * @var \Magento\Framework\Registry
  28. */
  29. protected $_coreRegistry = null;
  30. /**
  31. * @param \Magento\Backend\Block\Template\Context $context
  32. * @param \Magento\Backend\Helper\Data $backendHelper
  33. * @param \Magento\Paypal\Helper\Data $helper
  34. * @param \Magento\Paypal\Model\ResourceModel\Billing\Agreement\CollectionFactory $agreementFactory
  35. * @param \Magento\Paypal\Model\Billing\Agreement $agreementModel
  36. * @param \Magento\Framework\Registry $coreRegistry
  37. * @param array $data
  38. */
  39. public function __construct(
  40. \Magento\Backend\Block\Template\Context $context,
  41. \Magento\Backend\Helper\Data $backendHelper,
  42. \Magento\Paypal\Helper\Data $helper,
  43. \Magento\Paypal\Model\ResourceModel\Billing\Agreement\CollectionFactory $agreementFactory,
  44. \Magento\Paypal\Model\Billing\Agreement $agreementModel,
  45. \Magento\Framework\Registry $coreRegistry,
  46. array $data = []
  47. ) {
  48. $this->_coreRegistry = $coreRegistry;
  49. parent::__construct($context, $backendHelper, $helper, $agreementFactory, $agreementModel, $data);
  50. }
  51. /**
  52. * Disable filters and paging
  53. *
  54. * @return void
  55. */
  56. protected function _construct()
  57. {
  58. parent::_construct();
  59. $this->setId('customer_edit_tab_agreements');
  60. }
  61. /**
  62. * {@inheritdoc}
  63. */
  64. public function getTabLabel()
  65. {
  66. return __('Billing Agreements');
  67. }
  68. /**
  69. * {@inheritdoc}
  70. */
  71. public function getTabTitle()
  72. {
  73. return __('Billing Agreements');
  74. }
  75. /**
  76. * {@inheritdoc}
  77. */
  78. public function canShowTab()
  79. {
  80. return $this->_coreRegistry->registry(RegistryConstants::CURRENT_CUSTOMER_ID) !== null;
  81. }
  82. /**
  83. * {@inheritdoc}
  84. */
  85. public function isHidden()
  86. {
  87. return false;
  88. }
  89. /**
  90. * Get grid url
  91. *
  92. * @return string
  93. */
  94. public function getGridUrl()
  95. {
  96. return $this->getUrl('paypal/billing_agreement/customerGrid', ['_current' => true]);
  97. }
  98. /**
  99. * Tab class getter
  100. *
  101. * @return string
  102. */
  103. public function getTabClass()
  104. {
  105. return '';
  106. }
  107. /**
  108. * Return URL link to Tab content
  109. *
  110. * @return string
  111. */
  112. public function getTabUrl()
  113. {
  114. return '';
  115. }
  116. /**
  117. * Tab should be loaded trough Ajax call
  118. *
  119. * @return bool
  120. */
  121. public function isAjaxLoaded()
  122. {
  123. return false;
  124. }
  125. /**
  126. * Defines after which tab, this tab should be rendered
  127. *
  128. * @return string
  129. */
  130. public function getAfter()
  131. {
  132. return 'orders';
  133. }
  134. /**
  135. * Prepare collection for grid
  136. *
  137. * @return $this
  138. */
  139. protected function _prepareCollection()
  140. {
  141. $customerId = $this->_coreRegistry->registry(RegistryConstants::CURRENT_CUSTOMER_ID);
  142. $collection = $this->_agreementFactory->create()->addFieldToFilter(
  143. 'customer_id',
  144. $customerId
  145. )->setOrder(
  146. 'created_at'
  147. );
  148. $this->setCollection($collection);
  149. return \Magento\Backend\Block\Widget\Grid::_prepareCollection();
  150. }
  151. /**
  152. * Remove some columns and make other not sortable
  153. *
  154. * @return \Magento\Backend\Block\Widget\Grid\Extended
  155. * @SuppressWarnings(PHPMD.UnusedLocalVariable)
  156. */
  157. protected function _prepareColumns()
  158. {
  159. $result = parent::_prepareColumns();
  160. foreach ($this->getColumns() as $key => $value) {
  161. if (in_array($key, $this->_columnsToRemove)) {
  162. $this->removeColumn($key);
  163. }
  164. }
  165. return $result;
  166. }
  167. }