Skip to content

Commit

Permalink
Added settings option to hide price (#41)
Browse files Browse the repository at this point in the history
#### What problem is this solving?

Added setting option to hide price for b2b stores

#### How to test it?

Check PDP in following workspace


[Workspace](https://jorgeopengraph--renwil.myvtex.com/hopper-lpt1173/p?__bindingAddress=www.renwil.com/en)

#### Screenshots or example usage:

<img width="1076" alt="image"
src="https://github.com/vtex-apps/open-graph/assets/94565086/6620926f-cfb1-4da2-a214-b07d53f6c80a">

---------

Co-authored-by: Jorge Acosta <[email protected]>
  • Loading branch information
jorgeAcostaVTEX and Jorge Acosta authored Feb 9, 2024
1 parent 6874854 commit 9aed2ad
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 2 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

## [Unreleased]

### Added
- Settings option to hide price.

## [1.2.2] - 2022-10-14

### Added
Expand Down
16 changes: 15 additions & 1 deletion manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,21 @@
"postreleasy": "vtex publish --verbose"
},
"dependencies": {
"vtex.product-context": "0.x"
"vtex.product-context": "0.x",
"vtex.apps-graphql": "3.x"
},
"settingsSchema": {
"title": "Structured data",
"type": "object",
"access": "public",
"properties": {
"disableOffers": {
"title": "Disable Offers",
"type": "boolean",
"default": false,
"description": "Disable product offers"
}
}
},
"$schema": "https://raw.githubusercontent.com/vtex/node-vtex-api/master/gen/manifest.schema"
}
8 changes: 7 additions & 1 deletion react/ProductOpenGraph.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import {
} from 'vtex.render-runtime'
import { ProductContext, SKU } from 'vtex.product-context'

import useAppSettings from './hooks/useAppSettings'

// eslint-disable-next-line no-var
declare var global: {
__hostname__: string
Expand All @@ -21,7 +23,6 @@ interface MetaTag {
function ProductOpenGraph() {
const productContext = useContext(ProductContext) as ProductContext
const runtime = useRuntime() as RenderContext

const hasValue = productContext?.product

if (!hasValue) {
Expand Down Expand Up @@ -111,6 +112,7 @@ function productAvailability(selectedItem?: SKU): MetaTag {
}

function productPrice(selectedItem?: SKU): MetaTag | null {
const { disableOffers } = useAppSettings()
const seller = selectedItem?.sellers.find(
({ commertialOffer }) => commertialOffer.AvailableQuantity > 0
)
Expand All @@ -119,6 +121,10 @@ function productPrice(selectedItem?: SKU): MetaTag | null {
return null
}

if (disableOffers) {
return null
}

return {
property: 'product:price:amount',
content: `${seller.commertialOffer.spotPrice}`,
Expand Down
27 changes: 27 additions & 0 deletions react/hooks/useAppSettings.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { useQuery } from 'react-apollo'

import GET_SETTINGS from '../queries/getSettings.graphql'

const DEFAULT_DISABLE_OFFERS = false

interface Settings {
disableOffers: boolean
}

const useAppSettings = (): Settings => {
const { data } = useQuery(GET_SETTINGS, { ssr: false })

if (data?.publicSettingsForApp?.message) {
const { disableOffers } = JSON.parse(data.publicSettingsForApp.message)

return {
disableOffers: disableOffers || DEFAULT_DISABLE_OFFERS,
}
}

return {
disableOffers: DEFAULT_DISABLE_OFFERS,
}
}

export default useAppSettings
6 changes: 6 additions & 0 deletions react/queries/getSettings.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
query getSettings {
publicSettingsForApp(app: "vtex.open-graph", version: "1.x")
@context(provider: "vtex.apps-graphql") {
message
}
}

0 comments on commit 9aed2ad

Please sign in to comment.