From c536c1b5e654ec6a7ccc4fb807ffa134a7471823 Mon Sep 17 00:00:00 2001 From: Wender Lima Date: Wed, 26 May 2021 16:54:43 -0300 Subject: [PATCH 1/2] [WISHLIST-6] Adding Spotprice to the product context --- CHANGELOG.md | 2 ++ react/WishlistAdmin.tsx | 1 - react/queries/productById.gql | 1 + react/utils/normalize.ts | 11 +++++++++++ 4 files changed, 14 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cf3ee5c..ecdceb9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ## [Unreleased] +### Fixed +- Spotprice not showing up ## [1.7.4] - 2021-05-14 ### Fixed diff --git a/react/WishlistAdmin.tsx b/react/WishlistAdmin.tsx index 13e541e..49db33a 100644 --- a/react/WishlistAdmin.tsx +++ b/react/WishlistAdmin.tsx @@ -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' diff --git a/react/queries/productById.gql b/react/queries/productById.gql index a2bba76..fc728fe 100644 --- a/react/queries/productById.gql +++ b/react/queries/productById.gql @@ -118,6 +118,7 @@ query productsByIdentifier($ids: [ID!]) { Name } AvailableQuantity + spotPrice Price PriceWithoutDiscount ListPrice diff --git a/react/utils/normalize.ts b/react/utils/normalize.ts index 3721fae..d04806a 100644 --- a/react/utils/normalize.ts +++ b/react/utils/normalize.ts @@ -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 ?? [] From 69820e8074d52d17a25c812e6e68aa7cfb8e29a4 Mon Sep 17 00:00:00 2001 From: Wender Lima Date: Thu, 27 May 2021 11:32:44 -0300 Subject: [PATCH 2/2] Fixed error when the component loads before the content exists at the PDP --- CHANGELOG.md | 1 + react/AddProductBtn.tsx | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ecdceb9..a418336 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ### Fixed - Spotprice not showing up +- Error when the component loads before the content exists at the PDP ## [1.7.4] - 2021-05-14 ### Fixed diff --git a/react/AddProductBtn.tsx b/react/AddProductBtn.tsx index 464879f..1d3a65f 100644 --- a/react/AddProductBtn.tsx +++ b/react/AddProductBtn.tsx @@ -1,3 +1,4 @@ +/* eslint-disable no-console */ /* eslint-disable @typescript-eslint/no-use-before-define */ import React, { FC, @@ -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') {