MyParcel Delivery Options
Introduction
This is the MyParcel delivery options module for use in any e-commerce platform's checkout. It's used to show your customers the possible delivery and/or pickup options for their location, based on your settings. It only has the bare minimum css styling so it should integrate with the design of your webshop easily.
Browser support
This app is written in Vue.js, it supports IE9 and up.
Example
An example of the delivery options functionality can be found in our sandbox. Here you can try out every combination of settings and copy the code for use in your project.
Installation
- Clone the repository or download the latest package from releases.
- Run the following commands:
$ npm i
$ npm run build
- Include
dist/myparcel.js
in your project. - Place
<div id="myparcel-delivery-options"></div>
in your HTML. - Follow the usage instructions.
- The delivery options will be rendered inside the div created in step 4.
Usage
All options
window.MyParcelConfig = {
config: {
platform: 'belgie',
carriers: ['bpost', 'dpd'],
priceMorningDelivery: 7.95,
priceStandardDelivery: 5.85,
priceEveningDelivery: 6.25,
priceSignature: 0.35,
priceOnlyRecipient: 0.30,
pricePickup: 5.85,
allowSaturdayDelivery: true,
allowPickupLocations: true,
allowSignature: true,
dropOffDays: '1;2;3;4;5;6',
cutoffTime: '15:00',
deliveryDaysWindow: 4,
dropOffDelay: 1,
carrierSettings: {
bpost: {
deliveryDaysWindow: 7,
},
dpd: {},
},
},
strings: {
wrongPostalCodeCity: 'Zaterdaglevering',
saturdayDeliveryTitle: 'Combinatie postcode/plaats onbekend',
city: 'Plaats',
postcode: 'Postcode',
houseNumber: 'Huisnummer',
addressNotFound: 'Adresgegevens niet ingevuld',
deliveryEveningTitle: 'Avondlevering',
deliveryMorningTitle: 'Ochtendlevering',
deliveryStandardTitle: 'Standaardlevering',
deliveryTitle: 'Bezorgen op',
pickupTitle: 'Afhalen op locatie',
onlyRecipientTitle: 'Home address only',
signatureTitle: 'Handtekening',
pickUpFrom: 'Afhalen vanaf',
openingHours: 'Openingstijden',
closed: 'Gesloten',
discount: 'korting',
free: 'Gratis',
from: 'Vanaf',
loadMore: 'Laad meer',
retry: 'Opnieuw',
},
address: {
cc: 'BE',
city: 'Antwerpen',
postalCode: '2000',
}
};
When there is no title set for deliveryMorningTitle
, deliveryStandardTitle
or deliveryEveningTitle
, the delivery time will automatically be visible. For more in-depth explanation of each config item and string and an interactive demo please see our sandbox
To get the object with the selected options from the delivery options do the following:
const data = document.querySelector('#mypa-input').value;
const obj = JSON.parse(data);
Examples
These examples assume you've already loaded the delivery options in your page. See Installation if you haven't.
You have to provide a configuration file in the following format as window.MyParcelConfig
and initialize the delivery options with an event.
Setting up the configuration
This is an example.
window.MyParcelConfig = {
config: {
platform: 'belgie',
carrierSettings: {
bpost: {
allowDeliveryOptions: true,
allowPickupLocations: true,
},
dpd: {
allowDeliveryOptions: true,
allowPickupLocations: true,
},
},
},
address: {
cc: 'BE',
city: 'Antwerpen',
postalCode: '2000',
},
};
document.dispatchEvent(new Event('myparcel_update_delivery_options'));
Getting the address from your environment
- Set up the link between the address fields and the delivery options:
function updateAddress() {
window.MyParcelConfig.address = {
cc: document.querySelector('#country').value,
postalCode: document.querySelector('#house_number').value,
number: document.querySelector('#postcode').value,
city: document.querySelector('#address_1').value,
};
document.dispatchEvent(new Event('myparcel_update_delivery_options'));
var event = document.createEvent('HTMLEvents');
event.initEvent('myparcel_update_delivery_options', true, false);
document.querySelector('body').dispatchEvent(event);
}
- Add event listeners to each address field to execute this function:
const addressFields = [
'<Country field selector>',
'<Postal code field selector>',
'<Address line 1 field selector>',
];
addressFields.forEach((field) => {
document.querySelector(field).addEventListener('change', updateAddress);
});
- Now, when an user changes the value in any of the fields set in
addressFields
the window.MyParcelConfig
will be updated and the delivery options module will receive the event that tells it to update. The delivery options will reload and fetch the available options for the new address.
Usage in forms
You'll often want to use the delivery options module in a checkout form in your webshop software. We have implemented it in WooCommerce and Magento2 using the following method to get its data in the $_POST
variable on submitting the form.
- Follow the steps in Installation and
Contribute
- Clone this repository
- Run
npm install
- Make your changes conforming to the existing code style, we recommend enabling ESLint and using our configuration to make this easier.
- Test the new code using
npm run serve
- Create a pull request!
Support
If you're experiencing trouble with the implementation we're ready to help you out! Please reach out to us via support@sendmyparcel.be or join our support community on Slack.