Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

custom fields not hydrated (?) before publishing product.updated event #3275

Open
jezzzm opened this issue Dec 15, 2024 · 1 comment
Open
Assignees
Labels
P4: low Non-critical, workarounds exist type: bug 🐛 Something isn't working @vendure/core
Milestone

Comments

@jezzzm
Copy link
Contributor

jezzzm commented Dec 15, 2024

Is your feature request related to a problem? Please describe.
I realised I had a bug in my code - I was checking product custom fields before deciding to add that product to a job queue or not. what i missed was that the custom fields objects was just a whole bunch of nulls.

i'm not sure, but i believe the translatableSaver isn't hydrating (for want of a better word) the updatedProduct with its custom fields before publishing the update event.

const updatedProduct = await this.translatableSaver.update({
ctx,
input,
entityType: Product,
translationType: ProductTranslation,
beforeSave: async p => {
if (input.facetValueIds) {
const facetValuesInOtherChannels = product.facetValues.filter(fv =>
fv.channels.every(channel => !idsAreEqual(channel.id, ctx.channelId)),
);
p.facetValues = [
...facetValuesInOtherChannels,
...(await this.facetValueService.findByIds(ctx, input.facetValueIds)),
];
}
await this.assetService.updateFeaturedAsset(ctx, p, input);
await this.assetService.updateEntityAssets(ctx, p, input);
},
});
await this.customFieldRelationService.updateRelations(ctx, Product, input, updatedProduct);
await this.eventBus.publish(new ProductEvent(ctx, updatedProduct, 'updated', input));

Describe the solution you'd like
the translatableSaver to populate custom fields before returning the product entity.

Describe alternatives you've considered
i have worked around this by making another request to get the whole product by id (including custom fields), but it'd be great to not have to do that.

Additional context
image

@michaelbromley
Copy link
Member

Thanks for the report. I was at first thinking this was referring to relation-type custom fields, but I see most of your custom fields are primitive types. So it looks like a bug.

@michaelbromley michaelbromley moved this to 📅 Planned in Vendure OS Roadmap Dec 30, 2024
@michaelbromley michaelbromley added this to the v3.1.2 milestone Dec 30, 2024
@michaelbromley michaelbromley added type: bug 🐛 Something isn't working @vendure/core P4: low Non-critical, workarounds exist labels Dec 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P4: low Non-critical, workarounds exist type: bug 🐛 Something isn't working @vendure/core
Projects
Status: 📅 Planned
Development

No branches or pull requests

3 participants