-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMonduHelper.php
82 lines (67 loc) · 2.76 KB
/
MonduHelper.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
<?php
namespace OxidEsales\MonduPayment\Core\Utils;
use OxidEsales\Eshop\Core\Registry;
use OxidEsales\EshopCommunity\Internal\Framework\Module\Setup\Bridge\ModuleActivationBridgeInterface;
use OxidEsales\EshopCommunity\Internal\Container\ContainerFactory;
class MonduHelper
{
public static function removeEmptyElementsFromArray(array $array)
{
return array_filter($array, function ($v) {
return !is_null($v) && $v !== '';
});
}
public static function showErrorMessage($message = '')
{
Registry::getUtilsView()->addErrorToDisplay($message, false);
}
public static function isMonduPayment($paymentId = '')
{
return stripos($paymentId, 'oxmondu') !== false;
}
public static function isMonduModuleActive()
{
$container = ContainerFactory::getInstance()->getContainer();
$moduleActivationBridge = $container->get(ModuleActivationBridgeInterface::class);
return $moduleActivationBridge->isActive(
'oemondu',
Registry::getConfig()->getShopId()
);
}
public static function camelToSnakeCase($string)
{
return strtoupper(preg_replace("/([a-z])([A-Z])/", "$1_$2", $string));
}
public static function getMappedOrderArticles($orderArticles)
{
$mappedArr = array_map(function ($a) {
$article = $a->getArticle();
return [
'external_reference_id' => $article->getFieldData('oxid'),
'title' => $article->getFieldData('oxtitle'),
'net_price_per_item_cents' => round($a->getBasePrice()->getNettoPrice() * 100),
'quantity' => (int) $a->getFieldData('oxamount')
];
}, $orderArticles);
return $mappedArr;
}
public static function ordersHaveSameArticles($order1, $order2)
{
$array1 = array_values($order1->getOrderArticles()->getArray());
$array2 = array_values($order2->getOrderArticles()->getArray());
$mappedArr1 = self::getMappedOrderArticles($array1);
$mappedArr2 = self::getMappedOrderArticles($array2);
return array_diff($mappedArr1, $mappedArr2) == array_diff($mappedArr2, $mappedArr1);
}
public static function isOrderAdjusted($oldOrder, $newOrder)
{
return $oldOrder->getOrderCurrency()->name != $newOrder->getOrderCurrency()->name ||
$oldOrder->getId() != $newOrder->getId() ||
$oldOrder->getOrderNetSum() != $newOrder->getOrderNetSum() ||
array_values($oldOrder->getProductVats(false))[0] != array_values($newOrder->getProductVats(false))[0] ||
$oldOrder->getFieldData('oxtotalordersum') != $newOrder->getFieldData('oxtotalordersum') ||
$oldOrder->getFieldData('oxorder__oxdelcost') != $newOrder->getFieldData('oxorder__oxdelcost') ||
$oldOrder->getFieldData('oxorder__oxdiscount') != $newOrder->getFieldData('oxorder__oxdiscount') ||
!self::ordersHaveSameArticles($oldOrder, $newOrder);
}
}