ERROR

Undefined index: title

/home/wenzelc/domains/wenzel.com.br/public_html/Controllers/Produtos.php 313

1 <?php
2
/**
3* Objeto principal das páginas
4*
5* @package    Shopper
6* @author     Lucas/Postali
7*/    
8    
use Navigation\JsonTransaction;
9    use 
Navigation\Page;
10    use 
Shopper\Defaults;
11    use 
Dynamic\Dynamic;
12
13    use 
Shopper\Shopper;
14    use \
Box\Spout\Reader\Common\Creator\ReaderEntityFactory;
15
16    class 
Produtos extends Shopper
17    
{    
18        
19        
20
21        
/**
22         * Exibe toda a listagem de categorias para o frontend
23         * 
24         * @return array
25         */
26        
public function showCategories ()
27        {
28            
$query $this->_filterAvailableCategory($this->_queryCategory())
29
30                ->
where('visible'Defaults::YES);
31
32            
//Criar uma tabela de subcategorias
33            
$subTable $this->_filterAvailableCategory($this->_queryCategory())
34                
35                ->
alias('subcategories')
36                
37                ->
where('visible'Defaults::YES);
38
39            
//Incluir sub categorias
40            
$query
41                
->append($subTable'id_parent_category''id')
42                
43                ->
whereNull('id_parent_category');
44
45            
// //Esconder categoria black friday
46            // Blackfriday::filterCategory($query, 'id');
47
48            
return $query->select();                
49        }
50
51
52            
/**
53         * Exibe toda a listagem de categorias para o frontend
54         * 
55         * @return array
56         */
57        
public function listcategories($dataJsonTransaction $transaction)
58        {
59            
$query $this->_filterAvailableCategory($this->_queryCategory())
60
61                ->
where('visible'Defaults::YES);
62
63            
//Criar uma tabela de subcategorias
64            
$subTable $this->_filterAvailableCategory($this->_queryCategory())
65                
66                ->
alias('subcategories')
67                
68                ->
where('visible'Defaults::YES);
69
70            
//Incluir sub categorias
71            
$query
72                
->append($subTable'id_parent_category''id')
73                
74                ->
whereNull('id_parent_category');
75
76            
// //Esconder categoria black friday
77            // Blackfriday::filterCategory($query, 'id');
78
79            
return $query->select();                
80        }
81
82
83
84
85        public function 
serialize($dataJsonTransaction $transaction){
86            
87            
$data $this->serializeXLSX($data['file']['tmp_name'], true1);
88            
89
90            foreach (
$data as $item) {
91                
$item['stocks'] = [];
92                
//$image_url = $item['images'];
93                
$item['images'] = [];
94                
$item['categories'] = [];
95
96                
$id_item $this->_saveItem($item);
97
98                
//Se retornou erro, retornar
99                
if($id_item instanceof Fault)
100                    return 
$id_item;
101
102                
//Salvar variações se houver
103                
if(!empty($data['variations']))
104                {
105                    
$variations $this->_saveItemVariations($data['variations'], $id_item);
106
107                    
//Se retornou erro, retornar
108                    
if($variations instanceof Fault)
109                        return 
$variations;
110                }
111
112                
113            }
114        }
115
116        
/**
117         * Resgata um arquivo XLSX e transforma em array
118         * 
119         * @param  string $filePath Caminho do arquivo
120         * @param  boolean $mergeWorksheet Informa se todas as abas devem ser mescladas
121         * @param  boolean $skipRow        Informa se há linhas a serem ignoradas
122         * @param  boolean $useTitles      Informa se devem ser usados títulos
123         * 
124         * @return array
125         */
126        
protected function serializeXLSX ($filePath$mergeWorksheet false$skipRow false$useTitles true)
127        {
128            
//Instancia o leitor
129            
$reader ReaderEntityFactory::createXLSXReader();
130
131            
//Abre o arquivo
132            
$reader->open($filePath);
133
134            
//Array de conteúdo
135            
$content = [];
136
137            
//Iterar cada uma das abas
138            
foreach ($reader->getSheetIterator() as $is => $sheet)
139            {
140                
//Resgatar nome da aba (se pedido para mesclar as abas, utilizar um nome comum)
141                
$sheetName $mergeWorksheet 'merged' $sheet->getName();
142
143                
//Se a aba ainda não existe
144                
if(empty($content[$sheetName]))
145                    
$content[$sheetName] = [];
146
147                
//Títulos das colunas
148                
$titles = [];
149
150                
//Índice da linha
151                
$rowID = -1;
152
153                
//Para cada linha
154                
foreach ($sheet->getRowIterator() as $ir => $row)
155                {
156                    
//Cria o registro dessa linha
157                    
if(!$skipRow || $ir $skipRow)
158                    {
159                        
$rowID++;
160                        
$content[$sheetName][$rowID] = [];
161                    }
162
163                    foreach(
$row->getCells() as $ic => $cell)
164                    {
165                        
//Usar primeira linha como título
166                        
if($ir == 1)
167                            
$titles[$ic] = $cell->getValue();
168
169                        
//Pular linhas definidas
170                        
if($skipRow && $ir <= $skipRow)
171                            continue;
172
173                        
//Identificador da célula
174                        
$cellID $ic;
175
176                        if(
$useTitles && isset($titles[$ic]))
177                            
$cellID $titles[$ic];
178
179                        
$content[$sheetName][$rowID][$cellID] = $cell->getValue();
180                    }
181                }
182            }
183
184            
//Fechar o leitor 
185            
$reader->close();
186
187            
//Se pedido para mesclar as abas, retornar apenas as abas mescladas
188            
if(!empty($content) && $mergeWorksheet)
189                
$content $content['merged'];
190
191            return 
$content;
192        }
193
194        protected function 
normalize ($number)
195        {
196            return 
$number == '-' $number*100;
197        }
198
199        public function 
imposto (Console\Console $console)
200        {
201            
$file $this->getPath('Var/imposto.xlsx');
202            
$table $this->serializeXLSX($filefalse2false);
203            
$impostoTable = new Icecream\Icecream('imposto');
204
205            foreach(
$table as $aba => $valores)
206            {
207                foreach(
$valores as $linha)
208                {
209                    
$estado substr($linha[1], -2);
210                    
211
212                    
$impostoTable->insert([
213                        
'estado' => $estado,
214                        
'id_option' => $linha[2],
215                        
'icms' => $this->normalize($linha[3]),
216                        
'st' => $this->normalize($linha[4]),
217                        
'ipi' => $this->normalize($linha[5]),
218                    ]);
219                }
220            }
221        }
222
223        public function 
vinculaProduto (Console\Console $console)
224        {
225            
$id_category 7;
226            
$id_option 13;
227            
$id_attribute 4;
228
229            
$items $this->_queryItemsCategory()
230                ->
columns('&&.id_item'true)
231                ->
where('&&.id_category'$id_category)
232                ->
list('id_item');
233
234            
//$this->Log($items);
235
236            
foreach($items as $id_item)
237            {
238                \
Shopper\Item\Attribute\Tables::itemAttributeOption()
239                    ->
insert([
240                        
'id_item' => $id_item,
241                        
'id_attribute' => $id_attribute,
242                        
'id_attribute_option' => $id_option,
243                    ]);
244            }
245        }
246
247        
/**
248         * Verifica e insere as variáveis de SEO de uma pagina de um produto
249         * 
250
251         * @param  array $produto   Produto a ser verificado
252         * @param  Page $page      Pagina do produto 
253         * 
254         * Exemplo de uso
255         * 
256         * $this->Produtos->verifySEO($itemCompleto,$this);
257         * 
258         */
259        
public function verifySEO($produto,$page){
260
261            
/**Title padrão */
262            
$page->variables["pageTitle"] = $produto['title']  . " - Wenzel Ferramentas";
263            
264            
/**Meta OgImage */
265            
if(sizeof($produto['images']) > 0){
266                
$page->variables['ogImage'] = $this->getURL().'/'.DEFAULTS::ITEM_IMAGE_PATH.'/' .reset($produto['images'])['image'];
267            }
268
269            
/**Meta Og */
270            
if (!empty($produto['seo']['meta_keywords']))
271                
$page->variables['metaKeywords'] = $produto['seo']['meta_keywords'];
272            
273            if (!empty(
$produto['seo']['meta_description'])){
274                
$page->variables['metaDescription'] = $produto['seo']['meta_description'];
275                
$page->variables['ogDescription'] = $produto['seo']['meta_description'];
276            }
277                
278            if (!empty(
$produto['seo']['meta_title'])){
279                
$page->variables['metaTitle'] = $produto['seo']['meta_title'] . " - Wenzel Ferramentas";
280                
$page->variables['ogTitle'] = $produto['seo']['meta_title'] . " - Wenzel Ferramentas";
281            }
282                
283            else{
284                
$page->variables['metaTitle'] =  $produto['title'] . " - Wenzel Ferramentas";
285                
$page->variables['ogTitle'] = $produto['title'] . " - Wenzel Ferramentas";
286            }
287            
288        }
289
290
291
292
293
294
295
296
297        
/**
298         * Verifica e insere as variáveis de SEO de uma pagina de uma categoria
299         * 
300
301         * @param  array $produto   Produto a ser verificado
302         * @param  Page $page      Pagina do produto 
303         * 
304         * Exemplo de uso
305         * 
306         * $this->Produtos->verifySEOCategory($category_slug,$this);
307         * 
308         */
309        
public function verifySEOCategory($category,$page){
310
311            
$categoryObj $this->getCategoryBySlug($category);
312
313            $page->variables["pageTitle"] = $categoryObj['title']  . " - Wenzel Ferramentas";

314            
$page->variables['metaKeywords'] = $categoryObj['meta_keywords'];
315            
$page->variables['metaDescription'] = $categoryObj['meta_description'];
316            
$page->variables['metaTitle'] = $categoryObj['meta_title'] . " - Wenzel Ferramentas";
317            
$page->variables['ogDescription'] = $categoryObj['meta_description'];
318            
$page->variables['ogTitle'] = $categoryObj['meta_title'] . " - Wenzel Ferramentas";
319        }
320    }

Error trace

You can see detailed error trace in the console.

System trace

You can see detailed error trace in the console.