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 SkuCommand |
18
|
|
|
{ |
19
|
|
|
public static function append(Application $app) |
20
|
|
|
{ |
21
|
|
|
$insertOptions = [ |
22
|
|
|
['key' => 'file'], |
23
|
|
|
]; |
24
|
|
|
|
25
|
|
|
$app->appendCommand('product:sku:update', 'Atualiza um SKU') |
26
|
|
|
->setDefinition($app->factoryDefinition($insertOptions)) |
27
|
|
View Code Duplication |
->setCode(function (InputInterface $input, OutputInterface $output) use ($app, $insertOptions) { |
|
|
|
|
28
|
|
|
$list = $app->processInputParameters($insertOptions, $input, $output); |
29
|
|
|
|
30
|
|
|
$data = json_decode(file_get_contents($list['file']), true); |
31
|
|
|
$sdk = $app->factorySdk($list); |
32
|
|
|
$product = $sdk->createSku($data); |
33
|
|
|
|
34
|
|
|
try { |
35
|
|
|
$operation = $sdk->factoryManager('sku')->save($product); |
36
|
|
|
|
37
|
|
|
if (202 === $operation->getHttpStatusCode()) { |
38
|
|
|
$output->writeln('<info>Successo!</info>'); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
} catch (\Exception $e) { |
42
|
|
|
$output->writeln('<error>Erro na criação</error>'); |
43
|
|
|
$output->writeln('Message: <comment>'.$e->getMessage().'</comment>'); |
44
|
|
|
$output->writeln('Code: <comment>'.$e->getCode().'</comment>'); |
45
|
|
|
} |
46
|
|
|
}); |
47
|
|
|
|
48
|
|
|
return $app; |
49
|
|
|
} |
50
|
|
|
} |
51
|
|
|
|
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.