Jump to content

Carrier module using api call taking too much time to get results


Recommended Posts

Hi,

I am developing a carrier module and using API call to get carrier cost from Bigpost Shipping, i am getting results from bigpost using api call but the problem is request taking too much time to get results, my code's are

	public function carrierCost($id_address){
        
        $cart = Context::getContext()->cart;
        $products = $cart->getProducts(true);
        //print_r($products);
        foreach($products as $key => $product){
            
            $products_array[] = array(
            'ItemType' => 0,
            'Description' => $products[$key]['name'],
            'Quantity' => $products[$key]['cart_quantity'],
            'Height' => $products[$key]['height'],
            'Width' => $products[$key]['width'],
            'Length' => $products[$key]['depth'],
            'Weight' => 10,
            'Consolidatable' => true);               
        }
        
        $address = new Address($id_address);        
       
        $url = "https://www.bigpost.com.au/api/getquote";
        
        $ch = curl_init();
        
        $headers = array(
            'Content-Type: application/json',
            'AccessToken: xxxxxxxxxxxxxxxxxxxx'
        );

        $data = array (
                  'JobType' => 2,
                  'BuyerIsBusiness' => true,
                  'BuyerHasForklift' => true,
                  'ReturnAuthorityToLeaveOptions' => true,
                  'JobDate' => '2020-08-14',
                  'DepotId' => 0,
                  'PickupLocation' => 
                  array (
                    'Name' => 'xxxx',
                    'Address' => 'xxxx',
                    'AddressLineTwo' => 'string',
                    'LocalityId' => 0,
                    'Locality' => 
                    array (
                      'Id' => 0,
                      'Suburb' => 'xxxx',
                      'Postcode' => 'xxxx',
                      'State' => 'WA',
                    ),
                  ),
                  'BuyerLocation' => 
                  array (
                    'Name' => $address->firstname." ".$address->lstname,
                    'Address' => $address->address1,
                    'AddressLineTwo' => 'string',
                    'LocalityId' => 0,
                    'Locality' => 
                    array (
                      'Id' => 0,
                      'Suburb' => $address->city,
                      'Postcode' => $address->postcode,
                      'State' => 'WA',
                    ),
                  ),
                  'Items' => $products_array,
                );
        
        $data_string = json_encode($data);
        
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
        curl_setopt($ch, CURLOPT_POST, true);
        curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, True);
    
        $server_output = curl_exec($ch);
        
        $_error = curl_error($ch);
    
        curl_close($ch);
        
        if ($_error == '') {
            return json_decode($server_output, true);
        } else {
            return FALSE;
        }
    }

and i am using this function inside 

public function getOrderShippingCost($params, $shipping_cost)

but that taking too much time if i open cart page, increase qty in cart, change address etc.

what should i do, please help and thanks in advance.

Prestashop 1.6.1.13

Edited by ArsalanAnsari (see edit history)
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...