Example #1
0
 public function getStandardCheckoutFormFields()
 {
     $orderId = $this->getCheckout()->getLastOrderId();
     $order = Mage::getModel('sales/order')->load($orderId);
     $a = $order->getIsNotVirtual() ? $order->getShippingAddress() : $order->getShippingAddress();
     //$a = $this->getQuote()->getShippingAddress();
     // Fazendo o telefone
     list($ddd, $telefone) = $this->_trataTelefone($a->getTelephone());
     // Dados de endereço (Endereço)
     list($endereco, $numero, $complemento) = $this->_endereco($a->getStreet(1) . ' ' . $a->getStreet(2));
     // Dados de endereço (CEP)
     $cep = preg_replace('@[^\\d]@', '', $a->getPostcode());
     // Montando os dados para o formulário
     $sArr = array('encoding' => 'UTF-8', 'email_cobranca' => $this->getConfigData('emailID'), 'Tipo' => "CP", 'Moeda' => "BRL", 'ref_transacao' => $order->getRealOrderId(), 'cliente_nome' => $a->getFirstname() . ' ' . $a->getLastname(), 'cliente_cep' => $cep, 'cliente_end' => $endereco, 'cliente_num' => $numero, 'cliente_compl' => $complemento, 'cliente_bairro' => "?", 'cliente_cidade' => $a->getCity(), 'cliente_uf' => $a->getRegionCode(), 'cliente_pais' => $a->getCountry(), 'cliente_ddd' => $ddd, 'cliente_tel' => $telefone, 'cliente_email' => $order->getCustomerEmail());
     $items = $order->getAllVisibleItems();
     $shipping_amount = $order->getBaseShippingAmount();
     $tax_amount = $order->getBaseTaxAmount();
     $discount_amount = $order->getBaseDiscountAmount();
     if ($items) {
         $i = 1;
         foreach ($items as $item) {
             $item_price = 0;
             $item_qty = $item->getQtyToShip();
             if ($children = $item->getChildrenItems()) {
                 foreach ($children as $child) {
                     $item_price += $child->getBasePrice() * $child->getQtyOrdered() / $item_qty;
                 }
                 $item_price = $this->formatNumber($item_price);
             }
             if (!$item_price) {
                 $item_price = $this->formatNumber($item->getBasePrice());
             }
             $sArr = array_merge($sArr, array('item_descr_' . $i => $item->getName(), 'item_id_' . $i => $item->getSku(), 'item_quant_' . $i => $item_qty, 'item_peso_' . $i => round($item->getWeight()), 'item_valor_' . $i => $item_price));
             $i++;
         }
         if ($tax_amount > 0) {
             $tax_amount = $this->formatNumber($tax_amount);
             $sArr = array_merge($sArr, array('item_descr_' . $i => "Taxa", 'item_id_' . $i => "taxa", 'item_quant_' . $i => 1, 'item_valor_' . $i => $tax_amount));
             $i++;
         }
         if ($discount_amount != 0) {
             $discount_amount = $this->formatNumber($discount_amount);
             if (preg_match("/^1\\.[23]/i", Mage::getVersion())) {
                 $discount_amount = -$discount_amount;
             }
             $sArr = array_merge($sArr, array('extras' => $discount_amount));
         }
         $module = new PagSeguro_Model_Carrier_ShippingMethod();
         $active = $module->getConfigData('active');
         if (!$active) {
             if ($shipping_amount > 0) {
                 $shipping_amount = $this->formatNumber($shipping_amount);
                 // passa o valor do frete como um produto
                 $sArr = array_merge($sArr, array('item_descr_' . $i => substr($order->getShippingDescription(), 0, 100), 'item_id_' . $i => "frete", 'item_quant_' . $i => 1, 'item_valor_' . $i => $shipping_amount));
                 $i++;
             }
         }
     }
     $transaciton_type = $this->getConfigData('transaction_type');
     $totalArr = $a->getTotals();
     $shipping = sprintf('%.2f', $order->getBaseShippingAmount());
     if ($active) {
         // passa o valor do frete total em uma única variavel para o pagseguro, utilizado junto com o modulo de correio
         $sArr = array_merge($sArr, array('item_frete_1' => str_replace(".", ",", $shipping * 100)));
         $e = 'EN';
         if ($order->_data['shipping_method'] == 'pagseguro_pagseguro:Sedex') {
             $e = 'SD';
         }
         $sArr = array_merge($sArr, array('tipo_frete' => $e));
     }
     $sReq = '';
     $rArr = array();
     foreach ($sArr as $k => $v) {
         /*
            replacing & char with and. otherwise it will break the post
         */
         $value = str_replace("&", "and", $v);
         $rArr[$k] = $value;
         $sReq .= '&' . $k . '=' . $value;
     }
     return $rArr;
 }
Example #2
0
 public function gerar($CepOrigem, $Peso, $Valor, $Destino)
 {
     $module = new PagSeguro_Model_Carrier_ShippingMethod();
     $valores = array();
     if ($Valor <= 10000) {
         if ($Peso <= 30) {
             $Peso = str_replace('.', ',', $Peso);
             $url = "https://pagseguro.uol.com.br/desenvolvedor/simulador_de_frete_calcular.jhtml?postalCodeFrom={$CepOrigem}&weight={$Peso}&value={$Valor}&postalCodeTo={$Destino}";
             $this->request($url);
             $result = explode('|', $this->_result);
             if ($result[0] == 'ok') {
                 $valores['Sedex'] = $result[3];
                 $valores['PAC'] = $result[4];
             } else {
                 // Cond. erro cep
                 $fixo_no_sedex = $module->getConfigData('fixo_no_sedex');
                 $valores['Sedex'] = $fixo_no_sedex;
                 $fixo_no_pac = $module->getConfigData('fixo_no_pac');
                 $valores['PAC'] = $fixo_no_pac;
             }
         } else {
             // Cond. Peso > 30kg
             $fixo_sedex_up_kg = $module->getConfigData('fixo_sedex_up_kg');
             $valores['Sedex'] = $fixo_sedex_up_kg;
             $fixo_pac_up_kg = $module->getConfigData('fixo_pac_up_kg');
             $valores['PAC'] = $fixo_pac_up_kg;
         }
     } else {
         // Cond. valor > 10.000
         $fixo_sedex_up_valor = $module->getConfigData('fixo_sedex_up_valor');
         $valores['Sedex'] = $fixo_sedex_up_valor;
         $fixo_pac_up_valor = $module->getConfigData('fixo_pac_up_valor');
         $valores['PAC'] = $fixo_pac_up_valor;
     }
     return $valores;
 }