diff --git a/CHANGELOG.md b/CHANGELOG.md index 0d9e5b2..51036c3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,11 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] -## [0.1.4] - 2024-10-01 - -### Fixed +### Added -- Adjust drawer width to mobile +- orderForm integration from PLP to cart ## [0.1.2] - 2024-09-12 diff --git a/manifest.json b/manifest.json index 7723eb3..6bcf794 100644 --- a/manifest.json +++ b/manifest.json @@ -18,9 +18,7 @@ "vtex.pixel-manager": "1.x", "vtex.device-detector": "0.x" }, - "registries": [ - "smartcheckout" - ], + "registries": ["smartcheckout"], "policies": [], "$schema": "https://raw.githubusercontent.com/vtex/node-vtex-api/master/gen/manifest.schema" } diff --git a/react/client.ts b/react/client.ts index 1a18fab..3a903ac 100644 --- a/react/client.ts +++ b/react/client.ts @@ -30,3 +30,16 @@ export const getPickups = ( fetch( `/api/checkout/pub/pickup-points?an=${account}&countryCode=${countryCode}&postalCode=${zipCode}` ).then((res) => res.json()) + +export const updateOrderForm = ( + country: string, + zipCode: string, + orderFormId: string +) => + fetch(`/api/checkout/pub/orderForm/${orderFormId}/attachments/shippingData`, { + method: 'POST', + body: `{"selectedAddresses": [{ "postalCode": ${zipCode}, "country": "${country}" }]}`, + headers: { + 'Content-Type': 'application/json', + }, + }).then((res) => res.json()) diff --git a/react/hooks/useShippingOptions.ts b/react/hooks/useShippingOptions.ts index 1af2797..a39c6e1 100644 --- a/react/hooks/useShippingOptions.ts +++ b/react/hooks/useShippingOptions.ts @@ -4,9 +4,14 @@ import { useRuntime, useSSR } from 'vtex.render-runtime' import { useIntl } from 'react-intl' import { usePixel } from 'vtex.pixel-manager' -import { getCountryCode, getZipCode } from '../utils/cookie' +import { getCountryCode, getOrderFormId, getZipCode } from '../utils/cookie' import messages from '../messages' -import { getAddress, getPickups, updateSession } from '../client' +import { + getAddress, + getPickups, + updateOrderForm, + updateSession, +} from '../client' declare let window: any @@ -104,6 +109,12 @@ const useShippingOptions = () => { setIsLoading(true) + const orderFormId = getOrderFormId() + + if (orderFormId) { + await updateOrderForm(countryCode, inputZipCode, orderFormId) + } + const { geoCoordinates: coordinates } = await getAddress( countryCode, inputZipCode, diff --git a/react/utils/cookie.ts b/react/utils/cookie.ts index 9640cb3..be1b139 100644 --- a/react/utils/cookie.ts +++ b/react/utils/cookie.ts @@ -50,3 +50,13 @@ export function getCountryCode() { return countryCode } + +export function getOrderFormId() { + const orderForm = localStorage.getItem('orderform') + + if (!orderForm) { + return + } + + return JSON.parse(orderForm || '{}').id +}