1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of gpupo/netshoes-sdk |
5
|
|
|
* Created by Gilmar Pupo <[email protected]> |
6
|
|
|
* For the information of copyright and license you should read the file |
7
|
|
|
* LICENSE which is distributed with this source code. |
8
|
|
|
* Para a informação dos direitos autorais e de licença você deve ler o arquivo |
9
|
|
|
* LICENSE que é distribuído com este código-fonte. |
10
|
|
|
* Para obtener la información de los derechos de autor y la licencia debe leer |
11
|
|
|
* el archivo LICENSE que se distribuye con el código fuente. |
12
|
|
|
* For more information, see <http://www.g1mr.com/>. |
13
|
|
|
*/ |
14
|
|
|
|
15
|
|
|
namespace Gpupo\NetshoesSdk\Console\Command; |
16
|
|
|
|
17
|
|
|
use Gpupo\NetshoesSdk\Console\Application; |
18
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
19
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
20
|
|
|
|
21
|
|
|
class DetailCommand extends AbstractCommand |
22
|
|
|
{ |
23
|
|
|
public static function append(Application $app) |
24
|
|
|
{ |
25
|
|
|
$insertOptions = [ |
26
|
|
|
['key' => 'file'], |
27
|
|
|
[ |
28
|
|
|
'key' => 'type', |
29
|
|
|
'options' => ['Price', 'PriceSchedule', 'Stock', 'Status'], |
30
|
|
|
'default' => 'Price' |
31
|
|
|
], |
32
|
|
|
]; |
33
|
|
|
|
34
|
|
|
$app->appendCommand('product:sku:detail:update', 'Atualiza detalhes de um SKU') |
35
|
|
|
->setDefinition($app->factoryDefinition($insertOptions)) |
36
|
|
|
->setCode(function (InputInterface $input, OutputInterface $output) use ($app, $insertOptions) { |
37
|
|
|
$list = $app->processInputParameters($insertOptions, $input, $output); |
38
|
|
|
|
39
|
|
|
$data = json_decode(file_get_contents($list['file']), true); |
40
|
|
|
$sdk = $app->factorySdk($list); |
41
|
|
|
$sku = $sdk->createSku($data); |
42
|
|
|
|
43
|
|
|
try { |
44
|
|
|
$type = ucfirst($list['type']); |
45
|
|
|
$operation = $sdk->factoryManager('sku')->saveDetail($sku, $type); |
46
|
|
|
|
47
|
|
|
if (200 === $operation->getHttpStatusCode()) { |
48
|
|
|
$output->writeln('Atualizando <comment>'.$type.'</comment>'); |
49
|
|
|
$output->writeln('<info>Successo!</info>'); |
50
|
|
|
} |
51
|
|
|
} catch (\Exception $e) { |
52
|
|
|
$output->writeln('<error>Erro na criação</error>'); |
53
|
|
|
$output->writeln('Message: <comment>'.$e->getMessage().'</comment>'); |
54
|
|
|
$output->writeln('Error Code: <comment>'.$e->getCode().'</comment>'); |
55
|
|
|
} |
56
|
|
|
}); |
57
|
|
|
|
58
|
|
|
return $app; |
59
|
|
|
} |
60
|
|
|
} |
61
|
|
|
|