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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
<?php
/**
* @copyright Vertex. All rights reserved. https://www.vertexinc.com/
* @author Mediotype https://www.mediotype.com/
*/
namespace Vertex\Tax\Model\Plugin;
use Magento\Config\Model\Config\Structure\Element\Group;
use Vertex\Tax\Model\Config;
use Vertex\Tax\Model\ModuleManager;
/**
* Hides likely unused tax classes from the store configuration
*
* @see Group
*/
class GroupPlugin
{
/** @var Config */
private $config;
/** @var ModuleManager */
private $moduleManager;
/**
* @param ModuleManager $moduleManager
* @param Config $config
*/
public function __construct(ModuleManager $moduleManager, Config $config)
{
$this->moduleManager = $moduleManager;
$this->config = $config;
}
/**
* Hides likely unused tax classes
* MEQP2 Warning: Unused Parameter $subject necessary for plugins
*
* @see Group::setData()
* @param Group $subject
* @param \Closure $proceed
* @param array $data
* @param string $scope
* @return mixed
* @SuppressWarnings(PHPMD.UnusedFormalParameter) $subject is a necessary part of a plugin
*/
public function aroundSetData(Group $subject, \Closure $proceed, $data, $scope)
{
if (!$this->config->isVertexActive() || !$this->config->isTaxCalculationEnabled()) {
return $proceed($data, $scope);
}
$taxClasses = isset($data['path'], $data['id']) && $data['path'] === 'tax' && $data['id'] === 'classes';
if ($taxClasses && !$this->moduleManager->isEnabled('Magento_GiftWrapping')) {
$this->hide(
$data,
[
'giftwrap_order_class',
'giftwrap_order_code',
'giftwrap_item_class',
'giftwrap_item_code',
'printed_giftcard_class',
'printed_giftcard_code',
]
);
}
if ($taxClasses && !$this->moduleManager->isEnabled('Magento_Reward')) {
$this->hide(
$data,
[
'reward_points_class',
'reward_points_code',
]
);
}
return $proceed($data, $scope);
}
/**
* Updates the data array to hide a path
*
* @param array &$data
* @param array $toHide
*/
private function hide(array &$data, array $toHide)
{
if (isset($data['path'], $data['id']) && $data['path'] === 'tax' && $data['id'] === 'classes') {
foreach ($toHide as $code) {
if (is_array($data['children'][$code])) {
$data['children'][$code]['showInDefault'] = 0;
$data['children'][$code]['showInWebsite'] = 0;
$data['children'][$code]['showInStore'] = 0;
}
}
}
}
}