private static function subtraiEstoque($pedido)
 {
     $itens = PedidoItens::find('pedido_id =' . $pedido);
     $base = new BaseHelper();
     foreach ($itens as $key => $value) {
         $item = PedidoItens::findFisrt('id =' . $value->id);
         $produto = Produtos::findById($value->produto_id);
         if ($value->detalhe_id != '') {
             $chave = $base->arrayMultiSearch($produto['detalhes'], 'detalhe_id', $value->detalhe_id);
             $produto['detalhes'][$chave]['estoque'] = $produto['detalhes'][$chave]['estoque'] - $value->quantidade;
             $produto->save();
         } else {
             $produto->estoque = $produto->estoque - $value->quantidade;
             $produto->save();
         }
     }
 }
 private function setItem($array)
 {
     $base = new BaseHelper();
     $produto = Produtos::findById($array['produto_id'])->toArray();
     $array['id'] = $array['produto_id'];
     $array['name'] = $produto['nome'];
     $array['quantity'] = $array['quantidade'];
     if (isset($array['detalhe_id']) && $array['detalhe_id'] != '') {
         $desconto = $base->getDesconto($produto, $array['detalhe_id']);
         $chave = $base->arrayMultiSearch($produto['detalhes'], 'detalhe_id', $array['detalhe_id']);
         $array['options']['detalhe_id'] = $array['detalhe_id'];
         $array['price'] = $produto['detalhes'][$chave]['valor'] - $desconto;
         if ($desconto != 0) {
             $array['valor_real'] = $produto['detalhes'][$chave]['valor'];
         }
     } else {
         $desconto = $base->getDesconto($produto);
         $valor = isset($produto['valor']) ? $produto['valor'] : $produto['detalhes'][0]['valor'];
         $array['price'] = $valor - $desconto;
         if ($desconto != 0) {
             $array['valor_real'] = $valor;
         }
     }
     unset($array['produto_id']);
     unset($array['detalhe_id']);
     return $array;
 }
 protected function getCores($obj)
 {
     $html = '';
     $index = parent::arrayMultiSearch($this->detalhes, 'label', 'cor');
     if (!is_null($index)) {
         $cores = array_values(array_unique(array_column($obj->detalhes, 'cor')));
         if (count($cores) > 1) {
             foreach ($cores as $key => $value) {
                 $ref = $this->detalhes[$index]['referencia'];
                 $referencia = $ref::findFirst("nome = '{$value}'")->toArray();
                 $url = parent::generateUrl($obj->nome, $obj->_id, 'produto_variacao');
                 $url = $url . '/' . $referencia['nome'] . '/' . $key;
                 $html .= "<a href='{$url}' class='sideColor color-produto-detalhe variacao' style='background-color:{$referencia['hexa']}'></a>";
             }
             $html .= '<br clear="all"/>';
         }
     }
     return $html;
 }
 protected function getItens()
 {
     $html = '';
     foreach ($this->cart->contents() as $key => $value) {
         $produto = Produtos::findById($value->id)->toArray();
         $html .= "<tr class='cart-item {$this->options['item_class']}'>";
         $preco = number_format($value->price, 2, ',', '.');
         $total = number_format($value->price * $value->quantity, 2, ',', '.');
         $imagem = Imagens::findFirst($produto['imagens'][0]);
         $preco_real = $value->valor_real ? '<span class="preco-desconto">R$ ' . number_format($value->valor_real, 2, ',', '.') . '</span>' : '';
         if (!$this->options['resumo']) {
             $html .= "<td><img src='{$this->url_base}{$imagem->url}' class='img-responsive' style='width:100px'/></td>";
             if ($this->ecommerce_options->produto_detalhes == '1') {
                 $chave = parent::arrayMultiSearch($produto['detalhes'], 'detalhe_id', $value->options['detalhe_id']);
                 $variacao = '';
                 foreach (unserialize($this->ecommerce_options->produto_detalhe_options) as $c => $v) {
                     $variacao .= ucwords($v['label']) . ': ' . $produto['detalhes'][$chave]["{$v['label']}"];
                 }
             } else {
                 $variacao = '';
             }
             $html .= "<td>{$value->name}<br/> <span class='cart-variacao'>{$variacao}</span></td>";
             $select = "<select class='form-control cart-update' data-identificador='{$key}'>";
             if ($this->ecommerce_options->produto_detalhes == '0') {
                 $estoque = $produto['estoque'];
             } else {
                 $estoque = isset($value->options) ? $produto['detalhes'][$chave]['estoque'] : $produto['detalhes'][0]['estoque'];
             }
             for ($i = 1; $i <= $estoque; $i++) {
                 $selected = $value->quantity == $i ? 'selected' : '';
                 $select .= "<option value='{$i}' {$selected}>{$i}</option>";
             }
             $select .= '</select>';
             $html .= "<td style='width:18%'>{$select}</td>";
             $html .= "<td>R\$ {$preco} {$preco_real}</td>";
             $html .= "<td class='cart-item-total'>R\$ {$total}</td>";
             $link = $this->url_base . 'cart/remove/' . $key;
             $html .= "<td><a href='{$link}' class='cart-remove'><i class='fa fa-trash fa-2x'></i></a></td>";
         } else {
             $html .= "<td><img src='{$this->url_base}{$imagem->url}' class='img-responsive' style='width:100px'/></td>";
             $html .= "<td>\n\t\t\t\t\t\t\t{$value->name} <br/>\n\t\t\t\t\t\t\t<strong>{$value->quantity} x R\$ {$preco}</strong>\n\t\t\t\t\t\t\t<h5>R\$ {$total}</h5>\n\t\t\t\t</td>";
         }
         $html .= '<tr/>';
     }
     return $html;
 }