Skip to content

Commit

Permalink
Merge branch 'main' into add/l10n
Browse files Browse the repository at this point in the history
  • Loading branch information
luarakerlen committed Oct 4, 2024
2 parents b5d7d4c + 131168b commit 4dcc0c2
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 10 deletions.
11 changes: 8 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,18 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]

### Added

- Catalan, Czech, Danish, Greek, Finnish, Hungarian, Indonesian, Norwegian, Polish, Russian, Slovak, Slovenian, Swedish and Ukrainian translations.

## [0.1.4] - 2024-10-01
### Added

### Fixed
- Catalan, Czech, Danish, Greek, Finnish, Hungarian, Indonesian, Norwegian, Polish, Russian, Slovak, Slovenian, Swedish and Ukrainian translations.

## [0.2.0] - 2024-10-02

### Added

- Adjust drawer width to mobile
- orderForm integration from PLP to cart

## [0.1.2] - 2024-09-12

Expand Down
6 changes: 2 additions & 4 deletions manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"vendor": "vtex",
"name": "shipping-option-components",
"version": "0.1.4",
"version": "0.2.0",
"title": "Shipping Option Zipcode component",
"description": "Shipping Option Zipcode component",
"builders": {
Expand All @@ -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"
}
13 changes: 13 additions & 0 deletions react/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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())
15 changes: 13 additions & 2 deletions react/hooks/useShippingOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion react/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "CHANGE_ME",
"version": "0.1.4",
"version": "0.2.0",
"scripts": {
"test": "vtex-test-tools test"
},
Expand Down
10 changes: 10 additions & 0 deletions react/utils/cookie.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

0 comments on commit 4dcc0c2

Please sign in to comment.