Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Agreements.php
Go to the documentation of this file.
1 <?php
7 
15 {
21  protected $_paymentMethods = [];
22 
28  protected $_billingAgreements = null;
29 
33  protected $_customerSession;
34 
39 
43  protected $_helper;
44 
52  public function __construct(
53  \Magento\Framework\View\Element\Template\Context $context,
54  \Magento\Customer\Model\Session $customerSession,
55  \Magento\Paypal\Model\ResourceModel\Billing\Agreement\CollectionFactory $agreementCollection,
56  \Magento\Paypal\Helper\Data $helper,
57  array $data = []
58  ) {
59  $this->_helper = $helper;
60  $this->_customerSession = $customerSession;
61  $this->_agreementCollection = $agreementCollection;
62  parent::__construct($context, $data);
63  $this->_isScopePrivate = true;
64  }
65 
71  protected function _prepareLayout()
72  {
73  parent::_prepareLayout();
74  $pager = $this->getLayout()->createBlock(
75  \Magento\Theme\Block\Html\Pager::class
76  )->setCollection(
77  $this->getBillingAgreements()
78  )->setIsOutputRequired(
79  false
80  );
81  $this->setChild('pager', $pager)->setBackUrl($this->getUrl('customer/account/'));
82  $this->getBillingAgreements()->load();
83  return $this;
84  }
85 
91  public function getBillingAgreements()
92  {
93  if ($this->_billingAgreements === null) {
94  $this->_billingAgreements = $this->_agreementCollection->create()->addFieldToFilter(
95  'customer_id',
96  $this->_customerSession->getCustomerId()
97  )->setOrder(
98  'agreement_id',
99  'desc'
100  );
101  }
103  }
104 
112  public function getItemValue(\Magento\Paypal\Model\Billing\Agreement $item, $key)
113  {
114  switch ($key) {
115  case 'created_at':
116  case 'updated_at':
117  $value = $item->getData($key)
118  ? $this->formatDate($item->getData($key), \IntlDateFormatter::SHORT, true)
119  : __('N/A');
120  break;
121  case 'edit_url':
122  $value = $this->getUrl('paypal/billing_agreement/view', ['agreement' => $item->getAgreementId()]);
123  break;
124  case 'payment_method_label':
125  $label = $item->getAgreementLabel();
126  $value = $label ? $label : __('N/A');
127  break;
128  case 'status':
129  $value = $item->getStatusLabel();
130  break;
131  default:
132  $value = $item->getData($key) ? $item->getData($key) : __('N/A');
133  break;
134  }
135  return $this->escapeHtml($value);
136  }
137 
143  protected function _loadPaymentMethods()
144  {
145  if (!$this->_paymentMethods) {
146  foreach ($this->_helper->getBillingAgreementMethods() as $paymentMethod) {
147  $this->_paymentMethods[$paymentMethod->getCode()] = $paymentMethod->getTitle();
148  }
149  }
150  return $this->_paymentMethods;
151  }
152 
159  {
160  $paymentMethodOptions = [];
161  foreach ($this->_helper->getBillingAgreementMethods() as $paymentMethod) {
162  if ($paymentMethod->getConfigData('allow_billing_agreement_wizard') == 1) {
163  $paymentMethodOptions[$paymentMethod->getCode()] = $paymentMethod->getTitle();
164  }
165  }
166  return $paymentMethodOptions;
167  }
168 
174  protected function _toHtml()
175  {
176  $this->setCreateUrl($this->getUrl('paypal/billing_agreement/startWizard'));
177  return parent::_toHtml();
178  }
179 }
__construct(\Magento\Framework\View\Element\Template\Context $context, \Magento\Customer\Model\Session $customerSession, \Magento\Paypal\Model\ResourceModel\Billing\Agreement\CollectionFactory $agreementCollection, \Magento\Paypal\Helper\Data $helper, array $data=[])
Definition: Agreements.php:52
$helper
Definition: iframe.phtml:13
formatDate( $date=null, $format=\IntlDateFormatter::SHORT, $showTime=false, $timezone=null)
__()
Definition: __.php:13
getItemValue(\Magento\Paypal\Model\Billing\Agreement $item, $key)
Definition: Agreements.php:112
$label
Definition: details.phtml:21
$value
Definition: gender.phtml:16