Jump to content

Shipping cost by destination postcode


Recommended Posts

Hi,

 

We are configuring an online shop for a florist. As part of the shop we carry out deliveries using our own vehicles. What we need to achieve is a shipping cost based on the destination postcode which is derived from the delivery address.

 

We are using Spanish postcodes which are numerical.

 

As an example the shop is based in 04727 and shipping to various destinations would be something similar to these: -

04720-04723 = 12 €

04724-04725 = 8 €

04726 = 7 €

04727 = 5 €

04728 = 7 €

04729 = 8 €

04500-04531 = 15€

 

Any ideas?

 

Thanks in advance

Link to comment
Share on other sites

Hi

 

I'm a presta newbie so please don't build your hopes up just yet!

 

I wanted to point out that the issue of the numerical post codes is exactly the same as used here in France. My thinking is it must be a system already adopted by say 'Collisimo' the French postal service used for parcel delivery.

 

My store is not open yet and I haven't configured postage & shipping yet, otherwise I might have been more help.

 

The French forum does have plenty of stuff about collisimo and other delivery options, check them out and you may find something useful? I hope I do!

 

Good luck

Poly

Link to comment
Share on other sites

Hi Poly,

 

Many thanks for the reply - we will head over to the French forum as you suggest.

 

We have to say though that we are somewhat bemused that we have not had any positive replies.

 

Surely the issue of calculating delivery cost based on postcode is not a new concept?

 

We are wondering whether it would be easier if we based the delivery cost on the delivery town?

 

Any suggestions would be welcomed.

 

We are not necessarily looking for a free solution - if we could purchase a module for this then, depending on price of course, we would be happy.

 

Regards

Link to comment
Share on other sites

I hope you find what you want there! France works delivery by post code number. The problem for the postman/woman is the address of a town is all the same! For example my postcode is the same a the next village & the next town which is 8kms away. Must be a headache for the delivery address, but for the approximate cost to deliver to a region by post code it would work very well, because the small area has the same code! so easy to cost up.....

 

I'm a newbie so don't say too much about how things work here, but I have posted a few things here looking for help and usually its very good. Just a bit stop and start at times which can leave you with a problem for days......

 

Good luck

Poly

Link to comment
Share on other sites

Hi Poly,

 

Thanks again for your input.

 

