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
|
|
|
use Gpupo\CommonSdk\Exception\ClientException; |
17
|
|
|
class ProductCommand |
18
|
|
|
{ |
19
|
|
|
public static function append(Application $app) |
20
|
|
|
{ |
21
|
|
|
$app->appendCommand('product:view', 'Consulta a situação de um produto') |
22
|
|
|
->addArgument('productId', InputArgument::REQUIRED, 'Product ID') |
23
|
|
|
->setCode(function (InputInterface $input, OutputInterface $output) use ($app) { |
24
|
|
|
$list = $app->processInputParameters([], $input, $output); |
25
|
|
|
|
26
|
|
|
$p = $app->factorySdk($list)->factoryManager('product')->findById($input->getArgument('productId')); |
27
|
|
|
|
28
|
|
|
$app->displayTableResults($output, [[ |
29
|
|
|
'Id' => $p->getProductId(), |
30
|
|
|
'Brand' => $p->getBrand(), |
31
|
|
|
'Department' => $p->getDepartment(), |
32
|
|
|
'Product Type' => $p->getProductType(), |
33
|
|
|
]]); |
34
|
|
|
|
35
|
|
|
$output->writeln('<fg=yellow>Skus</>'); |
36
|
|
|
|
37
|
|
|
$app->displayTableResults($output, $p->getSkus()); |
38
|
|
|
|
39
|
|
|
}); |
40
|
|
|
|
41
|
|
|
$insertOptions = [ |
42
|
|
|
['key' => 'file'], |
43
|
|
|
]; |
44
|
|
|
|
45
|
|
|
$app->appendCommand('product:insert', 'Insere um produto a partir do Json de um arquivo') |
46
|
|
|
->setDefinition($app->factoryDefinition($insertOptions)) |
47
|
|
|
->setCode(function (InputInterface $input, OutputInterface $output) use ($app, $insertOptions) { |
48
|
|
|
$list = $app->processInputParameters($insertOptions, $input, $output); |
49
|
|
|
|
50
|
|
|
$data = json_decode(file_get_contents($list['file']), true); |
51
|
|
|
$sdk = $app->factorySdk($list); |
52
|
|
|
$product = $sdk->createProduct($data); |
53
|
|
|
|
54
|
|
|
try { |
55
|
|
|
$operation = $sdk->factoryManager('product')->save($product); |
56
|
|
|
|
57
|
|
|
if (202 === $operation->getHttpStatusCode()) { |
58
|
|
|
$output->writeln('<info>Successo!</info>'); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
} catch (\Exception $e) { |
62
|
|
|
$output->writeln('<error>Erro na criação</error>'); |
63
|
|
|
$output->writeln('Message: <comment>'.$e->getMessage().'</comment>'); |
64
|
|
|
$output->writeln('Code: <comment>'.$e->getCode().'</comment>'); |
65
|
|
|
} |
66
|
|
|
}); |
67
|
|
|
|
68
|
|
|
return $app; |
69
|
|
|
} |
70
|
|
|
} |
71
|
|
|
|