1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Copyright © Getnet. All rights reserved. |
4
|
|
|
* |
5
|
|
|
* @author Bruno Elisei <[email protected]> |
6
|
|
|
* See LICENSE for license details. |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
namespace Getnet\SplitExampleMagento\Cron; |
10
|
|
|
|
11
|
|
|
use Getnet\PaymentMagento\Model\Console\Command\Marketplace\PaymentRelease as ModelPaymentRelease; |
|
|
|
|
12
|
|
|
use Getnet\SplitExampleMagento\Helper\Data; |
13
|
|
|
use Magento\Framework\Api\SearchCriteriaBuilder; |
14
|
|
|
use Magento\Sales\Model\Order\ShipmentRepositoryFactory; |
|
|
|
|
15
|
|
|
use Psr\Log\LoggerInterface; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Class Release By Ship on Getnet. |
19
|
|
|
*/ |
20
|
|
|
class ReleaseByShip |
21
|
|
|
{ |
22
|
|
|
/** |
23
|
|
|
* @var LoggerInterface |
24
|
|
|
*/ |
25
|
|
|
protected $logger; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @var Data |
29
|
|
|
*/ |
30
|
|
|
protected $helper; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @var ShipmentRepositoryFactory |
34
|
|
|
*/ |
35
|
|
|
protected $shipRepository; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @var SearchCriteriaBuilder |
39
|
|
|
*/ |
40
|
|
|
protected $searchCriteriaBuilder; |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* @var ModelPaymentRelease |
44
|
|
|
*/ |
45
|
|
|
protected $modelPaymentRelease; |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* @var \Magento\Framework\Stdlib\DateTime\DateTime |
49
|
|
|
*/ |
50
|
|
|
protected $date; |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* @var \Magento\Framework\Stdlib\DateTime\TimezoneInterface |
54
|
|
|
*/ |
55
|
|
|
protected $timezone; |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* Constructor. |
59
|
|
|
* |
60
|
|
|
* @param LoggerInterface $logger |
61
|
|
|
* @param Data $helper |
62
|
|
|
* @param ModelPaymentRelease $modelPaymentRelease |
63
|
|
|
* @param ShipmentRepositoryFactory $shipRepository |
64
|
|
|
* @param SearchCriteriaBuilder $searchCriteriaBuilder |
65
|
|
|
* @param \Magento\Framework\Stdlib\DateTime\DateTime $date |
66
|
|
|
* @param \Magento\Framework\Stdlib\DateTime\TimezoneInterface $timezone |
67
|
|
|
*/ |
68
|
|
|
public function __construct( |
69
|
|
|
LoggerInterface $logger, |
70
|
|
|
Data $helper, |
71
|
|
|
ModelPaymentRelease $modelPaymentRelease, |
72
|
|
|
ShipmentRepositoryFactory $shipRepository, |
73
|
|
|
SearchCriteriaBuilder $searchCriteriaBuilder, |
74
|
|
|
\Magento\Framework\Stdlib\DateTime\DateTime $date, |
75
|
|
|
\Magento\Framework\Stdlib\DateTime\TimezoneInterface $timezone |
76
|
|
|
) { |
77
|
|
|
$this->logger = $logger; |
78
|
|
|
$this->helper = $helper; |
79
|
|
|
$this->modelPaymentRelease = $modelPaymentRelease; |
80
|
|
|
$this->shipRepository = $shipRepository; |
81
|
|
|
$this->searchCriteriaBuilder = $searchCriteriaBuilder; |
82
|
|
|
$this->date = $date; |
83
|
|
|
$this->timezone = $timezone; |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* Execute the cron. |
88
|
|
|
* |
89
|
|
|
* @return void |
90
|
|
|
*/ |
91
|
|
|
public function execute() |
92
|
|
|
{ |
93
|
|
|
$this->logger->debug('Cronjob Release By Ship'); |
94
|
|
|
|
95
|
|
|
$dateNow = new \DateTime(); |
96
|
|
|
$dateTo = $dateNow->format('Y-m-d 23:59:59'); |
97
|
|
|
$dateFrom = $dateNow->format('Y-m-d 00:00:00'); |
98
|
|
|
|
99
|
|
|
$searchCriteria = $this->searchCriteriaBuilder |
100
|
|
|
->addFilter('created_at', $dateFrom, 'gteq') |
101
|
|
|
->addFilter('created_at', $dateTo, 'lteq') |
102
|
|
|
->create(); |
103
|
|
|
|
104
|
|
|
$ships = $this->shipRepository->create()->getList($searchCriteria); |
105
|
|
|
|
106
|
|
|
$days = $this->helper->getDaysOfRelease(); |
107
|
|
|
$days = $days ? $days : 1; |
108
|
|
|
|
109
|
|
|
$dateNow->add(new \DateInterval('P'.$days.'D')); |
110
|
|
|
$dateToRelease = $dateNow->format('Y-m-d\TH:i:s\Z'); |
111
|
|
|
|
112
|
|
|
foreach ($ships->getItems() as $ship) { |
113
|
|
|
$order = $ship->getOrder(); |
114
|
|
|
$payment = $order->getPayment()->getMethodInstance(); |
115
|
|
|
if ($payment->getCode() === 'getnet_paymentmagento_boleto' |
116
|
|
|
|| $payment->getCode() === 'getnet_paymentmagento_cc' |
117
|
|
|
) { |
118
|
|
|
$orderId = $order->getId(); |
119
|
|
|
$this->logger->debug(sprintf('ship id %s, order id %s', $ship->getId(), $orderId)); |
120
|
|
|
$this->modelPaymentRelease->createPaymentRelease($orderId, $dateToRelease); |
121
|
|
|
} |
122
|
|
|
} |
123
|
|
|
|
124
|
|
|
$this->logger->debug('Cronjob Release By ship is done.'); |
125
|
|
|
} |
126
|
|
|
} |
127
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths