File: //proc/self/cwd/lhh/source/Support/Frete.php
<?php
/**
* Created by PhpStorm.
* User: sergiohidalgojunior
* Date: 2019-09-17
* Time: 09:23
*/
namespace Source\Support;
use Anam\Phpcart\Cart;
use FlyingLuscas\Correios\Client;
use FlyingLuscas\Correios\Service;
/**
* Class Frete
* @package Source\Support
*/
class Frete
{
/** @var \stdClass */
private $data;
/** @var string */
private $frete;
/** @var \stdClass */
private $config;
public function __construct()
{
$this->frete = new Client();
$this->frete->freight()->origin(CONF_SITE_ADDR_ZIPCODE)->destination(verifyAddress());
$cart = new Cart(CARRINHO);
if($cart->count() < 1){
return false;
}
if(!verifyAddress()){
return false;
}
if(!shippingBox()){
return false;
}
$this->frete->freight()->item(shippingBox()->width, shippingBox()->height, shippingBox()->lenght, shippingBox()->weight, 1);
return $this;
}
public function sedex() : ?\stdClass
{
$this->frete->freight()->services(Service::SEDEX);
$resposta = $this->frete->freight()->calculate()[0];
if($resposta["error"]){
return null;
}
return (object)$resposta;
}
public function pac() : ?\stdClass
{
$this->frete->freight()->services(Service::PAC);
$resposta = $this->frete->freight()->calculate()[0];
if($resposta["error"]){
return null;
}
return (object)$resposta;
}
public function all() : ?\stdClass
{
$this->frete->freight()->services(Service::PAC, Service::SEDEX);
$resposta = $this->frete->freight()->calculate();
if($resposta["error"]){
return null;
}
return (object)$resposta;
}
}