By searching the French forums and getting a few ideas, we found several modules that seem to work. One was rather expensive (but had lots of additional bells and whistles that we don't need) at $ 249 but we have been using the demo site for Localized Shipping. The support guys over there have been great so far and we will probably order the product later today.

 

Best wishes

Link to comment
Share on other sites

We are currently evaluating (using the demo site front-end and back-end) with Presto Changeo.

 

This is the link to the module: -

 

http://www.presto-changeo.com/en/shipping-modules/83-localized-shipping.html

 

So far we have managed to setup delivery costs using numerical postcodes - here in Spain our postcodes are 5 numbers long and sometimes start with a zero which has caused a couple of issues. However, the support that we have received has been good so far.

 

Hope that helps.

Link to comment
Share on other sites

  • 2 weeks later...
  • 4 months later...

Hi,

 

If you are looking for a less expensive module, take a look at mine:

 

http://addons.prestashop.com/en/shipping-logistics-delivery-prestashop-modules/5711-zones-by-zip-codes.html

 

If you have a question, please, tell me!

 

Regards,

Emmanuel

Hi Emmanuel,

 

Will your module work with Australian 4 digit postcodes? There are no letters involved...

 

Steve

Link to comment
Share on other sites

  • 4 weeks later...

Hi Emmanuel,

 

and your module is visible from FrontEnd? I would like to show shipping to unregistered customers, like presto-changeo module.

That means you can insert your zip code in FrontEnd and module calculates directly shipping price.

 

Is this possible?

 

Thanks

Link to comment
Share on other sites

Hi,

 

I don't have a front demo sorry and the module is not yet compatible with the estimation module. I have the modification but I have to edit my module. If you want the module now send me a message after your order and I will send you a file to replace ;)

 

Regards,

Emmanuel

Link to comment
Share on other sites

  • 4 weeks later...

/***use this one***instead of the deeliciouscarrier.php
<?php

if (!defined('_PS_VERSION_'))
    exit;

class deeliciousCarrier extends CarrierModule {

    public function __construct() {
        $this->name = 'deeliciousCarrier';
        $this->tab = 'shipping_logistics';
        $this->version = '1.0';
        $this->author = 'Murtaza Hussain';
        $this->need_instance = 1;
        //$this->ps_versions_compliancy = array('min' => '1.5', 'max' => '1.5');
        //$this->dependencies = array('blockcart');

        parent::__construct();

        $this->displayName = $this->l('Deelicious Carrier');
        $this->description = $this->l('Driving Distance based delivery module, [email protected]');

        $this->confirmUninstall = $this->l('Are you sure you want to uninstall?');

        if (!Configuration::get('MYMODULE_NAME'))
            $this->warning = $this->l('No name provided');

        if (self::isInstalled($this->name)) {
            // Getting carrier list
            global $cookie;
            $carriers = Carrier::getCarriers($cookie->id_lang, true, false, false, NULL, ALL_CARRIERS);

            // Saving id carrier list
            $id_carrier_list = array();
            foreach ($carriers as $carrier)
                $id_carrier_list[] .= $carrier['id_carrier'];

            // Testing if Carrier Id exists
            $warning = array();
            if (!in_array((int) (Configuration::get('MYCARRIER1_CARRIER_ID')), $id_carrier_list))
                $warning[] .= $this->l('"Carrier 1"') . ' ';

            if (count($warning))
                $this->warning .= implode(' , ', $warning) . $this->l('must be configured to use this module correctly') . ' ';
        }
    }

    public function install() {
        if (Shop::isFeatureActive())
            Shop::setContext(Shop::CONTEXT_ALL);

        $carrierConfig = array(
            0 => array('name' => 'Delivery on Door',
                'id_tax_rules_group' => 0,
                'active' => true,
                'deleted' => 0,
                'shipping_handling' => false,
                'range_behavior' => 0,
                'delay' => array('en' => 'Description 1', Language::getIsoById(Configuration::get('PS_LANG_DEFAULT')) => 'Description 1'),
                'id_zone' => 1,
                'is_module' => true,
                'shipping_external' => true,
                'external_module_name' => 'deeliciousCarrier',
                'need_range' => true
            )
        );

        $id_carrier1 = $this->installExternalCarrier($carrierConfig[0]);

        Configuration::updateValue('MYCARRIER1_CARRIER_ID', (int) $id_carrier1);
        return parent::install() &&
                $this->registerHook('extraCarrier') &&
                Configuration::updateValue('MYMODULE_NAME', 'deeliciousCarrier');
    }

    public function uninstall() {
        // Uninstall
        if (!parent::uninstall() ||
                !Configuration::deleteByName('MYMODULE_NAME') ||
                !$this->registerHook('extraCarrier'))
            return false;

        // Delete External Carrier
        $Carrier1 = new Carrier((int) (Configuration::get('MYCARRIER1_CARRIER_ID')));

        // If external carrier is default set other one as default
        if (Configuration::get('PS_CARRIER_DEFAULT') == (int) ($Carrier1->id)) {
            global $cookie;
            $carriersD = Carrier::getCarriers($cookie->id_lang, true, false, false, NULL, PS_CARRIERS_AND_CARRIER_MODULES_NEED_RANGE);
            foreach ($carriersD as $carrierD)
                if ($carrierD['active'] AND !$carrierD['deleted'] AND ($carrierD['name'] != $this->_config['name']))
                    Configuration::updateValue('PS_CARRIER_DEFAULT', $carrierD['id_carrier']);
        }

        // Then delete Carrier
        $Carrier1->deleted = 1;
        if (!$Carrier1->update())
            return false;

        parent::uninstall();
        return true;
    }

    public static function installExternalCarrier($config) {
        $carrier = new Carrier();
        $carrier->name = $config['name'];
        $carrier->id_tax_rules_group = $config['id_tax_rules_group'];
        $carrier->id_zone = $config['id_zone'];
        $carrier->active = $config['active'];
        $carrier->deleted = $config['deleted'];
        $carrier->delay = $config['delay'];
        $carrier->shipping_handling = $config['shipping_handling'];
        $carrier->range_behavior = $config['range_behavior'];
        $carrier->is_module = $config['is_module'];
        $carrier->shipping_external = $config['shipping_external'];
        $carrier->external_module_name = $config['external_module_name'];
        $carrier->need_range = $config['need_range'];

        $languages = Language::getLanguages(true);
        foreach ($languages as $language) {
            if ($language['iso_code'] == 'fr')
                $carrier->delay[(int) $language['id_lang']] = $config['delay'][$language['iso_code']];
            if ($language['iso_code'] == 'en')
                $carrier->delay[(int) $language['id_lang']] = $config['delay'][$language['iso_code']];
            if ($language['iso_code'] == Language::getIsoById(Configuration::get('PS_LANG_DEFAULT')))
                $carrier->delay[(int) $language['id_lang']] = $config['delay'][$language['iso_code']];
        }

        if ($carrier->add()) {
            $groups = Group::getGroups(true);
            foreach ($groups as $group)
                Db::getInstance()->autoExecute(_DB_PREFIX_ . 'carrier_group', array('id_carrier' => (int) ($carrier->id), 'id_group' => (int) ($group['id_group'])), 'INSERT');

            $rangePrice = new RangePrice();
            $rangePrice->id_carrier = $carrier->id;
            $rangePrice->delimiter1 = '0';
            $rangePrice->delimiter2 = '10000';
            $rangePrice->add();

            $rangeWeight = new RangeWeight();
            $rangeWeight->id_carrier = $carrier->id;
            $rangeWeight->delimiter1 = '0';
            $rangeWeight->delimiter2 = '10000';
            $rangeWeight->add();

            $zones = Zone::getZones(true);
            foreach ($zones as $zone) {
                Db::getInstance()->autoExecute(_DB_PREFIX_ . 'carrier_zone', array('id_carrier' => (int) ($carrier->id), 'id_zone' => (int) ($zone['id_zone'])), 'INSERT');
                Db::getInstance()->autoExecuteWithNullValues(_DB_PREFIX_ . 'delivery', array('id_carrier' => (int) ($carrier->id), 'id_range_price' => (int) ($rangePrice->id), 'id_range_weight' => NULL, 'id_zone' => (int) ($zone['id_zone']), 'price' => '0'), 'INSERT');
                Db::getInstance()->autoExecuteWithNullValues(_DB_PREFIX_ . 'delivery', array('id_carrier' => (int) ($carrier->id), 'id_range_price' => NULL, 'id_range_weight' => (int) ($rangeWeight->id), 'id_zone' => (int) ($zone['id_zone']), 'price' => '0'), 'INSERT');
            }

            // Copy Logo
            if (!copy(dirname(__FILE__) . '/carrier.jpg', _PS_SHIP_IMG_DIR_ . '/' . (int) $carrier->id . '.jpg'))
                return false;

            // Return ID Carrier
            return (int) ($carrier->id);
        }

        return false;
    }

    public function hookupdateCarrier($params) {
        if ((int) ($params['id_carrier']) == (int) (Configuration::get('MYCARRIER1_CARRIER_ID')))
            Configuration::updateValue('MYCARRIER1_CARRIER_ID', (int) ($params['carrier']->id));
    }

    public function hookextraCarrier($params) {
        // print_r($params);
        $this->context->smarty->assign(
                array(
                    'my_module_name' => Configuration::get('MYMODULE_NAME'),
                    'my_module_link' => $this->context->link->getModuleLink('deeliciousCarrier', 'display'),
                    'id_address' => $params['address']->id
                )
        );
        return $this->display(__FILE__, 'mymoduleShipping.tpl');
    }

    function getOrderShippingCost($params, $shipping_cost) {
        if ($this->context->customer->isLogged()) {
            $customer = new CustomerCore($this->context->customer->id);
            $customer_address = $customer->getAddresses(1);

            return (float) $this->isAddressCalculated($customer_address[0]['address1']);
        } else {
            return false;
        }
    }

    function getOrderShippingCostExternal($params) {

        if ($this->context->customer->isLogged()) {
            $customer = new CustomerCore($this->context->customer->id);
            $customer_address = $customer->getAddresses(1);
            return (float) $this->isAddressCalculated($customer_address[0]['address1']);
        } else {
            return false;
        }
    }

    public function isAddressCalculated($userAddress) {

        $meters = 0;
        $inMiles = 0;
        $totalCost = 0;

        $firstMile = Configuration::get('F_M_COST');
        $forEveryAnotherMile = Configuration::get('E_O_M_COST');
        $origin_address = Configuration::get('ORIGIN_ADDRESS');

        $url = "http://maps.googleapis.com/maps/api/distancematrix/json?origins=" . urlencode($origin_address) . "&destinations=" . urlencode($userAddress) . "&sensor=false&mode=driving";
        $jsonArr = json_decode(file_get_contents($url));
        if ($jsonArr->status != "INVALID_REQUEST" && $jsonArr->rows[0]->elements[0]->status != "ZERO_RESULTS") {
            $meters = $jsonArr->rows[0]->elements[0]->distance->value;
            $inMiles = ($meters / 1000) * 0.62137;
        }

        if ($inMiles >= 0 && $inMiles <= 1) {
            $totalCost = $inMiles * $firstMile;
        } else {
            $totalCost = (($inMiles - 1) * $forEveryAnotherMile) + $firstMile;
        }
        return $totalCost;
    }

    /*     * ***************** Form Area ************************* */

    public function getContent() {
        $output = null;
        $error = array();

        if (Tools::isSubmit('submit' . $this->name)) {
            $f_m_cost = strval(Tools::getValue('f_m_cost'));
            $e_o_m_cost = strval(Tools::getValue('e_o_m_cost'));
            $origin_address = strval(Tools::getValue('origin_address'));

            if ($f_m_cost == "") {
                $error[] = "First Mile Cost cannot be empty";
            }
            if ($e_o_m_cost == "") {
                $error[] = "Every Other Mile Cost cannot be empty";
            }
            if ($origin_address == "") {
                $error[] = "Origin Address cannot be empty";
            }

            if (count($error) == 0) {
                Configuration::updateValue('F_M_COST', $f_m_cost);
                Configuration::updateValue('E_O_M_COST', $e_o_m_cost);
                Configuration::updateValue('ORIGIN_ADDRESS', $origin_address);

                $output .= $this->displayConfirmation($this->l('Settings updated'));
            } else {
                for ($i = 0; $i < count($error); $i++) {
                    $output .= $this->displayError($this->l($error[$i]));
                }
            }
        }
        return $output . $this->displayForm();
    }

    public function displayForm() {
        // Get default Language
        $default_lang = (int) Configuration::get('PS_LANG_DEFAULT');

        // Init Fields form array
        $fields_form[0]['form'] = array(
            'legend' => array(
                'title' => $this->l('General Settings'),
            ),
            'input' => array(
                array(
                    'type' => 'text',
                    'label' => $this->l('First Mile Cost'),
                    'name' => 'f_m_cost',
                    'size' => 40,
                    'required' => true
                ),
                array(
                    'type' => 'text',
                    'label' => $this->l('Every Other Mile Cost'),
                    'name' => 'e_o_m_cost',
                    'size' => 40,
                    'required' => true
                ),
                array(
                    'type' => 'text',
                    'label' => $this->l('Origin Address'),
                    'name' => 'origin_address',
                    'size' => 80,
                    'required' => true
                ),
            ),
            'submit' => array(
                'title' => $this->l('Save'),
                'class' => 'button'
            )
        );

        $helper = new HelperForm();

        // Module, token and currentIndex
        $helper->module = $this;
        $helper->name_controller = $this->name;
        $helper->token = Tools::getAdminTokenLite('AdminModules');
        $helper->currentIndex = AdminController::$currentIndex . '&configure=' . $this->name;

        // Language
        $helper->default_form_language = $default_lang;
        $helper->allow_employee_form_lang = $default_lang;

        // Title and toolbar
        $helper->title = $this->displayName;
        $helper->show_toolbar = true;
        $helper->toolbar_scroll = true;
        $helper->submit_action = 'submit' . $this->name;
        $helper->toolbar_btn = array(
            'save' =>
            array(
                'desc' => $this->l('Save'),
                'href' => AdminController::$currentIndex . '&configure=' . $this->name . '&save' . $this->name .
                '&token=' . Tools::getAdminTokenLite('AdminModules'),
            ),
            'back' => array(
                'href' => AdminController::$currentIndex . '&token=' . Tools::getAdminTokenLite('AdminModules'),
                'desc' => $this->l('Back to list')
            )
        );

        // Load current value
        $helper->fields_value['f_m_cost'] = Configuration::get('F_M_COST');
        $helper->fields_value['e_o_m_cost'] = Configuration::get('E_O_M_COST');
        $helper->fields_value['origin_address'] = Configuration::get('ORIGIN_ADDRESS');

        return $helper->generateForm($fields_form);
    }

}
?>
 

Link to comment
Share on other sites

Dear Emmanuel, please tell me this!!

 

QUESTION ON FORUM and LINK is: http://www.prestashop.com/forums/topic/305460-how-to-add-tracking-url-in-prestashop-1561/

 

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

 

Hi Admin/dear all, i want to setup the tracking URL for the carrier. How is that possible in back office. Please help!!

 

Thankyou in advance!

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Link to comment
Share on other sites

  • 6 months later...

Hi,

 

No problem, if I remember right, I already have a client using it in Australia :)

 

Regards,

Emmanuel

hi Emmauel,

 

I am interested in your module. but not 100% sure if it will work the way i am expecting. whats the refund policy?

 

Also wondering if you have any module that can do dynamically shipping cost (using api) based in the dimensions and weight of the cartons ?

 

cheers

rocky

Link to comment
Share on other sites

  • 11 months later...

Hey Guys,

 

Checkout this module:

 

Table Rate Shipping - PrestaShop Shipping by Zip Code

https://www.prestashop.com/forums/topic/459819-module-table-rate-shipping-prestashop-shipping-by-zip-code/

 

You can calculate shipping by zip/post code range and so many other features.

 

Thanks,

Amit

Edited by Kahanitcom (see edit history)
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...