| 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\InputArgument; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  | use Symfony\Component\Console\Input\InputInterface; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  | use Symfony\Component\Console\Output\OutputInterface; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  | class ProductCommand extends AbstractCommand | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |     protected $list = ['view', 'insert']; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |      * @codeCoverageIgnore | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 27 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 28 |  |  |     public function insert($app) | 
            
                                                                        
                            
            
                                    
            
            
                | 29 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 30 |  |  |         $insertOptions = [ | 
            
                                                                        
                            
            
                                    
            
            
                | 31 |  |  |             ['key' => 'file'], | 
            
                                                                        
                            
            
                                    
            
            
                | 32 |  |  |         ]; | 
            
                                                                        
                            
            
                                    
            
            
                | 33 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 34 |  |  |         $this->getApp()->appendCommand('product:insert', 'Insere um produto a partir do Json de um arquivo') | 
            
                                                                        
                            
            
                                    
            
            
                | 35 |  |  |             ->setDefinition($this->getApp()->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 |  |  |                 $product = $sdk->createProduct($data); | 
            
                                                                        
                            
            
                                    
            
            
                | 42 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 43 |  |  |                 try { | 
            
                                                                        
                            
            
                                    
            
            
                | 44 |  |  |                     $operation = $sdk->factoryManager('product')->save($product); | 
            
                                                                        
                            
            
                                    
            
            
                | 45 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 46 |  |  |                     if (202 === $operation->getHttpStatusCode()) { | 
            
                                                                        
                            
            
                                    
            
            
                | 47 |  |  |                         $output->writeln('<info>Successo!</info>'); | 
            
                                                                        
                            
            
                                    
            
            
                | 48 |  |  |                     } | 
            
                                                                        
                            
            
                                    
            
            
                | 49 |  |  |                 } catch (\Exception $e) { | 
            
                                                                        
                            
            
                                    
            
            
                | 50 |  |  |                     $output->writeln('<error>Erro na criação</error>'); | 
            
                                                                        
                            
            
                                    
            
            
                | 51 |  |  |                     $output->writeln('Message: <comment>'.$e->getMessage().'</comment>'); | 
            
                                                                        
                            
            
                                    
            
            
                | 52 |  |  |                     $output->writeln('Error Code: <comment>'.$e->getCode().'</comment>'); | 
            
                                                                        
                            
            
                                    
            
            
                | 53 |  |  |                 } | 
            
                                                                        
                            
            
                                    
            
            
                | 54 |  |  |             }); | 
            
                                                                        
                            
            
                                    
            
            
                | 55 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |      * @codeCoverageIgnore | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |     public function view($app) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |         $this->getApp()->appendCommand('product:view', 'Consulta a situação de um produto') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |             ->addArgument('productId', InputArgument::REQUIRED, 'Product ID') | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |             ->setCode(function (InputInterface $input, OutputInterface $output) use ($app) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |                 $list = $app->processInputParameters([], $input, $output); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |                 $p = $app->factorySdk($list)->factoryManager('product')->findById($input->getArgument('productId')); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |                 $app->displayTableResults($output, [[ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |                     'Id'           => $p->getProductId(), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |                     'Brand'        => $p->getBrand(), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |                     'Department'   => $p->getDepartment(), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |                     'Product Type' => $p->getProductType(), | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |                 ]]); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  |                 $output->writeln('<fg=yellow>Skus</>'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  |                 $app->displayTableResults($output, $p->getSkus()); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  |             }); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 81 |  |  | } | 
            
                                                        
            
                                    
            
            
                | 82 |  |  |  |