{"id":335077,"date":"2022-05-15T04:40:04","date_gmt":"2022-05-15T04:40:04","guid":{"rendered":"https:\/\/webkul.com\/blog\/?p=335077"},"modified":"2024-06-19T06:01:34","modified_gmt":"2024-06-19T06:01:34","slug":"how-to-save-a-custom-column-value-in-product-review-details","status":"publish","type":"post","link":"https:\/\/webkul.com\/blog\/how-to-save-a-custom-column-value-in-product-review-details\/","title":{"rendered":"How to save a custom column value in Product Review Details"},"content":{"rendered":"\n<p>Hello Friends!!!<br><br>In this blog, we will learn how we can save a custom column&#8217;s value in a product review details record table in the database. To achieve this functionality, we will follow the below steps:<\/p>\n\n\n\n<p><strong>1. We will create our <em>custom_column<\/em> in the <em>review_detail<\/em> record table in the <em>app\/code\/Vendor\/Module\/etc\/db_schema.xml<\/em> file.<\/strong><\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\">&lt;?xml version=&quot;1.0&quot;?&gt;\n&lt;schema xmlns:xsi=&quot;http:\/\/www.w3.org\/2001\/XMLSchema-instance&quot; xsi:noNamespaceSchemaLocation=&quot;urn:magento:framework:Setup\/Declaration\/Schema\/etc\/schema.xsd&quot;&gt;\n    &lt;!--Adding custom_column field in review_detail table--&gt;\n    &lt;table name=&quot;review_detail&quot; resource=&quot;default&quot; comment=&quot;Review Detail&quot;&gt;\n        &lt;column xsi:type=&quot;int&quot; name=&quot;custom_column&quot; \n            unsigned=&quot;true&quot; padding=&quot;2&quot; \n            nullable=&quot;false&quot; default=&quot;0&quot; \n            comment=&quot;Custom Column&quot;\/&gt;\n    &lt;\/table&gt;\n&lt;\/schema&gt;<\/pre>\n\n\n\n<p><strong>2. Now, we will create an <em>events.xml<\/em> file inside the <em>app\/code\/Vendor\/Module\/etc <\/em>directory. And we will add our custom observer class for the <em>review_save_after<\/em> event.<\/strong><\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\">&lt;?xml version=&quot;1.0&quot;?&gt;\n\n&lt;config xmlns:xsi=&quot;http:\/\/www.w3.org\/2001\/XMLSchema-instance&quot; xsi:noNamespaceSchemaLocation=&quot;urn:magento:framework:Event\/etc\/events.xsd&quot;&gt;\n    &lt;event name=&quot;review_save_after&quot;&gt;\n    &lt;observer name=&quot;wk_update_product_review_after_observer&quot;\n      instance=&quot;Vendor\\Module\\Observer\\SaveReviewAfter&quot;\/&gt;\n  &lt;\/event&gt;\n&lt;\/config&gt;<\/pre>\n\n\n\n<p><strong>3. Now, we will create a <em>SaveReviewAfter.php<\/em> file inside the <em>app\/code\/Vendor\/Module\/Observer<\/em> directory.<\/strong><\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\">&lt;?php\nnamespace Vendor\\Module\\Observer;\n\nuse Magento\\Framework\\Event\\ObserverInterface;\nuse Magento\\Framework\\Message\\ManagerInterface;\n\nclass SaveReviewAfter implements ObserverInterface\n{\n    \/**\n     * @var ManagerInterface\n     *\/\n    private $_messageManager;\n\n    \/**\n     * @param ManagerInterface $messageManager\n     * @param \\Magento\\Framework\\App\\RequestInterface $request\n     * @param \\Magento\\Framework\\App\\ResourceConnection $resource\n     *\/\n    public function __construct(\n        ManagerInterface $messageManager,\n        \\Magento\\Framework\\App\\RequestInterface $request,\n        \\Magento\\Framework\\App\\ResourceConnection $resource\n    ) {\n        $this-&gt;_request        = $request;\n        $this-&gt;_resource       = $resource;\n        $this-&gt;_messageManager = $messageManager;\n    }\n\n    \/**\n     * Execute Method to save user id in review_detail record table\n     * \n     * @param \\Magento\\Framework\\Event\\Observer $observer\n     * @return void\n     *\/\n    public function execute(\\Magento\\Framework\\Event\\Observer $observer)\n    {\n        try {\n                $review = $observer-&gt;getEvent()-&gt;getDataObject();\n                $connection = $this-&gt;_resource;\n                $value = 12;\n                $tableName = $connection-&gt;getTableName(&#039;review_detail&#039;);\n                $detail = &#091;\n                    &#039;custom_column&#039; =&gt; $value,\n                ];\n\n                $select = $connection-&gt;getConnection()-&gt;select()\n                    -&gt;from($tableName)\n                    -&gt;where(&#039;review_id = :review_id&#039;);\n                $detailId = $connection-&gt;getConnection()\n                    -&gt;fetchOne($select, &#091;&#039;:review_id&#039; =&gt; $review-&gt;getId()]);\n\n                if ($detailId) {\n                    $condition = &#091;&quot;detail_id = ?&quot; =&gt; $detailId];\n                    $connection-&gt;getConnection()-&gt;update($tableName, $detail, $condition);\n                } else {\n                    $detail&#091;&#039;store_id&#039;] = $review-&gt;getStoreId();\n                    $detail&#091;&#039;customer_id&#039;] = $review-&gt;getCustomerId();\n                    $detail&#091;&#039;review_id&#039;] = $review-&gt;getId();\n                    $connection-&gt;getConnection()-&gt;insert($tableName, $detail);\n                }\n            \n        } catch(Exception $e){\n            $this-&gt;_messageManager-&gt;addError($e-&gt;getMessage());\n        }\n    }\n}<\/pre>\n\n\n\n<p>Now, we will execute the setup upgrade command and flush the cache, then we will save the review and check the result.<br><br>Hope this will be helpful.<br>Thanks \ud83d\ude42<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hello Friends!!! In this blog, we will learn how we can save a custom column&#8217;s value in a product review details record table in the database. To achieve this functionality, we will follow the below steps: 1. We will create our custom_column in the review_detail record table in the app\/code\/Vendor\/Module\/etc\/db_schema.xml file. 2. Now, we will <a href=\"https:\/\/webkul.com\/blog\/how-to-save-a-custom-column-value-in-product-review-details\/\">[&#8230;]<\/a><\/p>\n","protected":false},"author":249,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[9121],"tags":[12743,12740,12741,12742],"class_list":["post-335077","post","type-post","status-publish","format-standard","hentry","category-magento-2","tag-custom-field-value-in-review-table","tag-how-to-save-a-custom-column-value-in-product-review-details","tag-save-custom-column-value-in-review-detail-table","tag-save-custom-field-value-in-review"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v24.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>How to save a custom column value in Product Review Details - Webkul Blog<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/webkul.com\/blog\/how-to-save-a-custom-column-value-in-product-review-details\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to save a custom column value in Product Review Details - Webkul Blog\" \/>\n<meta property=\"og:description\" content=\"Hello Friends!!! In this blog, we will learn how we can save a custom column&#8217;s value in a product review details record table in the database. To achieve this functionality, we will follow the below steps: 1. We will create our custom_column in the review_detail record table in the app\/code\/Vendor\/Module\/etc\/db_schema.xml file. 2. Now, we will [...]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/webkul.com\/blog\/how-to-save-a-custom-column-value-in-product-review-details\/\" \/>\n<meta property=\"og:site_name\" content=\"Webkul Blog\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/webkul\/\" \/>\n<meta property=\"article:published_time\" content=\"2022-05-15T04:40:04+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-06-19T06:01:34+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-og.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1200\" \/>\n\t<meta property=\"og:image:height\" content=\"630\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Khushboo Sahu\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@webkul\" \/>\n<meta name=\"twitter:site\" content=\"@webkul\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Khushboo Sahu\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/webkul.com\/blog\/how-to-save-a-custom-column-value-in-product-review-details\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/webkul.com\/blog\/how-to-save-a-custom-column-value-in-product-review-details\/\"},\"author\":{\"name\":\"Khushboo Sahu\",\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/person\/f94b8f53397bf85810761d76c98fadca\"},\"headline\":\"How to save a custom column value in Product Review Details\",\"datePublished\":\"2022-05-15T04:40:04+00:00\",\"dateModified\":\"2024-06-19T06:01:34+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/webkul.com\/blog\/how-to-save-a-custom-column-value-in-product-review-details\/\"},\"wordCount\":144,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/webkul.com\/blog\/#organization\"},\"keywords\":[\"custom field value in review table\",\"How to save a custom column value in Product Review Details\",\"save custom column value in review detail table\",\"save custom field value in review\"],\"articleSection\":[\"Magento 2\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/webkul.com\/blog\/how-to-save-a-custom-column-value-in-product-review-details\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/webkul.com\/blog\/how-to-save-a-custom-column-value-in-product-review-details\/\",\"url\":\"https:\/\/webkul.com\/blog\/how-to-save-a-custom-column-value-in-product-review-details\/\",\"name\":\"How to save a custom column value in Product Review Details - Webkul Blog\",\"isPartOf\":{\"@id\":\"https:\/\/webkul.com\/blog\/#website\"},\"datePublished\":\"2022-05-15T04:40:04+00:00\",\"dateModified\":\"2024-06-19T06:01:34+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/webkul.com\/blog\/how-to-save-a-custom-column-value-in-product-review-details\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/webkul.com\/blog\/how-to-save-a-custom-column-value-in-product-review-details\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/webkul.com\/blog\/how-to-save-a-custom-column-value-in-product-review-details\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/webkul.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to save a custom column value in Product Review Details\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/webkul.com\/blog\/#website\",\"url\":\"https:\/\/webkul.com\/blog\/\",\"name\":\"Webkul Blog\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\/\/webkul.com\/blog\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/webkul.com\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/webkul.com\/blog\/#organization\",\"name\":\"WebKul Software Private Limited\",\"url\":\"https:\/\/webkul.com\/blog\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-logo-accent-sq.png\",\"contentUrl\":\"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-logo-accent-sq.png\",\"width\":380,\"height\":380,\"caption\":\"WebKul Software Private Limited\"},\"image\":{\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/webkul\/\",\"https:\/\/x.com\/webkul\",\"https:\/\/www.instagram.com\/webkul\/\",\"https:\/\/www.linkedin.com\/company\/webkul\",\"https:\/\/www.youtube.com\/user\/webkul\/\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/person\/f94b8f53397bf85810761d76c98fadca\",\"name\":\"Khushboo Sahu\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/webkul.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/cabac965df656d114e6bf340df07518c990eda03bb09265dbd5c17f1097adaae?s=96&d=https%3A%2F%2Fcdnblog.webkul.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F10%2Feva.png&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/cabac965df656d114e6bf340df07518c990eda03bb09265dbd5c17f1097adaae?s=96&d=https%3A%2F%2Fcdnblog.webkul.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F10%2Feva.png&r=g\",\"caption\":\"Khushboo Sahu\"},\"url\":\"https:\/\/webkul.com\/blog\/author\/khushboo-sahu062\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How to save a custom column value in Product Review Details - Webkul Blog","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/webkul.com\/blog\/how-to-save-a-custom-column-value-in-product-review-details\/","og_locale":"en_US","og_type":"article","og_title":"How to save a custom column value in Product Review Details - Webkul Blog","og_description":"Hello Friends!!! In this blog, we will learn how we can save a custom column&#8217;s value in a product review details record table in the database. To achieve this functionality, we will follow the below steps: 1. We will create our custom_column in the review_detail record table in the app\/code\/Vendor\/Module\/etc\/db_schema.xml file. 2. Now, we will [...]","og_url":"https:\/\/webkul.com\/blog\/how-to-save-a-custom-column-value-in-product-review-details\/","og_site_name":"Webkul Blog","article_publisher":"https:\/\/www.facebook.com\/webkul\/","article_published_time":"2022-05-15T04:40:04+00:00","article_modified_time":"2024-06-19T06:01:34+00:00","og_image":[{"width":1200,"height":630,"url":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-og.png","type":"image\/png"}],"author":"Khushboo Sahu","twitter_card":"summary_large_image","twitter_creator":"@webkul","twitter_site":"@webkul","twitter_misc":{"Written by":"Khushboo Sahu","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/webkul.com\/blog\/how-to-save-a-custom-column-value-in-product-review-details\/#article","isPartOf":{"@id":"https:\/\/webkul.com\/blog\/how-to-save-a-custom-column-value-in-product-review-details\/"},"author":{"name":"Khushboo Sahu","@id":"https:\/\/webkul.com\/blog\/#\/schema\/person\/f94b8f53397bf85810761d76c98fadca"},"headline":"How to save a custom column value in Product Review Details","datePublished":"2022-05-15T04:40:04+00:00","dateModified":"2024-06-19T06:01:34+00:00","mainEntityOfPage":{"@id":"https:\/\/webkul.com\/blog\/how-to-save-a-custom-column-value-in-product-review-details\/"},"wordCount":144,"commentCount":0,"publisher":{"@id":"https:\/\/webkul.com\/blog\/#organization"},"keywords":["custom field value in review table","How to save a custom column value in Product Review Details","save custom column value in review detail table","save custom field value in review"],"articleSection":["Magento 2"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/webkul.com\/blog\/how-to-save-a-custom-column-value-in-product-review-details\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/webkul.com\/blog\/how-to-save-a-custom-column-value-in-product-review-details\/","url":"https:\/\/webkul.com\/blog\/how-to-save-a-custom-column-value-in-product-review-details\/","name":"How to save a custom column value in Product Review Details - Webkul Blog","isPartOf":{"@id":"https:\/\/webkul.com\/blog\/#website"},"datePublished":"2022-05-15T04:40:04+00:00","dateModified":"2024-06-19T06:01:34+00:00","breadcrumb":{"@id":"https:\/\/webkul.com\/blog\/how-to-save-a-custom-column-value-in-product-review-details\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/webkul.com\/blog\/how-to-save-a-custom-column-value-in-product-review-details\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/webkul.com\/blog\/how-to-save-a-custom-column-value-in-product-review-details\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/webkul.com\/blog\/"},{"@type":"ListItem","position":2,"name":"How to save a custom column value in Product Review Details"}]},{"@type":"WebSite","@id":"https:\/\/webkul.com\/blog\/#website","url":"https:\/\/webkul.com\/blog\/","name":"Webkul Blog","description":"","publisher":{"@id":"https:\/\/webkul.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/webkul.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/webkul.com\/blog\/#organization","name":"WebKul Software Private Limited","url":"https:\/\/webkul.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/webkul.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-logo-accent-sq.png","contentUrl":"https:\/\/cdnblog.webkul.com\/blog\/wp-content\/uploads\/2021\/08\/webkul-logo-accent-sq.png","width":380,"height":380,"caption":"WebKul Software Private Limited"},"image":{"@id":"https:\/\/webkul.com\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/webkul\/","https:\/\/x.com\/webkul","https:\/\/www.instagram.com\/webkul\/","https:\/\/www.linkedin.com\/company\/webkul","https:\/\/www.youtube.com\/user\/webkul\/"]},{"@type":"Person","@id":"https:\/\/webkul.com\/blog\/#\/schema\/person\/f94b8f53397bf85810761d76c98fadca","name":"Khushboo Sahu","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/webkul.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/cabac965df656d114e6bf340df07518c990eda03bb09265dbd5c17f1097adaae?s=96&d=https%3A%2F%2Fcdnblog.webkul.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F10%2Feva.png&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/cabac965df656d114e6bf340df07518c990eda03bb09265dbd5c17f1097adaae?s=96&d=https%3A%2F%2Fcdnblog.webkul.com%2Fblog%2Fwp-content%2Fuploads%2F2019%2F10%2Feva.png&r=g","caption":"Khushboo Sahu"},"url":"https:\/\/webkul.com\/blog\/author\/khushboo-sahu062\/"}]}},"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts\/335077","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/users\/249"}],"replies":[{"embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/comments?post=335077"}],"version-history":[{"count":2,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts\/335077\/revisions"}],"predecessor-version":[{"id":448637,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/posts\/335077\/revisions\/448637"}],"wp:attachment":[{"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/media?parent=335077"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/categories?post=335077"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/webkul.com\/blog\/wp-json\/wp\/v2\/tags?post=335077"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}