Skip to content

Commit

Permalink
feat: add option to show prices as surcharge
Browse files Browse the repository at this point in the history
  • Loading branch information
RichardPerdaan authored and EdieLemoine committed Mar 17, 2021
1 parent ebcc17a commit 0e17e7d
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/config/defaultConfiguration.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export const defaultConfiguration = (platform = DEFAULT_PLATFORM) => {
[CONFIG.KEY]: {
[CONFIG.PLATFORM]: DEFAULT_PLATFORM,
[CONFIG.CURRENCY]: 'EUR',
[CONFIG.SHOW_PRICE_SURCHARGE]: false,

[CONFIG.PACKAGE_TYPE]: DEFAULT_PACKAGE_TYPE,

Expand Down
1 change: 1 addition & 0 deletions src/data/keys/configKeys.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export const API_BASE_URL = 'apiBaseUrl';
export const LOCALE = 'locale';
export const PLATFORM = 'platform';
export const CURRENCY = 'currency';
export const SHOW_PRICE_SURCHARGE = 'showPriceSurcharge';

export const PACKAGE_TYPE = 'packageType';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import * as CONFIG from "@/data/keys/configKeys";
import * as STRINGS from '@/data/keys/stringsKeys';
import { formatCurrency } from '@/delivery-options/data/prices/formatCurrency';
import { getLowestPriceFromFormConfig } from '@/delivery-options/data/prices/getLowestPriceFromFormConfig';
Expand All @@ -17,6 +18,11 @@ export function getPriceLabelFromFormConfig(formSettings, carrier = null, config
const minimumPrice = getLowestPriceFromFormConfig(formSettings, carrier, configBus);
const formattedPrice = formatCurrency(minimumPrice, configBus);
const isDiscount = minimumPrice < 0;
const showPriceSurcharge = configBus.get(CONFIG.SHOW_PRICE_SURCHARGE);

if (showPriceSurcharge && minimumPrice === 0) {
return null;
}

if (isDiscount) {
return `${formattedPrice} ${configBus.strings[STRINGS.DISCOUNT].toLowerCase()}`;
Expand Down
5 changes: 5 additions & 0 deletions src/sandbox/settings/form.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ export const createSettings = memoize((platform) => {
key: CONFIG.KEY,
name: CONFIG.CURRENCY,
},
{
key: CONFIG.KEY,
name: CONFIG.SHOW_PRICE_SURCHARGE,
component: CToggle,
},
{
key: CONFIG.KEY,
name: CONFIG.DROP_OFF_DAYS,
Expand Down
8 changes: 5 additions & 3 deletions src/sandbox/translations/en.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,20 +42,20 @@ export const englishTranslations = {
[`field.${CONFIG.ALLOW_EVENING_DELIVERY}`]: 'Allow evening delivery',
[`field.${CONFIG.ALLOW_MONDAY_DELIVERY}.description`]: `Monday delivery is only possible if the package is delivered before <code>15:00</code> on Saturday at the post office. Note: To activate Monday delivery, Saturday must be present in "@:field.${CONFIG.DROP_OFF_DAYS}". On Saturday the cutoff time must be before <code>15:00</code> (<code>14:30</code> recommended) to allow Monday to be shown in the delivery options. <a href="https://blog.myparcel.nl/maandagbezorging/" target="_blank">More information about this free service</a>`,
[`field.${CONFIG.ALLOW_MONDAY_DELIVERY}`]: 'Allow Monday delivery',
[`field.${CONFIG.ALLOW_SATURDAY_DELIVERY}`]: 'Allow Saturday delivery',
[`field.${CONFIG.ALLOW_SATURDAY_DELIVERY}.description`]: `Saturday delivery is only possible when the package is delivered before <code>15:00</code> on Friday at the designated bpost locations. <strong>Note: To allow Saturday delivery, Friday must be enabled in <code>@:field.${CONFIG.DROP_OFF_DAYS}</code>.</strong>`,
[`field.${CONFIG.ALLOW_MORNING_DELIVERY}`]: 'Allow morning delivery',
[`field.${CONFIG.ALLOW_ONLY_RECIPIENT}`]: 'Allow only recipient',
[`field.${CONFIG.ALLOW_PICKUP_LOCATIONS}`]: 'Allow pickup locations',
[`field.${CONFIG.ALLOW_SATURDAY_DELIVERY}.description`]: `Saturday delivery is only possible when the package is delivered before <code>15:00</code> on Friday at the designated bpost locations. <strong>Note: To allow Saturday delivery, Friday must be enabled in <code>@:field.${CONFIG.DROP_OFF_DAYS}</code>.</strong>`,
[`field.${CONFIG.ALLOW_SATURDAY_DELIVERY}`]: 'Allow Saturday delivery',
[`field.${CONFIG.ALLOW_SIGNATURE}`]: 'Allow signature',
[`field.${CONFIG.CURRENCY}.description`]: 'The currency to display prices in. Default: <code>EUR</code>',
[`field.${CONFIG.CURRENCY}`]: 'Currency',
[`field.${CONFIG.CUTOFF_TIME}.description`]: 'The latest cutoff time before an order will still be picked, packed and dispatched on the same/first set dropoff day, taking the dropoff delay into account. (Industry standard) default time is <code>17:00</code>. For example, if cutoff time is <code>17:00</code>, Wednesday is a delivery day and there\'s no delivery delay; all orders placed Wednesday before <code>17:00</code> will be dropped of on that same Wednesday in time for the Wednesday collection and delivery on Thursday.',
[`field.${CONFIG.CUTOFF_TIME}`]: 'Cutoff time',
[`field.${CONFIG.DELIVERY_DAYS_WINDOW}.description`]: 'The number of days into the future for which you want to show delivery days. For example; If set to 3, a consumer ordering on Monday will see possible delivery options for Tuesday, Wednesday and Thursday (provided there is no drop-off delay and it\'s before the cutoff time). The minimum is <code>1</code> and maximum is <code>14</code> days.',
[`field.${CONFIG.DELIVERY_DAYS_WINDOW}`]: 'Delivery days window',
[`field.${CONFIG.DROP_OFF_DAYS}`]: 'Drop-off days',
[`field.${CONFIG.DROP_OFF_DAYS}.description`]: 'The days you normally hand in your parcels.',
[`field.${CONFIG.DROP_OFF_DAYS}`]: 'Drop-off days',
[`field.${CONFIG.DROP_OFF_DELAY}.description`]: 'The number of days it takes you to pick, pack and hand in your parcel at the post office (if ordered before the cutoff time). By default this is <code>0</code> and the maximum is <code>14</code>.',
[`field.${CONFIG.DROP_OFF_DELAY}`]: 'Drop-off delay',
[`field.${CONFIG.FEATURE_ALLOW_RETRY}.description`]: 'When the address is invalid, show a "retry" prompt where users can update their address.',
Expand Down Expand Up @@ -90,6 +90,8 @@ export const englishTranslations = {
[`field.${CONFIG.PRICE_STANDARD_DELIVERY}`]: 'Standard delivery price',
[`field.${CONFIG.SATURDAY_CUTOFF_TIME}.description`]: `Like the regular "@:field.${CONFIG.CUTOFF_TIME}" setting: This option allows you to indicate the latest cutoff time before an order will still be picked, packed and dispatched on the same/first set dropoff day, taking the dropoff delay into account.`,
[`field.${CONFIG.SATURDAY_CUTOFF_TIME}`]: 'Saturday cutoff time',
[`field.${CONFIG.SHOW_PRICE_SURCHARGE}.description`]: 'Enable to show price as surcharge rather than total price.',
[`field.${CONFIG.SHOW_PRICE_SURCHARGE}`]: 'Show price as surcharge',

[`field.${STRINGS.ADDRESS_NOT_FOUND}`]: 'Address not found',
[`field.${STRINGS.CITY}`]: 'City',
Expand Down
18 changes: 18 additions & 0 deletions tests/unit/delivery-options/prices.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,4 +107,22 @@ describe('price logic', () => {
const priceLabel = getPriceLabelFromFormConfig(formConfigDelivery, null, configBus);
expect(priceLabel).toEqual('Vanaf € 0,00');
});

it('handles show price surcharge setting properly', () => {
const configBus = mockConfigBus({
[CONFIG.KEY]: {
[CONFIG.PLATFORM]: PLATFORMS.SENDMYPARCEL,
[CONFIG.SHOW_PRICE_SURCHARGE]: true,
[CONFIG.CARRIER_SETTINGS]: {
[CARRIERS.BPOST]: {
[CONFIG.PRICE_MORNING_DELIVERY]: 5.10,
[CONFIG.PRICE_STANDARD_DELIVERY]: 0,
},
},
},
});

const priceLabel = getPriceLabelFromFormConfig(formConfigDelivery, null, configBus);
expect(priceLabel).toEqual(null);
});
});

0 comments on commit 0e17e7d

Please sign in to comment.