MOON
Server: Apache
System: Linux server1.studioinfinity.com.br 2.6.32-954.3.5.lve1.4.90.el6.x86_64 #1 SMP Tue Feb 21 12:26:30 UTC 2023 x86_64
User: artinside (517)
PHP: 7.4.33
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //home/artinside/public_html/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;
    }





}