Skip to content

Commit

Permalink
Refactor payment method filter in Matcher service
Browse files Browse the repository at this point in the history
No need to access the underlying Select object
  • Loading branch information
ImanuelBertrand committed Jul 30, 2023
1 parent ee614db commit 74d2a4e
Showing 1 changed file with 5 additions and 11 deletions.
16 changes: 5 additions & 11 deletions Service/Matcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
use Magento\Sales\Model\ResourceModel\Order\Creditmemo\CollectionFactory as CreditmemoCollectionFactory;
use Magento\Sales\Model\ResourceModel\Order\Invoice\Collection as InvoiceCollection;
use Magento\Sales\Model\ResourceModel\Order\Invoice\CollectionFactory as InvoiceCollectionFactory;
use Magento\Sales\Model\ResourceModel\Order\Payment;
use Ibertrand\BankSync\Logger\Logger;

class Matcher
Expand All @@ -37,7 +36,6 @@ class Matcher
protected MatchConfidenceFactory $matchConfidenceFactory;
protected MatchConfidenceRepository $matchConfidenceRepository;
protected MatchConfidenceCollectionFactory $matchConfidenceCollectionFactory;
protected Payment $paymentResource;
/**
* @var callable
*/
Expand All @@ -58,7 +56,6 @@ public function __construct(
MatchConfidenceCollectionFactory $matchConfidenceCollectionFactory,
CustomerCollectionFactory $customerCollectionFactory,
OrderCollectionFactory $orderCollectionFactory,
Payment $paymentResource,
Config $config,
Matching $matching,
) {
Expand All @@ -72,7 +69,6 @@ public function __construct(
$this->matchConfidenceCollectionFactory = $matchConfidenceCollectionFactory;
$this->customerCollectionFactory = $customerCollectionFactory;
$this->orderCollectionFactory = $orderCollectionFactory;
$this->paymentResource = $paymentResource;
$this->config = $config;
$this->matching = $matching;
}
Expand Down Expand Up @@ -123,13 +119,11 @@ protected function getBaseDocumentCollection(TempTransaction $tempTransaction):

$paymentMethods = $this->config->getPaymentMethods();
if (!empty($paymentMethods)) {
$collection->getSelect()->joinLeft(
['p' => $this->paymentResource->getMainTable()],
'main_table.order_id = p.parent_id',
''
);
$where = $collection->getConnection()->quoteInto('p.method in (?)', $paymentMethods);
$collection->getSelect()->where($where);
$collection->join(
['payment' => 'sales_order_payment'],
'main_table.order_id = payment.parent_id',
[]
)->addFieldToFilter('payment.method', ['in' => $paymentMethods]);
}

return $collection;
Expand Down

0 comments on commit 74d2a4e

Please sign in to comment.