| 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 Symfony\Component\Console\Input\InputInterface; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  | use Symfony\Component\Console\Output\OutputInterface; | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 19 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 20 |  |  | class DetailCommand extends AbstractCommand | 
            
                                                                        
                            
            
                                    
            
            
                | 21 |  |  | { | 
            
                                                                        
                            
            
                                    
            
            
                | 22 |  |  |     /** | 
            
                                                                        
                            
            
                                    
            
            
                | 23 |  |  |      * @codeCoverageIgnore | 
            
                                                                        
                            
            
                                    
            
            
                | 24 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |     public function main($app) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |         $insertOptions = [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |             ['key' => 'file'], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |             [ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |                 'key'     => 'type', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |                 'options' => ['Price', 'PriceSchedule', 'Stock', 'Status'], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |                 'default' => 'Price', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |             ], | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |         ]; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |         $this->getApp()->appendCommand('product:sku:detail:update', 'Atualiza detalhes de um SKU') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |             ->setDefinition($this->getApp()->factoryDefinition($insertOptions)) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |             ->setCode(function (InputInterface $input, OutputInterface $output) use ($app, $insertOptions) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |                 $list = $app->processInputParameters($insertOptions, $input, $output); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |                 $data = json_decode(file_get_contents($list['file']), true); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |                 $sdk = $app->factorySdk($list); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |                 $sku = $sdk->createSku($data); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |                 try { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |                     $type = ucfirst($list['type']); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |                     $operation = $sdk->factoryManager('sku')->saveDetail($sku, $type); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |                     if (in_array($operation->getHttpStatusCode(), [200, 201], true)) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |                         $output->writeln('Atualizando <comment>'.$type.'</comment>'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |                         $output->writeln('<info>Successo!</info>'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |                     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |                 } catch (\Exception $e) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |                     $output->writeln('<error>Erro na criação</error>'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |                     $output->writeln('Message: <comment>'.$e->getMessage().'</comment>'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |                     $output->writeln('Error Code: <comment>'.$e->getCode().'</comment>'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |                 } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |             }); | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 59 |  |  |     } | 
            
                                                        
            
                                    
            
            
                | 60 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 61 |  |  |  |