Agreement.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Paypal\Model\ResourceModel\Billing;
  7. /**
  8. * Billing agreement resource model
  9. */
  10. class Agreement extends \Magento\Framework\Model\ResourceModel\Db\AbstractDb
  11. {
  12. /**
  13. * Resource initialization
  14. *
  15. * @return void
  16. */
  17. protected function _construct()
  18. {
  19. $this->_init('paypal_billing_agreement', 'agreement_id');
  20. }
  21. /**
  22. * Add order relation to billing agreement
  23. *
  24. * @param int $agreementId
  25. * @param int $orderId
  26. * @return $this
  27. */
  28. public function addOrderRelation($agreementId, $orderId)
  29. {
  30. $this->getConnection()->insert(
  31. $this->getTable('paypal_billing_agreement_order'),
  32. ['agreement_id' => $agreementId, 'order_id' => $orderId]
  33. );
  34. return $this;
  35. }
  36. /**
  37. * Add billing agreement filter on orders collection
  38. *
  39. * @param \Magento\Framework\Data\Collection\AbstractDb $orderCollection
  40. * @param string|int|array $agreementIds
  41. * @return $this
  42. */
  43. public function addOrdersFilter(\Magento\Framework\Data\Collection\AbstractDb $orderCollection, $agreementIds)
  44. {
  45. $agreementIds = is_array($agreementIds) ? $agreementIds : [$agreementIds];
  46. $orderIds = $this->getConnection()->fetchCol(
  47. $this->getConnection()->select()
  48. ->from(['pbao' => $this->getTable('paypal_billing_agreement_order')], ['order_id'])
  49. ->where(
  50. 'pbao.agreement_id IN(?)',
  51. $agreementIds
  52. )
  53. );
  54. $orderCollection->getSelect()
  55. ->where('main_table.entity_id IN (?)', $orderIds);
  56. return $this;
  57. }
  58. }