Skip to content

Commit

Permalink
Merge pull request #55 from vtex-apps/bugfix/WISHLIST-6_Wishlist-fix-…
Browse files Browse the repository at this point in the history
…for-missing-spot-price

[WISHLIST-6] Adding Spotprice to the product context
  • Loading branch information
wender authored May 27, 2021
2 parents e87a056 + 69820e8 commit 098fd6e
Show file tree
Hide file tree
Showing 5 changed files with 18 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]

### Fixed
- Spotprice not showing up
- Error when the component loads before the content exists at the PDP
## [1.7.4] - 2021-05-14

### Fixed
Expand Down
4 changes: 3 additions & 1 deletion react/AddProductBtn.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable no-console */
/* eslint-disable @typescript-eslint/no-use-before-define */
import React, {
FC,
Expand Down Expand Up @@ -145,9 +146,10 @@ const AddBtn: FC = () => {
const { showToast } = useContext(ToastContext)
const { product } = useContext(ProductContext) as any
const sessionResponse: any = useSessionResponse()
const [productId] = String(product.productId).split('-')
const [handleCheck, { data, loading, called }] = useLazyQuery(checkItem)

const [productId] = String(product?.productId).split('-')

const toastMessage = (messsageKey: string) => {
let action: any
if (messsageKey === 'notLogged') {
Expand Down
1 change: 0 additions & 1 deletion react/WishlistAdmin.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable no-console */
/* eslint-disable no-await-in-loop */
/* eslint-disable no-loop-func */
import React, { FC, useState } from 'react'
Expand Down
1 change: 1 addition & 0 deletions react/queries/productById.gql
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ query productsByIdentifier($ids: [ID!]) {
Name
}
AvailableQuantity
spotPrice
Price
PriceWithoutDiscount
ListPrice
Expand Down
11 changes: 11 additions & 0 deletions react/utils/normalize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,17 @@ export function mapCatalogProductToProductSummary(
wishlistId,
}
const items = normalizedProduct.items || []

items.forEach((eachSku: any, skuIndex: number) => {
eachSku.sellers.forEach((eachSeller: any, sellerIndex: number) => {
const skuSpotPrice = eachSeller.commertialOffer.spotPrice
const skuPrice = eachSeller.commertialOffer.Price
if (skuSpotPrice && skuSpotPrice === skuPrice) {
delete items[skuIndex].sellers[sellerIndex].commertialOffer.spotPrice
}
})
})

const sku = items.find(findAvailableProduct) || items[0]
if (sku) {
const [seller = defaultSeller] = sku.sellers ?? []
Expand Down

0 comments on commit 098fd6e

Please sign in to comment.