Skip to content

Commit

Permalink
Merge pull request #1163 from buckaroo-it/BP-4168-Cron-job-error-buck…
Browse files Browse the repository at this point in the history
…aroo_magento2_cancel_cron

BP-4168-Cron-job-error-buckaroo_magento2_cancel_cron
  • Loading branch information
vegimcarkaxhija authored Feb 4, 2025
2 parents 6f68cfd + 33ffee3 commit 19aaae5
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions Model/Service/Order.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
* @copyright Copyright (c) Buckaroo B.V.
* @license https://tldrlegal.com/license/mit-license
*/

namespace Buckaroo\Magento2\Model\Service;

use Buckaroo\Magento2\Model\ConfigProvider\Account;
Expand All @@ -29,7 +30,7 @@
use Magento\Sales\Model\ResourceModel\Order\CollectionFactory;
use Buckaroo\Magento2\Helper\Data;
use Magento\Framework\App\ResourceConnection;
use Laminas\Db\Sql\Expression;
use Zend_Db_Expr;

class Order
{
Expand All @@ -53,8 +54,7 @@ public function __construct(
Data $helper,
Log $logging,
ResourceConnection $resourceConnection
)
{
) {
$this->accountConfig = $accountConfig;
$this->configProviderMethodFactory = $configProviderMethodFactory;
$this->configProviderFactory = $configProviderFactory;
Expand Down Expand Up @@ -96,11 +96,11 @@ protected function cancelExpiredTransferOrdersPerStore($store)
)
->addFieldToFilter(
'created_at',
['lt' => new Expression('NOW() - INTERVAL ' . $dueDays . ' DAY')]
['lt' => new Zend_Db_Expr('NOW() - INTERVAL ' . $dueDays . ' DAY')]
)
->addFieldToFilter(
'created_at',
['gt' => new Expression('NOW() - INTERVAL ' . ($dueDays + 7) . ' DAY')]
['gt' => new Zend_Db_Expr('NOW() - INTERVAL ' . ($dueDays + 7) . ' DAY')]
);

$orderCollection->getSelect()
Expand Down Expand Up @@ -156,11 +156,11 @@ protected function cancelExpiredPPEOrdersPerStore($store)
)
->addFieldToFilter(
'created_at',
['lt' => new Expression('NOW() - INTERVAL ' . $dueDays . ' DAY')]
['lt' => new Zend_Db_Expr('NOW() - INTERVAL ' . $dueDays . ' DAY')]
)
->addFieldToFilter(
'created_at',
['gt' => new Expression('NOW() - INTERVAL ' . ($dueDays + 7) . ' DAY')]
['gt' => new Zend_Db_Expr('NOW() - INTERVAL ' . ($dueDays + 7) . ' DAY')]
);

$orderCollection->getSelect()
Expand All @@ -170,7 +170,7 @@ protected function cancelExpiredPPEOrdersPerStore($store)
['method']
)
->where('p.additional_information like "%isPayPerEmail%"'
. ' OR p.method ="buckaroo_magento2_payperemail"');
. ' OR p.method = "buckaroo_magento2_payperemail"');

$this->logging->addDebug(
__METHOD__ . '|PPEOrders query|' . $orderCollection->getSelect()->__toString()
Expand All @@ -195,14 +195,15 @@ public function cancel($order, $statusCode)
{
$this->logging->addDebug(__METHOD__ . '|1|' . var_export($order->getIncrementId(), true));

// Mostly the push api already canceled the order, so first check in wich state the order is.
// Check if the order is already canceled.
if ($order->getState() == \Magento\Sales\Model\Order::STATE_CANCELED) {
$this->logging->addDebug(__METHOD__ . '|5|');
return true;
}

$store = $order->getStore();

// Check if cancel on failed is enabled.
/**
* @noinspection PhpUndefinedMethodInspection
*/
Expand Down

0 comments on commit 19aaae5

Please sign in to comment.