3
3
namespace OxidEsales \MonduPayment \Model ;
4
4
5
5
use OxidEsales \Eshop \Core \Model \ListModel ;
6
+ use OxidEsales \Eshop \Core \Registry ;
7
+ use OxidEsales \MonduPayment \Core \Http \MonduClient ;
6
8
use OxidEsales \MonduPayment \Core \Utils \MonduHelper ;
7
9
use OxidEsales \MonduPayment \Model \MonduOrder ;
8
10
use OxidEsales \MonduPayment \Model \MonduInvoice ;
9
11
10
12
class Order extends Order_parent
11
13
{
14
+ /**
15
+ * @var mixed|\oxdeliveryset|\oxField|\OxidEsales\Eshop\Core\Field|\OxidEsales\EshopCommunity\Application\Model\oxDeliverySet|MonduClient
16
+ */
17
+ private mixed $ client ;
18
+
19
+ public function __construct ()
20
+ {
21
+ parent ::__construct ();
22
+ $ this ->client = oxNew (MonduClient::class);
23
+ }
24
+
12
25
public function getMonduOrders ()
13
26
{
14
27
if ($ this ->isMonduPayment ()) {
@@ -27,11 +40,16 @@ public function getMonduOrders()
27
40
public function getMonduInvoices ()
28
41
{
29
42
if ($ this ->isMonduPayment ()) {
30
- $ sQuery = 'SELECT * FROM `oemondu_invoices` WHERE `invoice_id`= :oxorderid ORDER BY created_at DESC ' ;
43
+ $ sQuery = 'SELECT * FROM `oemondu_invoices` WHERE `invoice_id` IN ( :oxorderid, :oxordernr) ORDER BY created_at DESC ' ;
31
44
32
45
$ oMonduInvoices = oxNew (ListModel::class);
33
46
$ oMonduInvoices ->init (MonduInvoice::class);
34
- $ oMonduInvoices ->selectString ($ sQuery , [':oxorderid ' => $ this ->getId ()]);
47
+ $ oMonduInvoices ->selectString (
48
+ $ sQuery , [
49
+ ':oxorderid ' => $ this ->getId (),
50
+ ':oxordernr ' => $ this ->getFieldData ('oxorder__oxordernr ' )
51
+ ]
52
+ );
35
53
36
54
return $ oMonduInvoices ;
37
55
}
@@ -54,4 +72,47 @@ public function deleteAllArticles()
54
72
55
73
$ this ->recalculateOrder ();
56
74
}
75
+
76
+ /**
77
+ * Order checking, processing and saving method.
78
+ * Before saving performed checking if order is still not executed (checks in
79
+ * database oxorder table for order with know ID), if yes - returns error code 3,
80
+ * if not - loads payment data, assigns all info from basket to new Order object
81
+ * and saves full order with error status. Then executes payment. On failure -
82
+ * deletes order and returns error code 2. On success - saves order (\OxidEsales\Eshop\Application\Model\Order::save()),
83
+ * removes article from wishlist (\OxidEsales\Eshop\Application\Model\Order::_updateWishlist()), updates voucher data
84
+ * (\OxidEsales\Eshop\Application\Model\Order::_markVouchers()). Finally sends order confirmation email to customer
85
+ * (\OxidEsales\Eshop\Core\Email::SendOrderEMailToUser()) and shop owner (\OxidEsales\Eshop\Core\Email::SendOrderEMailToOwner()).
86
+ * If this is order recalculation, skipping payment execution, marking vouchers as used
87
+ * and sending order by email to shop owner and user
88
+ * Mailing status (1 if OK, 0 on error) is returned.
89
+ *
90
+ * @param \OxidEsales\Eshop\Application\Model\Basket $oBasket Basket object
91
+ * @param object $oUser Current User object
92
+ * @param bool $blRecalculatingOrder Order recalculation
93
+ *
94
+ * @return integer
95
+ */
96
+ public function finalizeOrder (\OxidEsales \Eshop \Application \Model \Basket $ oBasket , $ oUser , $ blRecalculatingOrder = false )
97
+ {
98
+ $ result = parent ::finalizeOrder ($ oBasket , $ oUser , $ blRecalculatingOrder );
99
+
100
+ if (
101
+ $ this ->isMonduPayment () &&
102
+ $ this ->getMonduOrders ()
103
+ ) {
104
+ $ monduOrderUuid = array_values ($ this ->getMonduOrders ()->getArray ())[0 ]->getFieldData ( 'order_uuid ' );
105
+
106
+ if (!$ monduOrderUuid || !$ this ->getFieldData ( 'oxorder__oxordernr ' )) {
107
+ return $ result ;
108
+ }
109
+
110
+ $ this ->client ->updateOrderExternalInfo (
111
+ $ monduOrderUuid ,
112
+ ['external_reference_id ' => (string ) $ this ->getFieldData ('oxorder__oxordernr ' )]
113
+ );
114
+ }
115
+
116
+ return $ result ;
117
+ }
57
118
}
0 commit comments