Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
AbstractAgreement.php
Go to the documentation of this file.
1 <?php
7 
10 
19 {
23  const TRANSPORT_BILLING_AGREEMENT_ID = 'ba_agreement_id';
24 
25  const PAYMENT_INFO_REFERENCE_ID = 'ba_reference_id';
26 
30  protected $_infoBlockType = \Magento\Paypal\Block\Payment\Info\Billing\Agreement::class;
31 
35  protected $_formBlockType = \Magento\Paypal\Block\Payment\Form\Billing\Agreement::class;
36 
42  protected $_isAvailable = null;
43 
47  protected $_agreementFactory;
48 
63  public function __construct(
64  \Magento\Framework\Model\Context $context,
65  \Magento\Framework\Registry $registry,
66  \Magento\Framework\Api\ExtensionAttributesFactory $extensionFactory,
67  \Magento\Framework\Api\AttributeValueFactory $customAttributeFactory,
68  \Magento\Payment\Helper\Data $paymentData,
69  \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig,
70  \Magento\Payment\Model\Method\Logger $logger,
71  \Magento\Paypal\Model\Billing\AgreementFactory $agreementFactory,
72  \Magento\Framework\Model\ResourceModel\AbstractResource $resource = null,
73  \Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null,
74  array $data = []
75  ) {
76  $this->_agreementFactory = $agreementFactory;
77  parent::__construct(
78  $context,
79  $registry,
80  $extensionFactory,
83  $scopeConfig,
84  $logger,
85  $resource,
86  $resourceCollection,
87  $data
88  );
89  }
90 
97  public function isAvailable(\Magento\Quote\Api\Data\CartInterface $quote = null)
98  {
99  if ($this->_isAvailable === null) {
100  $this->_isAvailable = parent::isAvailable($quote) && $this->_isAvailable($quote);
101  $this->_canUseCheckout = $this->_isAvailable && $this->_canUseCheckout;
102  $this->_canUseInternal = $this->_isAvailable && $this->_canUseInternal;
103  }
104  return $this->_isAvailable;
105  }
106 
114  public function assignData(\Magento\Framework\DataObject $data)
115  {
116  parent::assignData($data);
117 
118  $additionalData = $data->getData(PaymentInterface::KEY_ADDITIONAL_DATA);
119 
120  if (!is_array($additionalData) || !isset($additionalData[self::TRANSPORT_BILLING_AGREEMENT_ID])) {
121  return $this;
122  }
123 
124  $id = $additionalData[self::TRANSPORT_BILLING_AGREEMENT_ID];
125  if (!$id || !is_numeric($id)) {
126  return $this;
127  }
128 
129  $info = $this->getInfoInstance();
131  $ba = $this->_agreementFactory->create();
132  $ba->load($id);
133 
134  if ($ba->getId() && $ba->getCustomerId() == $info->getQuote()->getCustomerId()) {
135  $info->setAdditionalInformation(self::TRANSPORT_BILLING_AGREEMENT_ID, $id);
136  $info->setAdditionalInformation(self::PAYMENT_INFO_REFERENCE_ID, $ba->getReferenceId());
137  }
138 
139  return $this;
140  }
141 
146  abstract protected function _isAvailable($quote);
147 }
$id
Definition: fieldset.phtml:14
$quote
$resource
Definition: bulk.php:12
__construct(\Magento\Framework\Model\Context $context, \Magento\Framework\Registry $registry, \Magento\Framework\Api\ExtensionAttributesFactory $extensionFactory, \Magento\Framework\Api\AttributeValueFactory $customAttributeFactory, \Magento\Payment\Helper\Data $paymentData, \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig, \Magento\Payment\Model\Method\Logger $logger, \Magento\Paypal\Model\Billing\AgreementFactory $agreementFactory, \Magento\Framework\Model\ResourceModel\AbstractResource $resource=null, \Magento\Framework\Data\Collection\AbstractDb $resourceCollection=null, array $data=[])
isAvailable(\Magento\Quote\Api\Data\CartInterface $quote=null)
assignData(\Magento\Framework\DataObject $data)
foreach( $_productCollection as $_product)() ?>" class $info
Definition: listing.phtml:52