Jump to content
Fórum Script Brasil
  • 0

Web Service + WSDL


Renato Penna

Question

Boa tarde a todos. Eu estou tentando fazer um webservice com WSDL. Porém eu nunca fiz isso e não está funcionando. Alguém pode me ajudar ? Eu fiz estes arquivos:

Loja.php

<?php
class Loja
{
    private $proxy;
    private $sessionId;
    private $atributeSets;
    private $set;
    private $caracteristicas;
    
    function getProxy()
    {
        return $this->proxy;
    }
    function setProxy($value)
    {
        $this->proxy = $value;
    }
    
    function getSessionId()
    {
        return $this->sessionId;
    }
    function setSessionId($value)
    {
        $this->sessionId = $value;
    }
    
    function getAtributeSets()
    {
        return $this->atributeSets;
    }
    function setAtributeSets($value)
    {
        $this->atributeSets = $value;
    }
    
    function getSet()
    {
        return $this->set;
    }
    function setSet($value)
    {
        $this->set = $value;
    }
    
    function getCaracteristicas()
    {
        return $this->caracteristicas;
    }
    function setCaracteristicas($value)
    {
        $this->caracteristicas = $value;
    }
    
    function pegarDados()
    {
        $proxy = new SoapClient('http://manutencao.workcopy.lojasingular.com.br/api/soap/?wsdl');
        //$this->setProxy(new SoapClient('http://manutencao.workcopy.lojasingular.com.br/api/soap/?wsdl'));
        $sessionId = $proxy->login('jefersonsilva', '123456');
        //$this->setSessionId($this->getProxy()->login('jefersonsilva', '123456'));
        $atributeSets = $proxy->call($sessionId, 'product_attribute_set.list');
        //$this->setAtributeSets($this->getProxy()->call($sessionId, 'product_attribute_set.list'));
        $set = current($atributeSets);
        //$this->setSet(current($this->getAtributeSets()));
        $caracteristicas = $proxy->call($sessionId, 'sales_order.list', array(array('state'=>array('eq'=>'processing'))));
        //$this->setCaracteristicas($this->getProxy()->call($sessionId, 'sales_order.list', array(array('state'=>array('eq'=>'processing')))));
        
        for($i=0;$i<count($caracteristicas);$i++)
        {
            $dados_loja = $proxy->call($sessionId, 'sales_order.info',$caracteristicas[$i]["increment_id"]);
        }
        return $dados_loja;
        
        /*
        $vet_caracteristicas = $this->getCaracteristicas();
        for($i=0;$i<count($this->getCaracteristicas());$i++)
        {
            $dados_loja = $this->getProxy()->call($sessionId, 'sales_order.info',$vet_caracteristicas[$i]["increment_id"]);
        }
        return $vet_caracteristicas;
         */
    }
}
?>
Sog.php
<?php
class Sog
{
    private $username;
    private $password;
    private $customerType;
    private $customerIdentifier;
    private $customerExtraIdentifier;
    private $customerName;
    private $customerEmail;
    private $customerBillingAddress;
    private $customerShippingAddress;
    private $sogob;
    
    function getUsername()
    {
        return $this->username;
    }
    function setUsername($value)
    {
        $this->username = $value;
    }
    
    function getPassword()
    {
        return $this->password;
    }
    function setPassword($value)
    {
        $this->password = $value;
    }
    
    function getCustomerType()
    {
        return $this->customertype;
    }
    function setCustomerType($value)
    {
        $this->customerType = $value;
    }
    
    function getCustomerIdentifier()
    {
        return $this->customeridentifier;
    }
    function setCustomerIdentifier($value)
    {
        $this->customerIdentifier = $value;
    }
    
    function getCustomerExtraIdentifier()
    {
        return $this->customerExtraIdentifier;
    }
    function setCustomerExtraIdentifier($value)
    {
        $this->customerExtraIdentifier = $value;
    }
    
    function getCustomerName()
    {
        return $this->customerName;
    }
    function setCustomerName($value)
    {
        $this->customerName = $value;
    }
    
    function getEmail()
    {
        return $this->customerEmail;
    }
    function setEmail($value)
    {
        $this->customerEmail = $value;
    }
    
    function getCustomerBillingAddress()
    {
        return $this->customerBillingAddress;
    }
    function setCustomerBillingAddress($value)
    {
        $this->customerBillingAddress = $value;
    }
    
