|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* MIT License |
|
5
|
|
|
* Use of this software requires acceptance of the Evaluation License Agreement. See LICENSE file. |
|
6
|
|
|
*/ |
|
7
|
|
|
|
|
8
|
|
|
namespace SprykerEco\Zed\ArvatoRss\Communication\Plugin\Oms\Condition; |
|
9
|
|
|
|
|
10
|
|
|
use Orm\Zed\ArvatoRss\Persistence\SpyArvatoRssApiCallLog; |
|
11
|
|
|
use Orm\Zed\Sales\Persistence\SpySalesOrderItem; |
|
12
|
|
|
use Spryker\Zed\Kernel\Communication\AbstractPlugin; |
|
13
|
|
|
use Spryker\Zed\Oms\Dependency\Plugin\Condition\ConditionInterface; |
|
14
|
|
|
use SprykerEco\Shared\ArvatoRss\ArvatoRssApiConfig; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* @method \SprykerEco\Zed\ArvatoRss\Business\ArvatorssFacadeInterface getFacade() |
|
18
|
|
|
* @method \SprykerEco\Zed\ArvatoRss\Persistence\ArvatoRssQueryContainerInterface getQueryContainer() |
|
19
|
|
|
* @method \SprykerEco\Zed\ArvatoRss\Communication\ArvatoRssCommunicationFactory getFactory() |
|
20
|
|
|
*/ |
|
21
|
|
|
class IsStoreOrderSuccessfulPlugin extends AbstractPlugin implements ConditionInterface |
|
22
|
|
|
{ |
|
23
|
|
|
/** |
|
24
|
|
|
* @api |
|
25
|
|
|
* |
|
26
|
|
|
* @param \Orm\Zed\Sales\Persistence\SpySalesOrderItem $orderItem |
|
27
|
|
|
* |
|
28
|
|
|
* @return bool |
|
29
|
|
|
*/ |
|
30
|
|
|
public function check(SpySalesOrderItem $orderItem) |
|
31
|
|
|
{ |
|
32
|
|
|
return $this->isStoreOrderSuccessful( |
|
33
|
|
|
$orderItem |
|
34
|
|
|
->getOrder() |
|
35
|
|
|
->getOrderReference() |
|
36
|
|
|
); |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* @param string $orderReference |
|
41
|
|
|
* |
|
42
|
|
|
* @return bool |
|
43
|
|
|
*/ |
|
44
|
|
|
protected function isStoreOrderSuccessful($orderReference) |
|
45
|
|
|
{ |
|
46
|
|
|
$storeOrderApiCallLog = $this->getApiCallLogEntry($orderReference); |
|
47
|
|
|
if ($storeOrderApiCallLog === null) { |
|
48
|
|
|
return false; |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
return $this->isTransactionSuccessfull($storeOrderApiCallLog); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* @param string $orderReference |
|
56
|
|
|
* |
|
57
|
|
|
* @return \Orm\Zed\ArvatoRss\Persistence\SpyArvatoRssApiCallLog |
|
58
|
|
|
*/ |
|
59
|
|
|
protected function getApiCallLogEntry($orderReference) |
|
60
|
|
|
{ |
|
61
|
|
|
return $this->getQueryContainer() |
|
62
|
|
|
->queryApiLogByOrderReferenceAndType( |
|
63
|
|
|
$orderReference, |
|
64
|
|
|
ArvatoRssApiConfig::TRANSACTION_TYPE_STORE_ORDER |
|
65
|
|
|
) |
|
66
|
|
|
->findOne(); |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
/** |
|
70
|
|
|
* @param \Orm\Zed\ArvatoRss\Persistence\Base\SpyArvatoRssApiCallLog $apiCallLog |
|
71
|
|
|
* |
|
72
|
|
|
* @return bool |
|
73
|
|
|
*/ |
|
74
|
|
|
protected function isTransactionSuccessfull(SpyArvatoRssApiCallLog $apiCallLog) |
|
75
|
|
|
{ |
|
76
|
|
|
return $apiCallLog->getResultCode() == ArvatoRssApiConfig::RESULT_CODE_SUCCESS; |
|
77
|
|
|
} |
|
78
|
|
|
} |
|
79
|
|
|
|