feat(medusa): invalidate price selection caching within update request (#3553)
* feat: invalidate price selection caching on update * feat: add `onVariantsPricesUpdate` to PriceSelectionStrategy * fix: update units * fix: import * Create .changeset/tame-pillows-heal.md * fix: address feedback * refactor: make `onVariantsPricesUpdate` optional --------- Co-authored-by: fPolic <frane@medusajs.com> Co-authored-by: Oliver Windall Juhl <59018053+olivermrbl@users.noreply.github.com>
This commit is contained in:
co-authored by
fPolic
Oliver Windall Juhl
parent
455c56c4b3
commit
1ce3cc5ae4
@@ -1,30 +0,0 @@
|
||||
import { ICacheService } from "@medusajs/types"
|
||||
import { EventBusService, ProductVariantService } from "../services"
|
||||
|
||||
type ProductVariantUpdatedEventData = {
|
||||
id: string
|
||||
product_id: string
|
||||
fields: string[]
|
||||
}
|
||||
|
||||
class PricingSubscriber {
|
||||
protected readonly eventBus_: EventBusService
|
||||
protected readonly cacheService_: ICacheService
|
||||
|
||||
constructor({ eventBusService, cacheService }) {
|
||||
this.eventBus_ = eventBusService
|
||||
this.cacheService_ = cacheService
|
||||
|
||||
this.eventBus_.subscribe(
|
||||
ProductVariantService.Events.UPDATED,
|
||||
async (data) => {
|
||||
const { id, fields } = data as ProductVariantUpdatedEventData
|
||||
if (fields.includes("prices")) {
|
||||
await this.cacheService_.invalidate(`ps:${id}:*`)
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
export default PricingSubscriber
|
||||
Reference in New Issue
Block a user