2017 © Pedro Peláez
 

library api-correios

Biblioteca para PHP

image

newerton/api-correios

Biblioteca para PHP

  • Sunday, August 3, 2014
  • by newerton
  • Repository
  • 1 Watchers
  • 0 Stars
  • 55 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 4 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

Biblioteca do Correios

Está biblioteca está configurada para o funcionamento correto no Yii Framework., (*1)

Exemplo:, (*2)

$correio = new Correios;

$address["cep_origem"] = $cep_origem;

if (Yii::app()->user->isGuest) {
    $address["cep_destino"] = $cep;
} else {
    $address["cep_destino"] = Yii::app()->user->cep;
}

try {
    $rows = $correio->getQuote($address);
    $this->renderPartial("index", array("rows" => $rows));
} catch (Exception $exc) {
    echo $exc->getTraceAsString();
}

O funcionamento de buscar os produtos do carrinho:, (*3)

class Shop {

    public static function getCartContent() {
        if (is_string(Yii::app()->user->getState("carrinho")))
            return json_decode(Yii::app()->user->getState("carrinho"), true);
        else
            return Yii::app()->user->getState("carrinho");
    }

    public static function setCartContent($cart) {
        return Yii::app()->user->setState("carrinho", json_encode($cart));
    }
}

Controller que adiciona os produtos a sessão:, (*4)

class CarrinhoController extends Controller {

    public function actionAdd($id) {

        $new = true;
        $cart = Shop::getCartContent();

        if (!is_null($cart)) {
            foreach ($cart as $key => $value) {
                if (($value["id"] == $id)) {
                    $new = false;
                    $cart[$key]["quant"] += 1;
                }
            }
        }

        if ($new)
            $cart[] = array("id" => $id, "quant" => 1);

        Shop::setCartcontent($cart);

        $this->redirect(Yii::app()->createAbsoluteUrl("cart"));
    }

}

The Versions

03/08 2014

dev-master

9999999-dev https://github.com/newerton/api-correios

Biblioteca para PHP

  Sources   Download

Apache 2.0

The Requires

  • php >=5.3.0
  • ext-curl *

 

correios pac sedex