Skip to content

Commit

Permalink
fix(checkout): use most recently selected shipping price
Browse files Browse the repository at this point in the history
  • Loading branch information
FlorianSDV committed Sep 20, 2024
1 parent 3d32f6a commit a0054a6
Showing 1 changed file with 11 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import {debounce, type DeliveryOptionsStoreState, type StoreCallbackUpdate} from '@myparcel-pdk/checkout';
import {
debounce,
useDeliveryOptionsStore,
type DeliveryOptionsStoreState,
type StoreCallbackUpdate,
} from '@myparcel-pdk/checkout';

Check warning on line 6 in views/js/frontend/checkout/src/deliveryOptions/listeners/updateCheckoutOnUpdate.ts

View check run for this annotation

Codecov / codecov/patch

views/js/frontend/checkout/src/deliveryOptions/listeners/updateCheckoutOnUpdate.ts#L2-L6

Added lines #L2 - L6 were not covered by tests
import {objectIsEqual} from '@myparcel/ts-utils';
import {getCurrentShippingMethod} from '../../utils';

const CHECKOUT_UPDATE_DELAY = 200;

/**
* Only do this once to avoid excessive animations.
*/
let done = false;

export const onDeliveryOptionsOutputChange: StoreCallbackUpdate<DeliveryOptionsStoreState> = debounce(
(newState, oldState) => {
if (objectIsEqual(newState.output, oldState?.output)) {
Expand All @@ -21,13 +21,12 @@ export const onDeliveryOptionsOutputChange: StoreCallbackUpdate<DeliveryOptionsS
return;
}

if (done) {
return;
}
const deliveryOptions = useDeliveryOptionsStore();

Check warning on line 24 in views/js/frontend/checkout/src/deliveryOptions/listeners/updateCheckoutOnUpdate.ts

View check run for this annotation

Codecov / codecov/patch

views/js/frontend/checkout/src/deliveryOptions/listeners/updateCheckoutOnUpdate.ts#L24

Added line #L24 was not covered by tests

// Trigger a change event on the shipping method input to let PrestaShop fetch the new price.
currentShippingMethod.input.trigger('change');
done = true;
// Update the hidden input.
if (deliveryOptions.state.hiddenInput) {
$(deliveryOptions.state.hiddenInput).trigger('change');
}

Check warning on line 29 in views/js/frontend/checkout/src/deliveryOptions/listeners/updateCheckoutOnUpdate.ts

View check run for this annotation

Codecov / codecov/patch

views/js/frontend/checkout/src/deliveryOptions/listeners/updateCheckoutOnUpdate.ts#L26-L29

Added lines #L26 - L29 were not covered by tests
},
CHECKOUT_UPDATE_DELAY,
);

0 comments on commit a0054a6

Please sign in to comment.