Jump to content

Edit History

ArsalanAnsari

ArsalanAnsari

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

ArsalanAnsari

ArsalanAnsari

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.

ArsalanAnsari

ArsalanAnsari

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 taking too much to get results from bigpost.

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

ArsalanAnsari

ArsalanAnsari

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 

Quote

public function getOrderShippingCost($params, $shipping_cost)

but that taking taking too much to get results from bigpost.

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

×
×
  • Create New...