Skip to content

Commit

Permalink
add variant conditional statement to the shipping facets
Browse files Browse the repository at this point in the history
  • Loading branch information
hiagolcm committed Nov 13, 2024
1 parent 52ec59c commit a5da064
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 28 deletions.
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "search-result",
"vendor": "vtex",
"version": "3.135.0-beta.2",
"version": "3.135.0-beta.4",
"title": "VTEX Search Result",
"description": "A search result wrapper component",
"mustUpdateAt": "2019-04-25",
Expand Down
5 changes: 4 additions & 1 deletion react/SearchResultFlexible.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ const SearchResultFlexible = ({
deliveries,
} = facets

const { query: runtimeQuery, production } = useRuntime()

const filters = useMemo(
() =>
getFilters({
Expand All @@ -96,6 +98,7 @@ const SearchResultFlexible = ({
hiddenFacets,
deliveries,
showShippingFacet,
production,
}),
[
brands,
Expand All @@ -105,6 +108,7 @@ const SearchResultFlexible = ({
brandsQuantity,
deliveries,
showShippingFacet,
production,
]
)

Expand All @@ -118,7 +122,6 @@ const SearchResultFlexible = ({
categoriesTrees.length > 0

const showFacets = showCategories || (!hideFacets && !isEmpty(filters))
const { query: runtimeQuery } = useRuntime()
const [state, dispatch] = useSearchPageStateReducer({
mobileLayout: mobileLayout.mode1,
showContentLoader: searchQuery.loading,
Expand Down
26 changes: 1 addition & 25 deletions react/components/SearchQuery.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { canUseDOM } from 'exenv'
import { equals } from 'ramda'
import { useCallback, useEffect, useMemo, useRef, useState } from 'react'
import { useQuery } from 'react-apollo'
Expand All @@ -15,30 +14,7 @@ import {
buildSelectedFacetsAndFullText,
detachFiltersByType,
} from '../utils/compatibilityLayer'

function getCookie(cname) {
if (!canUseDOM) {
return undefined
}

const name = `${cname}=`
const decodedCookie = decodeURIComponent(document.cookie)
const ca = decodedCookie.split(';')

for (let i = 0; i < ca.length; i++) {
let c = ca[i]

while (c.charAt(0) === ' ') {
c = c.substring(1)
}

if (c.indexOf(name) === 0) {
return c.substring(name.length, c.length)
}
}

return undefined
}
import getCookie from '../utils/getCookie'

const DEFAULT_PAGE = 1

Expand Down
27 changes: 27 additions & 0 deletions react/utils/getCookie.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { canUseDOM } from 'exenv'

function getCookie(cname) {
if (!canUseDOM) {
return undefined
}

const name = `${cname}=`
const decodedCookie = decodeURIComponent(document.cookie)
const ca = decodedCookie.split(';')

for (let i = 0; i < ca.length; i++) {
let c = ca[i]

while (c.charAt(0) === ' ') {
c = c.substring(1)
}

if (c.indexOf(name) === 0) {
return c.substring(name.length, c.length)
}
}

return undefined
}

export default getCookie
10 changes: 9 additions & 1 deletion react/utils/getFilters.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { path, contains, isEmpty } from 'ramda'
import { useIntl } from 'react-intl'

import getCookie from './getCookie'

export const SHIPPING_TITLE = 'store/search.filter.title.shipping'
export const CATEGORIES_TITLE = 'store/search.filter.title.categories'
export const BRANDS_TITLE = 'store/search.filter.title.brands'
Expand All @@ -27,6 +29,7 @@ const getFilters = ({
brandsQuantity = 0,
hiddenFacets = {},
showShippingFacet = false,
production = true,
}) => {
// eslint-disable-next-line react-hooks/rules-of-hooks
const intl = useIntl()
Expand All @@ -50,7 +53,12 @@ const getFilters = ({
)
}

if (!showShippingFacet) {
const variant = getCookie('sp-variant')

if (
!showShippingFacet ||
(production && variant && variant.indexOf('delivery_promises') === -1)
) {
deliveriesFormatted = deliveriesFormatted.filter(
d => d.name !== SHIPPING_KEY
)
Expand Down

0 comments on commit a5da064

Please sign in to comment.