Skip to content

Commit

Permalink
fix: Spot pricing sort for lowPrice/highPrice (#1350)
Browse files Browse the repository at this point in the history
* fix pricing for lowPrice

* exact types
  • Loading branch information
tlgimenes authored Jun 9, 2022
1 parent 1e8d1cf commit 6836c6f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
9 changes: 5 additions & 4 deletions packages/api/src/platforms/vtex/resolvers/aggregateOffer.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { inStock } from '../utils/productStock'
import { inStock, price } from '../utils/productStock'
import type { StoreProduct } from './product'
import type { PromiseType } from '../../../typings'
import type { Resolver } from '..'
Expand All @@ -10,13 +10,14 @@ export const StoreAggregateOffer: Record<string, Resolver<Root>> & {
} = {
highPrice: (offers) => {
const availableOffers = offers.filter(inStock)
const highOffer = availableOffers[availableOffers.length - 1]

return availableOffers[availableOffers.length - 1]?.Price ?? 0
return highOffer != null ? price(highOffer) : 0
},
lowPrice: (offers) => {
const availableOffers = offers.filter(inStock)
const [lowOffer] = offers.filter(inStock)

return availableOffers[0]?.Price ?? 0
return lowOffer ? price(lowOffer) : 0
},
offerCount: (offers) => offers.length,
priceCurrency: () => '',
Expand Down
2 changes: 1 addition & 1 deletion packages/api/src/platforms/vtex/utils/productStock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export const sellingPrice = (offer: CommertialOffer) => offer.Price ?? 0
export const availability = (available: boolean) =>
available ? 'https://schema.org/InStock' : 'https://schema.org/OutOfStock'

// Smallest Available Selling Price First
// Smallest Available Spot Price First
export const bestOfferFirst = (
a: Pick<CommertialOffer, 'AvailableQuantity' | 'spotPrice'>,
b: Pick<CommertialOffer, 'AvailableQuantity' | 'spotPrice'>
Expand Down

1 comment on commit 6836c6f

@vercel
Copy link

@vercel vercel bot commented on 6836c6f Jun 9, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.