1
|
|
|
<?php |
2
|
|
|
declare(strict_types=1); |
3
|
|
|
/** |
4
|
|
|
*/ |
5
|
|
|
|
6
|
|
|
namespace CommerceLeague\ActiveCampaign\MessageQueue\Quote; |
7
|
|
|
|
8
|
|
|
use CommerceLeague\ActiveCampaign\Api\AbandonedRepositoryInterface; |
9
|
|
|
use CommerceLeague\ActiveCampaign\Gateway\Client; |
10
|
|
|
use CommerceLeague\ActiveCampaign\Logger\Logger; |
11
|
|
|
use CommerceLeague\ActiveCampaign\MessageQueue\ConsumerInterface; |
12
|
|
|
use CommerceLeague\ActiveCampaign\Gateway\Request\AbandonedCartBuilder; |
13
|
|
|
use CommerceLeague\ActiveCampaignApi\Exception\HttpException; |
14
|
|
|
use Magento\Framework\Exception\CouldNotSaveException; |
15
|
|
|
use Magento\Framework\Exception\NoSuchEntityException; |
16
|
|
|
use Magento\Quote\Model\Quote; |
17
|
|
|
use Magento\Quote\Model\QuoteFactory; |
|
|
|
|
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* Class ExportAbandonedCartConsumer |
21
|
|
|
*/ |
22
|
|
|
class ExportAbandonedCartConsumer implements ConsumerInterface |
23
|
|
|
{ |
24
|
|
|
/** |
25
|
|
|
* @var AbandonedRepositoryInterface |
26
|
|
|
*/ |
27
|
|
|
private $abandonedRepository; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @var Logger |
31
|
|
|
*/ |
32
|
|
|
private $logger; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @var QuoteFactory |
36
|
|
|
*/ |
37
|
|
|
private $quoteFactory; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @var AbandonedCartBuilder |
41
|
|
|
*/ |
42
|
|
|
private $abandonedCartRequestBuilder; |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @var Client |
46
|
|
|
*/ |
47
|
|
|
private $client; |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* @param AbandonedRepositoryInterface $abandonedRepository |
51
|
|
|
* @param Logger $logger |
52
|
|
|
* @param QuoteFactory $quoteFactory |
53
|
|
|
* @param AbandonedCartBuilder $abandonedCartRequestBuilder |
54
|
|
|
* @param Client $client |
55
|
|
|
*/ |
56
|
|
|
public function __construct( |
57
|
|
|
AbandonedRepositoryInterface $abandonedRepository, |
58
|
|
|
Logger $logger, |
59
|
|
|
QuoteFactory $quoteFactory, |
60
|
|
|
AbandonedCartBuilder $abandonedCartRequestBuilder, |
61
|
|
|
Client $client |
62
|
|
|
) { |
63
|
|
|
$this->abandonedRepository = $abandonedRepository; |
64
|
|
|
$this->logger = $logger; |
65
|
|
|
$this->quoteFactory = $quoteFactory; |
66
|
|
|
$this->abandonedCartRequestBuilder = $abandonedCartRequestBuilder; |
67
|
|
|
$this->client = $client; |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* @param string $message |
72
|
|
|
* @throws CouldNotSaveException |
73
|
|
|
*/ |
74
|
|
|
public function consume(string $message): void |
75
|
|
|
{ |
76
|
|
|
$message = json_decode($message, true); |
77
|
|
|
|
78
|
|
|
/** @var Quote $quote */ |
79
|
|
|
$quote = $this->quoteFactory->create(); |
80
|
|
|
$quote->loadByIdWithoutStore($message['quote_id']); |
81
|
|
|
|
82
|
|
|
if (!$quote->getId()) { |
83
|
|
|
$this->logger->error(__('The Quote with the "%1" ID doesn\'t exist', $message['quote_id'])); |
84
|
|
|
return; |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
$abandoned = $this->abandonedRepository->getOrCreateByQuoteId($quote->getId()); |
88
|
|
|
$request = $this->abandonedCartRequestBuilder->build($quote); |
89
|
|
|
|
90
|
|
|
try { |
91
|
|
|
$apiResponse = $this->client->getOrderApi()->create(['ecomOrder' => $request]); |
92
|
|
|
} catch (HttpException $e) { |
93
|
|
|
$this->logger->error($e->getMessage()); |
94
|
|
|
return; |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
$abandoned->setActiveCampaignId($apiResponse['ecomOrder']['id']); |
98
|
|
|
$this->abandonedRepository->save($abandoned); |
99
|
|
|
} |
100
|
|
|
} |
101
|
|
|
|
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