forked from m2epro/magento2-extension
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathInvoice.php
64 lines (52 loc) · 1.96 KB
/
Invoice.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<?php
/*
* @author M2E Pro Developers Team
* @copyright M2E LTD
* @license Commercial use is forbidden
*/
namespace Ess\M2ePro\Observer;
class Invoice extends AbstractModel
{
protected $ebayFactory;
protected $messageManager;
protected $urlBuilder;
//########################################
public function __construct(
\Ess\M2ePro\Model\ActiveRecord\Component\Parent\Ebay\Factory $ebayFactory,
\Magento\Framework\Message\Manager $messageManager,
\Magento\Framework\UrlInterface $urlBuilder,
\Ess\M2ePro\Helper\Factory $helperFactory,
\Ess\M2ePro\Model\ActiveRecord\Factory $activeRecordFactory,
\Ess\M2ePro\Model\Factory $modelFactory
)
{
$this->ebayFactory = $ebayFactory;
$this->messageManager = $messageManager;
$this->urlBuilder = $urlBuilder;
parent::__construct($helperFactory, $activeRecordFactory, $modelFactory);
}
//########################################
public function process()
{
if ($this->getHelper('Data\GlobalData')->getValue('skip_invoice_observer')) {
// Not process invoice observer when set such flag
$this->getHelper('Data\GlobalData')->unsetValue('skip_invoice_observer');
return;
}
/** @var $invoice \Magento\Sales\Model\Order\Invoice */
$invoice = $this->getEvent()->getInvoice();
$magentoOrderId = $invoice->getOrderId();
try {
/** @var $order \Ess\M2ePro\Model\Order */
$order = $this->ebayFactory->getObjectLoaded('Order', $magentoOrderId, 'magento_order_id');
} catch (\Exception $e) {
return;
}
if (!$order->getChildObject()->canUpdatePaymentStatus()) {
return;
}
$order->getLog()->setInitiator(\Ess\M2ePro\Helper\Data::INITIATOR_EXTENSION);
$order->getChildObject()->updatePaymentStatus();
}
//########################################
}