1
1
<?php
2
+
2
3
/**
3
4
* Copyright © MercadoPago. All rights reserved.
4
5
*
8
9
9
10
namespace MercadoPago \AdbPayment \Cron ;
10
11
12
+ use Magento \Framework \App \ResourceConnection ;
11
13
use Magento \Payment \Model \Method \Logger ;
12
14
use Magento \Sales \Model \Order ;
13
15
use Magento \Sales \Model \ResourceModel \Order \CollectionFactory ;
@@ -39,24 +41,42 @@ class CancelCheckoutPro
39
41
*/
40
42
protected $ collectionFactory ;
41
43
44
+ /**
45
+ * @var ResourceConnection
46
+ */
47
+ protected $ resource ;
48
+
42
49
/**
43
50
* Constructor.
44
51
*
45
52
* @param Logger $logger
46
53
* @param FetchStatus $fetchStatus
47
54
* @param ConfigCheckoutPro $configCheckoutPro
48
55
* @param CollectionFactory $collectionFactory
56
+ * @param ResourceConnection $resource;
49
57
*/
50
58
public function __construct (
51
59
Logger $ logger ,
52
60
FetchStatus $ fetchStatus ,
53
61
ConfigCheckoutPro $ configCheckoutPro ,
54
- CollectionFactory $ collectionFactory
62
+ CollectionFactory $ collectionFactory ,
63
+ ResourceConnection $ resource
55
64
) {
56
65
$ this ->logger = $ logger ;
57
66
$ this ->fetchStatus = $ fetchStatus ;
58
67
$ this ->configCheckoutPro = $ configCheckoutPro ;
59
68
$ this ->collectionFactory = $ collectionFactory ;
69
+ $ this ->resource = $ resource ;
70
+ }
71
+
72
+ /**
73
+ * Get sales_order_payment table name.
74
+ *
75
+ * @return string
76
+ */
77
+ public function getSalesOrderPaymentTableName ()
78
+ {
79
+ return $ this ->resource ->getTableName ('sales_order_payment ' );
60
80
}
61
81
62
82
/**
@@ -66,21 +86,18 @@ public function __construct(
66
86
*/
67
87
public function execute ()
68
88
{
69
- $ expiration = $ this ->configCheckoutPro ->getExpiredPaymentDate ();
70
-
71
89
$ orders = $ this ->collectionFactory ->create ()
72
- ->addFieldToFilter ('state ' , Order::STATE_NEW )
73
- ->addAttributeToFilter ('created_at ' , [
74
- 'lteq ' => $ expiration ,
75
- ]);
90
+ ->addFieldToFilter ('state ' , Order::STATE_NEW );
76
91
77
92
$ orders ->getSelect ()
78
- ->join (
79
- ['sop ' => 'sales_order_payment ' ],
80
- 'main_table.entity_id = sop.parent_id ' ,
81
- ['method ' ]
82
- )
83
- ->where ('sop.method = ? ' , ConfigCheckoutPro::METHOD );
93
+ ->join (
94
+ ['sop ' => $ this ->getSalesOrderPaymentTableName ()],
95
+ 'main_table.entity_id = sop.parent_id ' ,
96
+ ['method ' ]
97
+ )
98
+ ->where (new \Zend_Db_Expr (
99
+ "sop.method = ? AND TIME_TO_SEC(TIMEDIFF(CURRENT_TIMESTAMP, CAST(JSON_EXTRACT(sop.additional_information, '$.date_of_expiration') AS DATETIME))) >= 0 "
100
+ ), ConfigCheckoutPro::METHOD );
84
101
85
102
foreach ($ orders as $ order ) {
86
103
$ orderId = $ order ->getEntityId ();
@@ -100,7 +117,7 @@ public function execute()
100
117
$ order ->cancel ();
101
118
$ order ->save ();
102
119
$ this ->logger ->debug ([
103
- 'fetch ' => 'Cancel Order Id ' . $ orderId ,
120
+ 'fetch ' => 'Cancel Order Id ' . $ orderId ,
104
121
]);
105
122
}
106
123
}
0 commit comments