    function getCustomerShippingAddress()
    {
        return $this->customerShippingAddress;
    }
    function setCustomerShippingAddress($value)
    {
        $this->customerShippingAddress = $value;
    }
    
    function enviarDados($dl)
    {
        $this->sogob = new SoapClient("http://lajedo.singulardigital.com.br:6060/sog/services/orderWS?wsdl");
        $sessionId = $this->sogob->login($this->getUsername(),  $this->getPassword());

        $lines = NULL;
        foreach($dl as $item)
    {
            $lines[] = Array(
            "isbn" => $item["sku"],
            "quantity" => $item["qty_ordered"],
            "price" => $item["price"]
            );
    }
        
        $params = Array(
        "username" => $this->getUsername(),
    "password" => $this->getPassword(),
    "customerType" => $this->getCustomerType(),
    "customerIdentifier" => $this->getCustomerIdentifier(),
    "customerExtraIdentifier" => $this->getCustomerExtraIdentifier(),
    "customerName" => $this->getCustomerName(),
    "customerEmail" => $this->getEmail(),
    "customerBillingAddress" => (Object) $this->getCustomerBillingAddress(),
    "customerShippingAddress" => (Object) $this->getCustomerBillingAddress(),
    "partnerOrderId" => $dl->sku,
    "shippingPrice" => $dl->shipping_amount,
    "lines" => $lines);
        /*
        $params = Array(
    "username" => $this->username,
    "password" => $this->password,
    "customerType" => $this->customerType,
    "customerIdentifier" => $this->customerIdentifier,
    "customerExtraIdentifier" => $this->customerExtraIdentifier,
    "customerName" => $this->customerName,
    "customerEmail" => $this->customerEmail,
    "customerBillingAddress" => (Object) $this->customerBillingAddress,
    "customerShippingAddress" => (Object) $this->customerBillingAddress,
    "partnerOrderId" => $dados->numeroDoPedido,
    "shippingPrice" => $dados->frete,
    "lines" => $lines
    );        
        */
        $dados_envio = $this->sogob->catalogStoredOrder($params);
        return $dados_envio;
    }
}
?>
web_service.php
<?php
include("loja.php");
include("sog.php");

$loja = new Loja();
$sog = new Sog();

$dados_loja = $loja->pegarDados();
$sog->setUsername("aaaa");
$sog->setPassword("bbbb123456");
$sog->setCustomerType("1");
$sog->setCustomerIdentifier("09900243773");
$sog->setCustomerExtraIdentifier("123456");
$sog->setCustomerName("Teste");
$sog->setEmail("teste@teste.com.br");
$sog->setCustomerBillingAddress("Rua teste número 368");
$sog->setCustomerShippingAddress("Rua teste número 368");
var_dump($sog->enviarDados($dados_loja));
?>

Quando eu mando rodar o web_service.php, fica um tempão rodando e no fim não aparece nada na tela. Nem erro nem nada. O que está faltando ou errado ? Desde já agradeço.

Link to comment
Share on other sites

2 answers to this question

Recommended Posts

  • 0

Não posso porque estou usando integração com o webservice do Magento também e se eu usar o nuSoap ele pára de funcionar.

Eu coloquei essas duas linhas no webservice.php e deu a mesma coisa. Ficou rodando e depois parou e não apareceu nada na tela. O webservice.php ficou assim:

<?php
set_time_limit(0);
error_reporting(E_ALL|E_STRICT);
include("loja.php");
include("sog.php");

$loja = new Loja();
$sog = new Sog();

$dados_loja = $loja->pegarDados();
$sog->setUsername("josemando@singulardigital.com.br");
$sog->setPassword("josemando123");
$sog->setCustomerType("1");
$sog->setCustomerIdentifier("09900243773");
$sog->setCustomerExtraIdentifier("123456");
$sog->setCustomerName("Teste");
$sog->setEmail("teste@teste.com.br");
$sog->setCustomerBillingAddress("Rua teste número 368");
$sog->setCustomerShippingAddress("Rua teste número 368");
var_dump($sog->enviarDados($dados_loja));
?>

Edited by Renato Penna
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



  • Forum Statistics

    • Total Topics
      152.2k
    • Total Posts
      652k
×
×
  • Create New...