/** * Define the enqueue XML data * * @param Varien_Object $order */ private function enfileirarData($order) { $this->_resetData(); //Pega os dados do cliente $customer = Mage::getModel('customer/customer')->load($order->getCustomerId()); //Define os dados da cobrança $this->xmlCompradorNome = (string) $order->getBillingAddress()->getFirstname() . ' ' . $order->getBillingAddress()->getLastname(); $customerDocs = explode(",", Mage::getStoreConfig('allpago/fcontrol/campo_documento')); $cpfLog = null; foreach ($customerDocs as $customerDoc) { $metodo = 'get' . ucfirst($customerDoc); if (!$this->xmlCompradorCpfCnpj && $customer->{$metodo}()) { $this->xmlCompradorCpfCnpj = (string) preg_replace('/[^0-9]/', '', $customer->{$metodo}()); } if ($customer->{$metodo}()) { $cpfLog .= '<pre>' . print_r($customer->getData(), true) . '<br/>Método: ' . $metodo . ' ( ' . $customer->{$metodo}() . ' )</pre>'; } } if (!$this->xmlCompradorCpfCnpj) { Mage::throwException('CPF não encontrado' . $cpfLog); } $this->xmlCompradorSexo = (string) 'M'; // @todo: Pegar esta informação do Magento $this->xmlCompradorDataNascimento = (string) '1900-01-01'; // @todo: Pegar esta informação do Magento $this->xmlCompradorDddTelefone = (string) substr(str_replace(' ', '', preg_replace('/[()-]*/', '', $order->getBillingAddress()->getTelephone())), 0, 2); $this->xmlCompradorNumeroTelefone = (string) substr(str_replace(' ', '', preg_replace('/[()-]*/', '', $order->getBillingAddress()->getTelephone())), 2, 9); $this->xmlCompradorDddCelular = (string) substr(str_replace(' ', '', preg_replace('/[()-]*/', '', $order->getBillingAddress()->getTelephone())), 0, 2); // @todo: Pegar esta informação do Magento / Community e o Enterprise $this->xmlCompradorNumeroCelular = (string) substr(str_replace(' ', '', preg_replace('/[()-]*/', '', $order->getBillingAddress()->getTelephone())), 2, 9); // @todo: Pegar esta informação do Magento / Community e o Enterprise $this->xmlCompradorIP = (string) $order->getRemoteIp(); $this->xmlCompradorEmail = (string) $order->getCustomerEmail(); $this->xmlCompradorEnderecoCep = (string) str_replace(' ', '', preg_replace('/[-.]*/', '', $order->getBillingAddress()->getPostcode())); $this->xmlCompradorEnderecoRua = (string) $order->getBillingAddress()->getStreet(1); $this->xmlCompradorEnderecoNumero = (string) $order->getBillingAddress()->getStreet(2); $this->xmlCompradorEnderecoComplemento = (string) Mage::helper('core/string')->truncate($order->getBillingAddress()->getStreet(3), 100); $this->xmlCompradorEnderecoBairro = (string) $order->getBillingAddress()->getStreet(4); $this->xmlCompradorEnderecoCidade = (string) $order->getBillingAddress()->getCity(); $region = ""; $directoryRegion = Mage::getResourceModel('directory/region_collection'); $directoryRegion->getSelect()->reset()->from(array('main_table' => $directoryRegion->getMainTable()), 'default_name'); $directoryRegion->addFieldToFilter('country_id', 'BR')->addFieldToFilter('region_id', $order->getBillingAddress()->getRegionId()); $billingRegion = $directoryRegion->getResource()->getReadConnection()->fetchOne($directoryRegion->getSelect()); $this->xmlCompradorEnderecoEstado = (string) $billingRegion; //Define os dados de entrega $this->xmlEntregaNome = (string) ($order->getShippingAddress()->getFirstname() . ' ' . $order->getShippingAddress()->getLastname()); $customerDocs = explode(",", Mage::getStoreConfig('allpago/fcontrol/campo_documento')); $this->xmlEntregaCpfCnpj = null; foreach ($customerDocs as $customerDoc) { $metodo = 'get' . ucfirst($customerDoc); if (!$this->xmlEntregaCpfCnpj && $order->getShippingAddress()->{$metodo}()) { $this->xmlEntregaCpfCnpj = (string) preg_replace('/[^0-9]/', '', $order->getShippingAddress()->{$metodo}()); } } $this->xmlEntregaCpfCnpj = $this->xmlEntregaCpfCnpj ? $this->xmlEntregaCpfCnpj : $this->xmlCompradorCpfCnpj; $this->xmlEntregaSexo = (string) 'M'; // @todo: Pegar esta informação do Magento $this->xmlEntregaDataNascimento = (string) '1900-01-01'; // @todo: Pegar esta informação do Magento $this->xmlEntregaDddTelefone = (string) substr(str_replace(' ', '', preg_replace('/[()-]*/', '', $order->getShippingAddress()->getTelephone())), 0, 2); $this->xmlEntregaNumeroTelefone = (string) substr(str_replace(' ', '', preg_replace('/[()-]*/', '', $order->getShippingAddress()->getTelephone())), 2, 9); $this->xmlEntregaDddCelular = (string) substr(str_replace(' ', '', preg_replace('/[()-]*/', '', $order->getBillingAddress()->getTelephone())), 0, 2); // @todo: Pegar esta informação do Magento / Community e o Enterprise $this->xmlEntregaNumeroCelular = (string) substr(str_replace(' ', '', preg_replace('/[()-]*/', '', $order->getShippingAddress()->getTelephone())), 2, 9); // @todo: Pegar esta informação do Magento / Community e o Enterprise $this->xmlEntregaEnderecoCep = (string) str_replace(' ', '', preg_replace('/[-.]*/', '', $order->getShippingAddress()->getPostcode())); $this->xmlEntregaEnderecoRua = (string) $order->getShippingAddress()->getStreet(1); $this->xmlEntregaEnderecoNumero = (string) $order->getShippingAddress()->getStreet(2); $this->xmlEntregaEnderecoComplemento = (string) Mage::helper('core/string')->truncate($order->getShippingAddress()->getStreet(3), 100); $this->xmlEntregaEnderecoBairro = (string) $order->getShippingAddress()->getStreet(4); $this->xmlEntregaEnderecoCidade = (string) $order->getShippingAddress()->getCity(); $directoryRegion = Mage::getResourceModel('directory/region_collection'); $directoryRegion->getSelect()->reset()->from(array('main_table' => $directoryRegion->getMainTable()), 'default_name'); $directoryRegion->addFieldToFilter('country_id', 'BR')->addFieldToFilter('region_id', $order->getShippingAddress()->getRegionId()); $shippingRegion = $directoryRegion->getResource()->getReadConnection()->fetchOne($directoryRegion->getSelect()); $this->xmlEntregaEnderecoEstado = (string) $shippingRegion; //Define os dados dos produtos $totalItems = 0; $items = $order->getAllItems(); $this->xmlPedidoProdutos = array(); foreach ($items as $item) { $this->xmlPedidoProdutos[] = array('Codigo' => (string) $item->getProductId(), 'Descricao' => (string) $item->getName(), 'Quantidade' => (string) $item->getQtyOrdered(), 'ValorUnitario' => (string) $item->getPrice() * 100, 'ListaDeCasamento' => (string) false, 'ParaPresente' => (string) false); $totalItems += $item->getQtyOrdered(); } //Define os dados do pagamento $this->xmlPedidoPagamentos = array('MetodoPagamento' => (string) 'CartaoCredito', 'Valor' => (string) ($order->getGrandTotal() * 100), 'NumeroParcelas' => (string) 1); //Define os dados dos pedido $this->xmlPedidoCodigoPedido = (string) $order->getId(); $dataCompra = new DateTime($order->getCreatedAt()); $dataCompra->setTimezone(new DateTimeZone('America/Sao_Paulo')); $this->xmlPedidoDataCompra = (string) $dataCompra->format('Y-m-d\\TH:i:s'); $this->xmlPedidoQuantidadeItensDistintos = (string) count($items); $this->xmlPedidoQuantidadeTotalItens = (string) $totalItems; $this->xmlPedidoValorTotalCompra = (string) ($order->getGrandTotal() * 100); $this->xmlPedidoValorTotalFrete = (string) ($order->getPayment()->getShippingAmount() * 100); $this->xmlPedidoPrazoEntregaDias = (string) '0'; $this->xmlPedidoCanalVenda = (string) 'Loja Virtual'; }