Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/js/constants/events-map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ export default {
updateProduct: 'updateProduct',
updatedProduct: 'updatedProduct',
updateFacets: 'updateFacets',
updatedDeliveryForm: 'updatedDeliveryForm',
};
3 changes: 3 additions & 0 deletions src/js/constants/selectors-map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ export const checkout = {
actionsButtons: '.js-back, .js-edit-addresses, .js-edit-shipping',
termsLink: '.js-terms a',
checkoutModal: '#checkout-modal',
carrierExtraContentWrapper: '.carrier__extra-content-wrapper',
carrierExtraContent: '.carrier__extra-content',
carrierExtraContentActive: '.carrier__extra-content-wrapper--active',
};

export const progressRing = {
Expand Down
42 changes: 42 additions & 0 deletions src/js/pages/checkout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,48 @@ const initCheckout = () => {
}
}
});

// Prestashop event triggers after selecting different carrier
prestashop.on(events.updatedDeliveryForm, (params: Theme.DeliveryOptionForm.DeliveryOptionItem): void => {
if (typeof params.deliveryOption === 'undefined' || Object.keys(params.deliveryOption).length === 0) {
return;
}

// Hide all extra content in delivery step
const extraContentElements = document.querySelectorAll(CheckoutMap.carrierExtraContentWrapper);
extraContentElements.forEach((content: HTMLElement) => {
content.style.maxHeight = '0';
});
const extraContentElementToShow = params.deliveryOption[0]
?.querySelector(CheckoutMap.carrierExtraContentWrapper) as HTMLElement;

// Show selected delivery method extra content
if (extraContentElementToShow != null) {
const content = extraContentElementToShow.querySelector(CheckoutMap.carrierExtraContent);

if (content != null) {
extraContentElementToShow.style.maxHeight = `${content.clientHeight}px`;
}
}
});

const setMaxHeightToActiveCarrierExtraContent = () => {
const activeExtraContent = document.querySelector(`${CheckoutMap.carrierExtraContentActive}`) as HTMLElement;
const content = activeExtraContent.querySelector(CheckoutMap.carrierExtraContent) as HTMLElement;

if (activeExtraContent != null && content != null) {
activeExtraContent.style.maxHeight = `${content.clientHeight}px`;
}
};

// Initiate active carrier extra content height
if (document.readyState === 'complete' || document.readyState === 'interactive') {
setTimeout(() => { setMaxHeightToActiveCarrierExtraContent(); }, 1);
} else {
document.addEventListener('DOMContentLoaded', () => {
setMaxHeightToActiveCarrierExtraContent();
});
}
};

export default initCheckout;
5 changes: 5 additions & 0 deletions src/scss/core/components/_checkout-steps.scss
Original file line number Diff line number Diff line change
Expand Up @@ -108,3 +108,8 @@ $component-name: checkout__steps;
color: var(--bs-gray-900);
}
}

.carrier__extra-content-wrapper {
overflow: hidden;
transition: max-height 0.5s ease-in-out;
}
6 changes: 4 additions & 2 deletions templates/checkout/_partials/steps/shipping.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,10 @@
</span>
</div>
</label>
<div class="carrier__extra-content js-carrier-extra-content"{if $delivery_option != $carrier_id} style="display:none;"{/if}>
{$carrier.extraContent nofilter}
<div class="carrier__extra-content-wrapper {if $delivery_option == $carrier_id} carrier__extra-content-wrapper--active {/if} js-carrier-extra-content" {if $delivery_option !== $carrier_id}style="max-height:0px"{/if}>
<div class="carrier__extra-content">
{$carrier.extraContent nofilter}
</div>
</div>
{if !$smarty.foreach.delivery_options.last}
<hr />
Expand Down
1 change: 1 addition & 0 deletions types/events.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ declare type EVENTS = {
updateProduct: string,
updatedProduct: string,
updateFacets: string,
updatedDeliveryForm: string,
}
3 changes: 3 additions & 0 deletions types/selectors.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ declare type checkout = {
actionsButtons: string,
termsLink: string,
checkoutModal: string,
carrierExtraContentWrapper: string,
carrierExtraContent: string,
carrierExtraContentActive: string,
};

declare type progressRing = {
Expand Down
23 changes: 23 additions & 0 deletions types/useDeliveryOption.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/**
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare namespace Theme {
namespace DeliveryOptionForm {
interface DeliveryOptionItem {
dataForm?: DataForm[],
deliveryOption?: Record<number, HTMLElement>,
resp?: Response,
}

interface Response {
preview?: string,
}

interface DataForm {
name?: string,
value?: string,
}
}
}