|
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
|
|
|
|
|
11
|
|
|
namespace Gpupo\NetshoesSdk\Console\Command; |
|
12
|
|
|
|
|
13
|
|
|
use Gpupo\NetshoesSdk\Console\Application; |
|
14
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
|
15
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
16
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
17
|
|
|
|
|
18
|
|
|
class PriceCommand extends AbstractCommand |
|
19
|
|
|
{ |
|
20
|
|
|
public static function append(Application $app) |
|
21
|
|
|
{ |
|
22
|
|
|
$insertOptions = [ |
|
23
|
|
|
['key' => 'file'], |
|
24
|
|
|
]; |
|
25
|
|
|
|
|
26
|
|
|
$app->appendCommand('product:sku:price:update', 'Atualiza o preço de um SKU') |
|
27
|
|
|
->setDefinition($app->factoryDefinition($insertOptions)) |
|
28
|
|
|
->setCode(function (InputInterface $input, OutputInterface $output) use ($app, $insertOptions) { |
|
29
|
|
|
$list = $app->processInputParameters($insertOptions, $input, $output); |
|
30
|
|
|
|
|
31
|
|
|
$data = json_decode(file_get_contents($list['file']), true); |
|
32
|
|
|
$sdk = $app->factorySdk($list); |
|
33
|
|
|
$sku = $sdk->createSku($data); |
|
34
|
|
|
|
|
35
|
|
|
try { |
|
36
|
|
|
$operation = $sdk->factoryManager('sku')->saveDetail($sku, 'Price'); |
|
37
|
|
|
|
|
38
|
|
|
if (200 === $operation->getHttpStatusCode()) { |
|
39
|
|
|
$output->writeln('<info>Successo!</info>'); |
|
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('Error Code: <comment>'.$e->getCode().'</comment>'); |
|
45
|
|
|
} |
|
46
|
|
|
}); |
|
47
|
|
|
|
|
48
|
|
|
return $app; |
|
49
|
|
|
} |
|
50
|
|
|
} |
|
51
|
|
|
|