We will be off from 27/1 (Monday) to 31/1 (Friday) (GMT +7) for our Tet Holiday (Lunar New Year) in our country

Commit 8159aba3 authored by Alessio Zampatti's avatar Alessio Zampatti

Check if order-billingagreement relation exists in...

Check if order-billingagreement relation exists in paypal_billing_agreement_order table before adding it
parent e6319d80
...@@ -113,6 +113,11 @@ class Data extends AbstractHelper ...@@ -113,6 +113,11 @@ class Data extends AbstractHelper
*/ */
protected $billingAgreementFactory; protected $billingAgreementFactory;
/**
* @var ResourceModel\Billing\Agreement
*/
private $agreementResourceModel;
/** /**
* Data constructor. * Data constructor.
* @param \Magento\Framework\App\Helper\Context $context * @param \Magento\Framework\App\Helper\Context $context
...@@ -131,6 +136,7 @@ class Data extends AbstractHelper ...@@ -131,6 +136,7 @@ class Data extends AbstractHelper
* @param \Magento\Store\Model\StoreManagerInterface $storeManager * @param \Magento\Store\Model\StoreManagerInterface $storeManager
* @param \Magento\Framework\App\CacheInterface $cache * @param \Magento\Framework\App\CacheInterface $cache
* @param \Adyen\Payment\Model\Billing\AgreementFactory $billingAgreementFactory * @param \Adyen\Payment\Model\Billing\AgreementFactory $billingAgreementFactory
* @param \Adyen\Payment\Model\ResourceModel\Billing\Agreement $agreementResourceModel
*/ */
public function __construct( public function __construct(
\Magento\Framework\App\Helper\Context $context, \Magento\Framework\App\Helper\Context $context,
...@@ -148,7 +154,8 @@ class Data extends AbstractHelper ...@@ -148,7 +154,8 @@ class Data extends AbstractHelper
\Adyen\Payment\Logger\AdyenLogger $adyenLogger, \Adyen\Payment\Logger\AdyenLogger $adyenLogger,
\Magento\Store\Model\StoreManagerInterface $storeManager, \Magento\Store\Model\StoreManagerInterface $storeManager,
\Magento\Framework\App\CacheInterface $cache, \Magento\Framework\App\CacheInterface $cache,
\Adyen\Payment\Model\Billing\AgreementFactory $billingAgreementFactory \Adyen\Payment\Model\Billing\AgreementFactory $billingAgreementFactory,
\Adyen\Payment\Model\ResourceModel\Billing\Agreement $agreementResourceModel
) { ) {
parent::__construct($context); parent::__construct($context);
$this->_encryptor = $encryptor; $this->_encryptor = $encryptor;
...@@ -166,6 +173,7 @@ class Data extends AbstractHelper ...@@ -166,6 +173,7 @@ class Data extends AbstractHelper
$this->storeManager = $storeManager; $this->storeManager = $storeManager;
$this->cache = $cache; $this->cache = $cache;
$this->billingAgreementFactory = $billingAgreementFactory; $this->billingAgreementFactory = $billingAgreementFactory;
$this->agreementResourceModel = $agreementResourceModel;
} }
/** /**
...@@ -1463,8 +1471,12 @@ class Data extends AbstractHelper ...@@ -1463,8 +1471,12 @@ class Data extends AbstractHelper
$billingAgreement->setCcBillingAgreement($additionalData); $billingAgreement->setCcBillingAgreement($additionalData);
if ($billingAgreement->isValid()) { if ($billingAgreement->isValid()) {
if (!$this->agreementResourceModel->getOrderRelation($billingAgreement->getAgreementId(),
$order->getId())) {
// save into sales_billing_agreement_order // save into sales_billing_agreement_order
$billingAgreement->addOrderRelation($order); $billingAgreement->addOrderRelation($order);
}
// add to order to save agreement // add to order to save agreement
$order->addRelatedObject($billingAgreement); $order->addRelatedObject($billingAgreement);
} else { } else {
......
...@@ -209,9 +209,13 @@ class Cron ...@@ -209,9 +209,13 @@ class Cron
*/ */
private $orderRepository; private $orderRepository;
/**
* @var ResourceModel\Billing\Agreement
*/
private $agreementResourceModel;
/** /**
* Cron constructor. * Cron constructor.
*
* @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig * @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
* @param \Adyen\Payment\Logger\AdyenLogger $adyenLogger * @param \Adyen\Payment\Logger\AdyenLogger $adyenLogger
* @param ResourceModel\Notification\CollectionFactory $notificationFactory * @param ResourceModel\Notification\CollectionFactory $notificationFactory
...@@ -230,6 +234,7 @@ class Cron ...@@ -230,6 +234,7 @@ class Cron
* @param \Magento\Sales\Model\ResourceModel\Order\Status\CollectionFactory $orderStatusCollection * @param \Magento\Sales\Model\ResourceModel\Order\Status\CollectionFactory $orderStatusCollection
* @param SearchCriteriaBuilder $searchCriteriaBuilder * @param SearchCriteriaBuilder $searchCriteriaBuilder
* @param OrderRepository $orderRepository * @param OrderRepository $orderRepository
* @param ResourceModel\Billing\Agreement $agreementResourceModel
*/ */
public function __construct( public function __construct(
\Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig, \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig,
...@@ -249,7 +254,8 @@ class Cron ...@@ -249,7 +254,8 @@ class Cron
AreaList $areaList, AreaList $areaList,
\Magento\Sales\Model\ResourceModel\Order\Status\CollectionFactory $orderStatusCollection, \Magento\Sales\Model\ResourceModel\Order\Status\CollectionFactory $orderStatusCollection,
SearchCriteriaBuilder $searchCriteriaBuilder, SearchCriteriaBuilder $searchCriteriaBuilder,
OrderRepository $orderRepository OrderRepository $orderRepository,
\Adyen\Payment\Model\ResourceModel\Billing\Agreement $agreementResourceModel
) { ) {
$this->_scopeConfig = $scopeConfig; $this->_scopeConfig = $scopeConfig;
$this->_adyenLogger = $adyenLogger; $this->_adyenLogger = $adyenLogger;
...@@ -269,6 +275,7 @@ class Cron ...@@ -269,6 +275,7 @@ class Cron
$this->_orderStatusCollection = $orderStatusCollection; $this->_orderStatusCollection = $orderStatusCollection;
$this->searchCriteriaBuilder = $searchCriteriaBuilder; $this->searchCriteriaBuilder = $searchCriteriaBuilder;
$this->orderRepository = $orderRepository; $this->orderRepository = $orderRepository;
$this->agreementResourceModel = $agreementResourceModel;
} }
/** /**
...@@ -1019,8 +1026,13 @@ class Cron ...@@ -1019,8 +1026,13 @@ class Cron
// Populate billing agreement data // Populate billing agreement data
$billingAgreement->parseRecurringContractData($contractDetail); $billingAgreement->parseRecurringContractData($contractDetail);
if ($billingAgreement->isValid()) { if ($billingAgreement->isValid()) {
if (!$this->agreementResourceModel->getOrderRelation($billingAgreement->getAgreementId(),
$this->_order->getId())) {
// save into sales_billing_agreement_order // save into sales_billing_agreement_order
$billingAgreement->addOrderRelation($this->_order); $billingAgreement->addOrderRelation($this->_order);
}
// add to order to save agreement // add to order to save agreement
$this->_order->addRelatedObject($billingAgreement); $this->_order->addRelatedObject($billingAgreement);
......
...@@ -29,4 +29,13 @@ namespace Adyen\Payment\Model\ResourceModel\Billing; ...@@ -29,4 +29,13 @@ namespace Adyen\Payment\Model\ResourceModel\Billing;
class Agreement extends \Magento\Paypal\Model\ResourceModel\Billing\Agreement class Agreement extends \Magento\Paypal\Model\ResourceModel\Billing\Agreement
{ {
public function getOrderRelation($agreementId, $orderId)
{
$select = $this->getConnection()->select()
->from(['billingagreement_order' => $this->getTable('paypal_billing_agreement_order')])
->where('billingagreement_order.agreement_id=?', $agreementId)
->where('billingagreement_order.order_id=?', $orderId);
return $this->getConnection()->fetchAll($select);
}
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment