Jump to content

Postal Code in Carrier Class


hellykun
 Share

Recommended Posts

Hello everyone I would like to call a function to get the customers postal code from his selected address into the get carrier function in the Carrier Class.php. Is it possible? Can somebody help a little?

 

Thanks a lot.

Share this post


Link to post
Share on other sites

You can get it from object address with object cart parameters (taken from global $cart or from $params)
If customer already set their delivery address, then we can catch it.

You can do something like this, depend on where you will use this function :

/* get postal code for the existing cart address delivery
 * @param $params An array of the existing objects
 * @param $obcart An existing object cart
 * If global cart object is exist, @param $params and $cart are not necessary
 * return postal code if delivery address already set in the cart, else return boolean false
 */
public function getPostCode($obcart = false, $params = false)
{
    global $cart;

    /* Make sure the existences of object cart */
    if(!$obcart OR !Validate::isLoadedObject($obcart))
        $mycart = !$params ? $cart : $params;
    if(!$params AND !Validate::isLoadedObject($mycart))
        return false;

    /* Get an existing id_address_delivery from object cart */
    $id_address_delivery = $mycart->id_address_delivery;
    
    /* Load object address according to existing id_address_delivery */
    $address = new Address($id_address_delivery);

    /* If object address passed validation, define postal code variable */    
    if(Validate::isLoadedObject($address))
        $postcode = $address->postcode;

    return $postcode;
}


Edited by gonebdg - webindoshop.com (see edit history)

Share this post


Link to post
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
 Share

×
×
  • Create New...

Important Information

Cookies ensure the smooth running of our services. Using these, you accept the use of cookies. Learn More