Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- defined('BASEPATH') OR exit('No direct script access allowed');
- class Checkout extends CI_Controller {
- function __construct()
- {
- parent::__construct();
- $this->load->library(array('template', 'cart'));
- $this->load->model('app_home');
- $this->load->library('form_validation');
- }
- public function index()
- {
- $this->template->alfatihmart("checkout");
- }
- public function city()
- {
- $prov = $this->input->post('prov', TRUE);
- $curl = curl_init();
- curl_setopt_array($curl, array(
- CURLOPT_URL => "http://api.rajaongkir.com/starter/city?province=$prov",
- CURLOPT_RETURNTRANSFER => true,
- CURLOPT_ENCODING => "",
- CURLOPT_MAXREDIRS => 10,
- CURLOPT_TIMEOUT => 30,
- CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
- CURLOPT_CUSTOMREQUEST => "GET",
- CURLOPT_HTTPHEADER => array(
- "key: b03354ea01da154f19e1d300a9497a16"
- ),
- ));
- $response = curl_exec($curl);
- $err = curl_error($curl);
- curl_close($curl);
- if ($err) {
- echo "cURL Error #:" . $err;
- } else {
- $data = json_decode($response, TRUE);
- echo '<option value="" selected disabled>kota / kabupaten</option>';
- for ($i=0; $i < count($data['rajaongkir']['results']); $i++) {
- echo '<option value="' .$data['rajaongkir']['results'][$i]['city_id'].','.$data['rajaongkir']['results'][$i]['city_name'].'">'.$data['rajaongkir']['results'][$i]['city_name'].'</option>';
- }
- }
- }
- public function getcost()
- {
- $asal = 445;
- $dest = $this->input->post('dest', TRUE);
- $kurir = $this->input->post('kurir', TRUE);
- $berat = 0;
- foreach ($this->cart->contents() as $key) {
- $berat += ($key['weight'] * $key['qty']);
- }
- $curl = curl_init();
- curl_setopt_array($curl, array(
- CURLOPT_URL => "http://api.rajaongkir.com/starter/cost",
- CURLOPT_RETURNTRANSFER => true,
- CURLOPT_ENCODING => "",
- CURLOPT_MAXREDIRS => 10,
- CURLOPT_TIMEOUT => 30,
- CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
- CURLOPT_CUSTOMREQUEST => "POST",
- CURLOPT_POSTFIELDS => "origin=$asal&destination=$dest&weight=$berat&courier=$kurir",
- CURLOPT_HTTPHEADER => array(
- "content-type: application/x-www-form-urlencoded",
- "key: b03354ea01da154f19e1d300a9497a16"
- ),
- ));
- $response = curl_exec($curl);
- $err = curl_error($curl);
- curl_close($curl);
- if ($err) {
- echo "cURL Error #:" . $err;
- } else {
- $data = json_decode($response, TRUE);
- echo '<option value="" selected disabled>Layanan yang Tersedia</option>';
- for ($i=0; $i < count($data['rajaongkir']['results']); $i++) {
- for ($l=0; $l < count($data['rajaongkir']['results'][$i]['costs']); $l++) {
- echo
- '<option value="'.$data['rajaongkir']['results'][$i]['costs'][$l][0]['cost']['value'].','.$data['rajaongkir']['results'][$i]['costs'][$l]['service'].'('.$data['rajaongkir']['results'][$i]['costs'][$l]['description'].')">';
- echo $data['rajaongkir']['results'][$i]['costs'][$l]['service'].'('.$data['rajaongkir']['results'][$i]['costs'][$l]['description'].')</option>';
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement