function _getPreco_site_correios($cart, $method, $cart_prices) { //Define medidas e formato da embalagem //Usei os valores mínimos (16x11x2 Cm) para todas as medidas a seguir: //Comprimento médio dos pacotes utilizados para envio pelos Correios(Cm) $this->Order_Length = $method->Comprimento_SN; //Largura/Diâmetro médio dos pacotes utilizados para envio pelos Correios(Cm) $this->Order_Width = $method->Larg_Diam_SN; //Altura média dos pacotes utilizados para envio pelos Correios(Cm) $this->Order_Height = $method->Altura_SN; //Tipo de embrulho dos Correios $this->Order_Formatos = $method->Formatos_SN; //Taxa de empacotamento e manuseio, e será acrescida aos custos de envio retornados pelos Correios $this->Order_Handling_Fee = $method->Handling_Fee_SN; $this->Order_Handling_Fee = floatval(str_replace(",", ".", $this->Order_Handling_Fee)); //Serviço Mão Própria dos Correios $this->Order_MaoPropria = $method->MaoPropria_SN; //Aviso de Recebimento dos Correios $this->Order_Aviso = $method->AvisoReceb_SN ? "S" : "N"; $this->correios_total = 0; $this->correios_prazo = 0; if ($method->FreteProduto_SN == 1) { $product_length = 0; $product_width = 0; $product_height = 0; foreach ($cart->products as $k => $product) { // converte pra centímetros if ($product->product_lwh_uom != 'CM') { $product_length = ShopFunctions::convertDimensionUnit($product->product_length, $product->product_lwh_uom, "CM"); $product_width = ShopFunctions::convertDimensionUnit($product->product_width, $product->product_lwh_uom, "CM"); $product_height = ShopFunctions::convertDimensionUnit($product->product_height, $product->product_lwh_uom, "CM"); } else { $product_height = $product->product_height; $product_width = $product->product_width; $product_length = $product->product_length; } if ($product_length < 16) { $product_length = "16"; } if ($product_width < 11) { $product_width = "11"; } if ($product_height < 2) { $product_height = "2"; } $this->Order_Length = round($product_length, 2); $this->Order_Width = round($product_width, 2); // $this->Order_Height = round($product_height * $product->quantity,2); $this->Order_Height = round($product_height, 2); // converte para kilos $product_weight = ShopFunctions::convertWeigthUnit($product->product_weight, $product->product_weight_uom, "KG"); // $peso = $product_weight * $product->quantity; $peso = $product_weight; //$total_preco = $product->product_price * $product->quantity; $total_preco = $product->product_price; // sempre pega o maior prazo $dados_frete = $this->_parametrosCorreios($total_preco, $method, $peso); // pra cada produto, faz a soma de cada produto em separado $dados_frete['valor'] = str_replace(",", ".", $dados_frete['valor']); $this->correios_total = $dados_frete['valor'] * $product->quantity; //$this->correios_total = $dados_frete['valor']; // for ($i=0; $i < $product->quantity; $i++) { // $this->correios_total += $dados_frete['valor']; // } if ($this->correios_prazo < $dados_frete['prazo']) { $this->correios_prazo = $dados_frete['prazo']; } } } else { // calcular o volume total do pedido ( um cálculo por pedido ) foreach ($cart->products as $k => $product) { //Define medidas minimas // converte pra centímetros $this->Order_Height = 0; if (strtoupper($product->product_lwh_uom) != 'CM') { $product_length = ShopFunctions::convertDimensionUnit($product->product_length, $product->product_lwh_uom, "CM"); $product_width = ShopFunctions::convertDimensionUnit($product->product_width, $product->product_lwh_uom, "CM"); $product_height = ShopFunctions::convertDimensionUnit($product->product_height, $product->product_lwh_uom, "CM"); } else { $product_height = $product->product_height; $product_width = $product->product_width; $product_length = $product->product_length; } if ($method->debug) { vmdebug('<b>Dimension Unit - ' . $product->virtuemart_product_id . '</b>:', $product->product_lwh_uom); vmdebug('<b>Height - ' . $product->virtuemart_product_id . '</b>:', $product_height); vmdebug('<b>Width - ' . $product->virtuemart_product_id . '</b>:', $product_width); vmdebug('<b>Length - ' . $product->virtuemart_product_id . '</b>:', $product_length); } if ($method->VolumeProduto_SN == '1') { $product_height = round($product_height * $product->quantity, 2); if ($product_height > $this->Order_Height) { $this->Order_Height += $product_height; } if ($product_width > $this->Order_Width) { $this->Order_Width = $product_width; } if ($product_length > $this->Order_Length) { $this->Order_Length = $product_length; } } else { if ($product_height > $this->Order_Height) { $this->Order_Height = $product_height; } if ($product_width > $this->Order_Width) { $this->Order_Width = $product_width; } if ($product_length > $this->Order_Length) { $this->Order_Length = $product_length; } } } // preco total do pedido $total_preco = $cart_prices['salesPrice']; $dados_frete = $this->_parametrosCorreios($total_preco, $method, $this->Order_WeightKG); $correios_total = str_replace(",", ".", $dados_frete['valor']); $this->correios_total = $correios_total; $this->correios_prazo = $dados_frete['prazo']; } if (!empty($method->Prazo_Extra_SN) and $method->Prazo_Extra_SN > 0) { $this->correios_prazo += $method->Prazo_Extra_SN; } if ($method->Handling_Fee_SN_type == 'plus') { $this->total = $this->correios_total + $this->Order_Handling_Fee; } else { if ($this->Order_Handling_Fee > 0) { $this->total = $this->correios_total * $this->Order_Handling_Fee; } else { $this->total = $this->correios_total; } } return; }