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

MethodParametersDoes
add{ type, id, comment }Adds a comment. type is 'product', 'page' or 'blog'.
getCommentstype, 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

EventFires whenArguments
comment::added / comment::addition.failedaddresponse or error, item id
comment::fetched / comment::fetch.failedgetComments, fetchCommentsresponse or error, the request

Gotchas

  • Adding a comment needs a logged-in customer.
  • getProductComments and getPageComments from the old Twig docs no longer exist, although the SDK's types still list them. Use getComments('product', id) and getComments('page', id).
  • add and fetchComments also accept the plural type ('products', 'pages', 'blogs'). getComments takes the singular only, because it adds the s itself.

See also

On this page