1+ <?php
2+
3+ namespace Etre \Shell \Console \Commands \Import ;
4+
5+ use Etre \Shell \Console \Commands \Import \Products \MapInput ;
6+ use Etre \Shell \Helper \DirectoryHelper ;
7+ use Etre \Shell \Helper \PatchesHelper ;
8+ use Maatwebsite \Excel \Classes \PHPExcel ;
9+ use Maatwebsite \Excel \Excel ;
10+ use N98 \Magento \Command \AbstractMagentoCommand ;
11+ use Symfony \Component \Console \Helper \ProgressBar ;
12+ use Symfony \Component \Console \Input \InputArgument ;
13+ use Symfony \Component \Console \Input \InputInterface ;
14+ use Symfony \Component \Console \Input \InputOption ;
15+ use Symfony \Component \Console \Output \OutputInterface ;
16+ use Symfony \Component \Console \Question \Question ;
17+
18+ class ListCommand extends AbstractMagentoCommand
19+ {
20+ const PRODUCT_IDENTIFIER = "sku " ;
21+ /** @var DirectoryHelper $directoryHelper */
22+ protected $ directoryHelper ;
23+ /** @var PatchesHelper $patchesHelper */
24+ protected $ patchesHelper ;
25+
26+ /**
27+ * PatchCommand constructor.
28+ * @param $patchHelper
29+ */
30+ public function __construct ($ name = null )
31+ {
32+ $ this ->directoryHelper = new DirectoryHelper ();
33+ $ this ->patchesHelper = new PatchesHelper ($ this ->directoryHelper );
34+
35+ parent ::__construct ($ name );
36+ }
37+
38+ public function configure ()
39+ {
40+ $ this
41+ ->setName ('etre:import:list ' )
42+ ->setDescription ('List files in import directory. ' )
43+ ->addArgument ("path " ,InputArgument::OPTIONAL , "Relative path to subdirectory within ./var/import " )
44+ ->setHelp ("This command lists available files " );
45+ }
46+
47+ protected function execute (InputInterface $ input , OutputInterface $ output )
48+ {
49+ $ this ->detectMagento ($ output );
50+ if (!$ this ->initMagento ()) {
51+ return ;
52+ }
53+ $ helper = $ this ->getHelper ('question ' );
54+ $ importDirectory = \Mage::getBaseDir () . DS . "var " . DS . "import " . DS . $ input ->getArgument ("path " );
55+ $ output ->writeln (scandir ($ importDirectory ));
56+ }
57+
58+ /**
59+ * @param string $importFile
60+ * @return \PHPExcel
61+ */
62+ protected function loadFile ($ importFile )
63+ {
64+ try {
65+ $ inputFileType = \PHPExcel_IOFactory::identify ($ importFile );
66+ $ objReader = \PHPExcel_IOFactory::createReader ($ inputFileType );
67+ $ objPHPExcel = $ objReader ->load ($ importFile );
68+ return $ objPHPExcel ;
69+ } catch (Exception $ e ) {
70+ die ('Error loading file " ' . pathinfo ($ importFile , PATHINFO_BASENAME ) . '": ' . $ e ->getMessage ());
71+ }
72+ return $ objPHPExcel ;
73+ }
74+
75+ /**
76+ * @param $lastColumn
77+ * @param $sheet
78+ * @param $row
79+ * @param $inputMappings
80+ */
81+ protected function mapFileColumns ($ lastColumn , $ sheet , $ row , $ inputMappings )
82+ {
83+ $ columnReverseMapping = [];
84+
85+ for ($ column = 'A ' ; $ column != $ lastColumn ; $ column ++):
86+ $ cell = $ sheet ->getCell ($ column . $ row );
87+ $ columnLetter = $ cell ->getColumn ();
88+ $ colIndex = \PHPExcel_Cell::columnIndexFromString ($ columnLetter );
89+ unset($ mapped_magento_attribute );
90+
91+ $ columnHeaderValue = $ cell ->getValue ();
92+ foreach ($ inputMappings as $ attribute_code => $ headerValue ):
93+ if (($ headerValue == $ columnHeaderValue || ($ headerValue == $ colIndex ))):
94+ $ mapped_magento_attribute = $ attribute_code ;
95+ endif ;
96+ endforeach ;
97+ if (!isset ($ mapped_magento_attribute )):
98+ continue ;
99+ else :
100+ $ columnReverseMapping [$ columnLetter ]['magento_attribute_map ' ] = $ mapped_magento_attribute ;
101+ $ columnReverseMapping [$ columnLetter ]["columnIndex " ] = $ colIndex ;
102+ $ columnReverseMapping [$ columnLetter ]["columnName " ] = $ columnHeaderValue ;
103+ $ columnReverseMapping [$ columnLetter ]["column " ] = $ columnLetter ;
104+ endif ;
105+ endfor ;
106+ return $ columnReverseMapping ;
107+ }
108+
109+ /**
110+ * @param $rowMap
111+ * @return mixed
112+ */
113+ protected function itemsToUpdateFilter ($ rowMap )
114+ {
115+ $ attributesToUpdate = $ rowMap ;
116+ unset($ attributesToUpdate [self ::PRODUCT_IDENTIFIER ]);
117+ return $ attributesToUpdate ;
118+ }
119+
120+ }
0 commit comments