It inserts 1 review, with its additional field values, for the Product Reviews module.
Description#
This is a runtime function intended to be called client side to submit a product review. Because this is a runtime (public) function no API key is required.
It inserts 1 review, with its additional field values, for the Product Reviews module. It applies the same validation and prelogic rules as a review submitted with the TGRADD form action, so the Reviews: Form component in mmx-product-details can submit reviews without reloading the page.
This function is provided by the Product Reviews module, so it’s called through Function: Module with Module_Code: tgreviews, not as a top-level Function. See Example Request.
New in 26.03.00.
Note
Calling this function with "Function": "Runtime_Product_Review_Insert", or without Session_Type, returns HTTP 200 with an empty response body rather than a JSON error. An empty body means the request never reached the function.
Request Parameters#
| Parameter | Type | Required | Description |
|---|---|---|---|
Function |
String | Yes | Must be Module. |
Module_Code |
String | Yes | Must be tgreviews. |
Module_Function |
String | Yes | Must be Runtime_Product_Review_Insert. |
Session_Type |
String | Yes | Must be runtime. Any other value returns no output. |
TGR_Product_Code |
String | Yes | Code of the product being reviewed. Returns MOD-SYS-TGR-00176 when the product isn’t found. |
TGR_Rating |
Number | Yes | The review’s rating, 1 to 5. A value outside that range returns a field error on TGR_Rating. |
TGR_Order_ID |
Number | No | ID of the order the review is for, stored on the review. Defaults to 0. The value isn’t checked against the store’s orders. |
TGR_Notify |
Boolean | No | Whether the reviewer wants to be notified about replies. Defaults to false. |
TGR_Name |
String | When the fld_name setting is Required |
Reviewer name. Max 255 characters. |
TGR_Email |
String | When the fld_email setting is Required |
Reviewer email. Max 255 characters. When it isn’t empty, an invalid address returns a field error on TGR_Email. |
TGR_Location |
String | When the fld_loc setting is Required |
Reviewer location. Max 255 characters. |
TGR_Title |
String | When the fld_title setting is Required |
Review title. Max 255 characters. |
TGR_Summary |
String | When the fld_summry setting is Required |
Review text. No length limit. |
TGR_reCAPTCHA |
String | When the rc_enabled setting is on |
The reCAPTCHA response token. Returns MOD-SYS-TGR-00179 when Google rejects it. |
TGR_AdditionalFields |
Object | No | Additional field values, keyed by additional field code. Each value must be a string. An unknown code returns a field error on TGR_AdditionalFields:<code>. May be omitted entirely. |
The fld_* and rc_enabled settings are Product Reviews module settings. Each fld_* setting is Required, Optional or Hidden. Required makes its input required; Optional and Hidden both make it optional.
Note
Setting a field to Hidden removes it from the storefront review form, but this function still accepts and stores a value for it. Hidden isn’t an input filter.
Field errors#
| Condition | Error Code | error_field_message |
|---|---|---|
| A required input isn’t supplied | MER-JSN-00023 | Missing required parameter |
| A required input is supplied as an empty string | MER-JSN-00023 | Value may not be blank |
TGR_Rating is outside 1 to 5 |
MER-JSN-00018 | Please specify a number between 1 and 5 |
TGR_Email isn’t a valid address |
MER-JSN-00018 | Please specify a valid email address |
TGR_AdditionalFields has an unknown code |
MER-JSN-00018 | Additional field does not exist |
Approval#
A new review’s approved state comes from the module’s auto_apprv setting. With auto-approve off, the review is inserted unapproved and the function still returns success, so a successful response doesn’t mean the review is visible yet.
The module recalculates the product’s stored rating average as part of the insert.
Duplicate Reviews#
A reviewer can submit 1 review per product. Submitting a second review for a product with an email address that already has one returns MOD-SYS-TGR-00180. TGR_Order_ID isn’t part of this check — reusing an order ID doesn’t block a submission on its own.
Prelogic#
The function runs the same prelogic as a review form post, including tgr_prelogic.mvc. Stores use the prelogic to block submissions, allow more than 1 review per reviewer, or override the approval setting.
When the prelogic sets allow_submission to 0, the review isn’t inserted. The function returns MOD-SYS-TGR-00178 with the message in g.TGR_Error, or “Product review is currently unavailable” when g.TGR_Error is empty.
Response Parameters#
On success, the function returns success with no data.
Validation errors use the standard field error format. See Requests and Responses.
Example Request#
{
"Store_Code": "{{Store_Code}}",
"Function": "Module",
"Module_Code": "tgreviews",
"Module_Function": "Runtime_Product_Review_Insert",
"Session_Type": "runtime",
"TGR_Product_Code": "{{Product_Code}}",
"TGR_Rating": 5,
"TGR_Notify": false,
"TGR_Name": "Jane Smith",
"TGR_Email": "[email protected]",
"TGR_Location": "San Diego, CA",
"TGR_Title": "Fits well",
"TGR_Summary": "True to size and the fabric holds up after washing.",
"TGR_AdditionalFields": {
"{{Additional_Field_Code}}": "{{Value}}"
}
}
Example Response#
{
"success": 1
}
Error Responses#
| Error Code | Error Message | Error Description |
|---|---|---|
| MER-JSN-00018 | Invalid value for field (field) | An input failed validation. See Field errors. |
| MER-JSN-00023 | One or more parameters are invalid | A required input is missing or blank. See Field errors. |
| MOD-SYS-TGR-00176 | Product not found | No product matches TGR_Product_Code. |
| MOD-SYS-TGR-00177 | No valid product page configured | The store has no loadable PROD page for the prelogic to run against. |
| MOD-SYS-TGR-00178 | (prelogic message) | The prelogic blocked the submission. Returns g.TGR_Error, or “Product review is currently unavailable” when it’s empty. |
| MOD-SYS-TGR-00179 | Invalid reCAPTCHA | reCAPTCHA is enabled and Google rejected TGR_reCAPTCHA. |
| MOD-SYS-TGR-00180 | You have reviewed this product already. | A review for this product already exists for the submitted email address. |
| MOD-SYS-TGR-00181 | You have reviewed this product already. | A review for this product already exists for the logged-in customer. |
| MOD-SYS-TGR-00182 | Review has already been submitted. | A review has already been submitted for this order. |
| invalid_module | Invalid module | The Product Reviews module isn’t installed, or Module_Code isn’t tgreviews. |