简体   繁体   中英

How to get shipping address prestashop

I created a carrier module with two kind of shipping method, i have a function to get order shipping cost, here i want to get an array of shipping address to validate the zip code,

Here the code of i try,

public function getOrderShippingCost($params, $shipping_cost, $package = array())
    {           
                    $postal_code = $package['destination']['postcode'];
                    $country = $package['destination']['country'];
                    $contents_cost = $package['contents_cost'];

                    }

running my store in debbug, show me this Undefined index: for destination and contents_cost.

How can get all the shipping addres values?

You can get shipping address with a method like this :

public function loadReceiverAddress($cart) // Cart or order object
 {

  $address = new Address($cart->id_address_delivery);
  $city = $address->city;
  $zip = $address->postcode;
  $country = $address->country;
  $state = State::getNameById($address->id_state);
  $street_no=$address->address1;

  return array($city,$zip,$country,$state,$street_no);
 }

You can call this method when you want to get shipping address by cart or order object, this is an example of use :

// Create a new Order Object with order id    
$order = new Order((int)Tools::getValue('id_order'));

// Get delivery address details 
list($firstname,$lastname,$company,$phone_mobile,$city,$zip,$country,$state,$street_no,$email)=$this->loadReceiverAddress($order,true);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM