File: //home/artinside/www/finance/source/Support/FreteFrenet.php
<?php
namespace Source\Support;
use Anam\Phpcart\Cart;
use Frenet\ApiFactory;
class FreteFrenet
{
private $frete;
private $result;
public function __construct(string $zipCodeOrigin, string $zipCodeDestination, float $invoiceValue)
{
$this->frete = ApiFactory::create(FRENET_TOKEN)
->shipping()
->quote()
->setRecipientCountry('BR')
->setSellerPostcode($zipCodeOrigin)
->setRecipientPostcode($zipCodeDestination)
->setShipmentInvoiceValue($invoiceValue);
return $this;
}
private function setItems(){
$cart = new Cart(CARRINHO);
if($cart->count() < 1){
return false;
}
foreach ($cart->getItems() as $item) {
$this->frete->addShippingItem($item->id, $item->quantity, $item->weight, $item->depth, $item->height, $item->width, "General");
}
return $this->frete;
}
public function getServices()
{
$this->setItems();
$this->result = $this->frete->execute();
return $this->result->getShippingServices();
}
}