Jump to content

SOLVED: Get selected delivery address 1.5.6


ruan567

Recommended Posts

Hi I've got the following code in my module, I would like to know if anybody has any sample code on how to determine the currently selected delivery address? Thanks in advance.

 

public function getOrderShippingCostExternal($params)

{

if ($this->id_carrier == (int)(Configuration::get('MYCARRIER1_CARRIER_ID')) && Configuration::get('MYCARRIER1_OVERCOST') > 1)

{

      if ($this->context->customer->isLogged()) 

      {

      $customer = new CustomerCore($this->context->customer->id);

      $customer_address = $customer->getAddresses(1);

      $cart = new CartCore($this->context->cart->id);

     $product_list = $cart->getProducts();

      $cartweight = $cart->getTotalWeight($product_list);

$url = "http://my.api.com/api/delivery/pricing.php?postalcode=".urlencode($customer_address[0]['postcode'])."&weight=".$cartweight."&update=".date("U"); 

     $result = file_get_contents($url);

     return ((float)$result); 

     }

     else return(false);

}

//return (float)(Configuration::get('MYCARRIER1_OVERCOST'));

if ($this->id_carrier == (int)(Configuration::get('MYCARRIER2_CARRIER_ID')) && Configuration::get('MYCARRIER2_OVERCOST') > 1)

return (float)(Configuration::get('MYCARRIER2_OVERCOST'));

 

// If the carrier is not known, you can return false, the carrier won't appear in the order process

return false;

}

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

Ruan,

 

You can get it from the $cart object:

 

$cart->id_address_delivery

 

or, to get the full address:

 

    new Address((int)$cart->id_address_delivery)

 

 

Hope this helps,

pascal

 

 

N.B. I saw this piece of code in your function:

 

$cart = new CartCore($this->context->cart->id);

 

Don't use CartCore, just use $cart = new Cart($this->context->cart->id);

 

 

(Everywhere you see the class xxxCore, just use xxx. This will enable you to override the class easier later on if needed)

 

FYI

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...