|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of gpupo/netshoes-sdk |
|
5
|
|
|
* Created by Gilmar Pupo <[email protected]> |
|
6
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
7
|
|
|
* file that was distributed with this source code. |
|
8
|
|
|
* For more information, see <http://www.g1mr.com/>. |
|
9
|
|
|
*/ |
|
10
|
|
|
namespace Gpupo\NetshoesSdk\Console\Command; |
|
11
|
|
|
|
|
12
|
|
|
use Gpupo\NetshoesSdk\Console\Application; |
|
13
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
|
14
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
15
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
16
|
|
|
|
|
17
|
|
|
class TemplatesCommand |
|
18
|
|
|
{ |
|
19
|
|
|
public static function append(Application $app) |
|
20
|
|
|
{ |
|
21
|
|
|
foreach ([ |
|
22
|
|
|
'brands', |
|
23
|
|
|
'flavors', |
|
24
|
|
|
'colors', |
|
25
|
|
|
'sizes', |
|
26
|
|
|
] as $templateKey) { |
|
27
|
|
|
$app->appendCommand('templates:' . $templateKey, 'List of ' . $templateKey) |
|
28
|
|
|
->setCode(function (InputInterface $input, OutputInterface $output) use ($app, $templateKey) { |
|
29
|
|
|
$list = $app->processInputParameters([], $input, $output); |
|
30
|
|
|
$responseList = $app->factorySdk($list)->factoryManager('templates')->fetchByRoute($templateKey); |
|
31
|
|
|
$app->displayTableResults($output, $responseList); |
|
32
|
|
|
}); |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
$app->appendCommand('templates:departments', 'List of departments') |
|
36
|
|
|
->addArgument('buId', InputArgument::REQUIRED, 'Business unit id - NS = Netshoes e ZT = Zattini') |
|
37
|
|
View Code Duplication |
->setCode(function (InputInterface $input, OutputInterface $output) use ($app) { |
|
|
|
|
|
|
38
|
|
|
$list = $app->processInputParameters([], $input, $output); |
|
39
|
|
|
$responseList = $app->factorySdk($list)->factoryManager('templates') |
|
40
|
|
|
->fetchByRoute('departments', 0, 50, [ |
|
41
|
|
|
'buId' => $input->getArgument('buId'), |
|
42
|
|
|
]); |
|
43
|
|
|
$app->displayTableResults($output, $responseList); |
|
44
|
|
|
}); |
|
45
|
|
|
|
|
46
|
|
|
$app->appendCommand('templates:productTypes', 'List of productTypes') |
|
47
|
|
|
->addArgument('departmentCode', InputArgument::REQUIRED, 'Id do departamento') |
|
48
|
|
View Code Duplication |
->setCode(function (InputInterface $input, OutputInterface $output) use ($app) { |
|
|
|
|
|
|
49
|
|
|
$list = $app->processInputParameters([], $input, $output); |
|
50
|
|
|
$responseList = $app->factorySdk($list)->factoryManager('templates') |
|
51
|
|
|
->fetchByRoute('productTypes', 0, 50, [ |
|
52
|
|
|
'departmentCode' => $input->getArgument('departmentCode'), |
|
53
|
|
|
]); |
|
54
|
|
|
$app->displayTableResults($output, $responseList); |
|
55
|
|
|
}); |
|
56
|
|
|
|
|
57
|
|
|
$app->appendCommand('templates:attributes', 'List of attributes') |
|
58
|
|
|
->addArgument('departmentCode', InputArgument::REQUIRED, 'Id do departamento') |
|
59
|
|
|
->addArgument('productTypeCode', InputArgument::REQUIRED, 'Id do Product Type') |
|
60
|
|
View Code Duplication |
->setCode(function (InputInterface $input, OutputInterface $output) use ($app) { |
|
|
|
|
|
|
61
|
|
|
$list = $app->processInputParameters([], $input, $output); |
|
62
|
|
|
$responseList = $app->factorySdk($list)->factoryManager('templates') |
|
63
|
|
|
->fetchByRoute('attributes', 0, 50, [ |
|
64
|
|
|
'departmentCode' => $input->getArgument('departmentCode'), |
|
65
|
|
|
'productTypeCode' => $input->getArgument('productTypeCode'), |
|
66
|
|
|
]); |
|
67
|
|
|
$app->displayTableResults($output, $responseList); |
|
68
|
|
|
}); |
|
69
|
|
|
|
|
70
|
|
|
$app->appendCommand('templates:tree', 'Tree of templates') |
|
71
|
|
|
->addArgument('buId', InputArgument::REQUIRED, 'Business unit id - NS = Netshoes e ZT = Zattini') |
|
72
|
|
|
->setCode(function (InputInterface $input, OutputInterface $output) use ($app) { |
|
73
|
|
|
$list = $app->processInputParameters([], $input, $output); |
|
74
|
|
|
$buId = $input->getArgument('buId'); |
|
75
|
|
|
$manager = $app->factorySdk($list)->factoryManager('templates'); |
|
76
|
|
|
|
|
77
|
|
|
$departaments = $manager->fetchByRoute('departments', 0, 50, [ |
|
78
|
|
|
'buId' => $buId, |
|
79
|
|
|
]); |
|
80
|
|
|
|
|
81
|
|
|
foreach ($departaments as $departament) { |
|
82
|
|
|
$output->writeln('<info>' . $departament->getId() . '</info> ' . $departament->getName()); |
|
83
|
|
|
|
|
84
|
|
|
$types = $manager->fetchByRoute('productTypes', 0, 50, [ |
|
85
|
|
|
'departmentCode' => $departament->getId(), |
|
86
|
|
|
]); |
|
87
|
|
|
|
|
88
|
|
|
foreach ($types as $type) { |
|
89
|
|
|
$output->writeln("\t - " . '<fg=yellow>' . $type->getId() . '</> ' . $type->getName()); |
|
90
|
|
|
|
|
91
|
|
|
$attributes = $manager->fetchByRoute('attributes', 0, 50, [ |
|
|
|
|
|
|
92
|
|
|
'departmentCode' => $departament->getId(), |
|
93
|
|
|
'productTypeCode' => $type->getId(), |
|
94
|
|
|
]); |
|
95
|
|
|
|
|
96
|
|
|
/* |
|
97
|
|
|
foreach($attributes as $attribute) { |
|
98
|
|
|
$output->writeln("\t\t * " . '<fg=blue>'.$attribute->getId().'</> ' . $attribute->getName()); |
|
99
|
|
|
} |
|
100
|
|
|
*/ |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
$output->writeln('<fg=yellow>------</>'); |
|
104
|
|
|
} |
|
105
|
|
|
}); |
|
106
|
|
|
|
|
107
|
|
|
return $app; |
|
108
|
|
|
} |
|
109
|
|
|
} |
|
110
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.