ruan567 Posted April 2, 2015 Share Posted April 2, 2015 (edited) 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 April 9, 2015 by ruan567 (see edit history) Link to comment Share on other sites More sharing options...
ruan567 Posted April 8, 2015 Author Share Posted April 8, 2015 Nobody? Link to comment Share on other sites More sharing options...
PascalVG Posted April 9, 2015 Share Posted April 9, 2015 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 More sharing options...
ruan567 Posted April 9, 2015 Author Share Posted April 9, 2015 (edited) Thanks so much Pascal, I used the full Address which returned the object $customer_address->postcode! OH BTW: The sample code I received had the CORE bit inside it - took it out now - thanks for the tip. Edited April 9, 2015 by ruan567 (see edit history) Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now