comment
Add a comment to a product, page or blog article, and list the comments on one or more of them.
Use Salla.comment for comments the customer writes on a product, a page or a blog article. The salla-comments web component lists and adds comments for you: see salla-comments.
await Salla.comment.add({ type: 'product', id: 85214, comment: 'The price is good' });
const { data } = await Salla.comment.getComments('product', 85214, 1, 10);Methods
| Method | Parameters | Does |
|---|---|---|
add | { type, id, comment } | Adds a comment. type is 'product', 'page' or 'blog'. |
getComments | type, id, page?, perPage?, sort?, customerId? | Lists comments on one item, or on several when id is an array |
fetchComments | { type, ids, page?, per_page?, sort?, customerId? } | The same, with one object |
page starts at 1 and perPage is 5 by default. Pass customerId to also ask for that customer's private comments.
To add a comment from a form, see Forms: Salla.form.submit('comment.add', e.nativeEvent) reads type, id and comment from the fields.
Events
| Event | Fires when | Arguments |
|---|---|---|
comment::added / comment::addition.failed | add | response or error, item id |
comment::fetched / comment::fetch.failed | getComments, fetchComments | response or error, the request |
Gotchas
- Adding a comment needs a logged-in customer.
getProductCommentsandgetPageCommentsfrom the old Twig docs no longer exist, although the SDK's types still list them. UsegetComments('product', id)andgetComments('page', id).addandfetchCommentsalso accept the plural type ('products','pages','blogs').getCommentstakes the singular only, because it adds thesitself.