public function addReplyComment()
 {
     $error_message = $success_message = "";
     $url = Url::to('products');
     $thread_id = Input::get('thread_id', 0);
     $product_code = Input::get('prd', 0);
     if ($product_code) {
         $rules = $messages = array();
         $rules = array('reply_message_' . $thread_id => 'required');
         $validator = Validator::make(Input::all(), $rules, $messages);
         if ($validator->passes()) {
             $reply_id = 0;
             $p_details = Product::whereRaw('product_code = ? AND product_status != ?', array($product_code, 'Deleted'))->first();
             if (count($p_details) > 0) {
                 $return_arr = $this->chkIsAllowConversation($p_details['id'], $p_details, $thread_id);
                 if ($return_arr['allow_to_reply']) {
                     $input_arr = Input::All();
                     $logged_user_id = getAuthUser() ? getAuthUser()->user_id : 0;
                     $date_now = date('Y-m-d H:i:s');
                     if ($thread_id > 0) {
                         $message_thread = MpProductComments::whereRaw('id = ? AND is_deleted = ?', array($thread_id, 0))->first();
                         if (count($message_thread) > 0) {
                             $visibility = $message_thread['visibility'] == 'Private' ? 'Private' : Input::get('visibility_' . $thread_id, 'Public');
                             $mesage_data = array('date_added' => $date_now, 'product_id' => $message_thread['product_id'], 'thread_id' => $thread_id, 'notes' => Input::get('reply_message_' . $thread_id), 'added_by_user_id' => $logged_user_id, 'visibility_status' => $visibility, 'is_deleted' => 0);
                             $message_comment_replies = new MpProductCommentReplies();
                             $reply_id = $message_comment_replies->insertGetId($mesage_data);
                             $reply_count = $message_thread['total_replies'];
                             //To update reply count and reply status
                             MpProductComments::where('id', $thread_id)->update(array("last_replied_user_id" => $logged_user_id, "last_updated" => $date_now, 'total_replies' => (int) $reply_count + 1));
                         }
                         $success_message = trans('webshoppack::viewProduct.reply_message_added_success');
                         $key = "NewReply";
                     } else {
                         $visibility = Input::get('visibility_' . $thread_id, 'Public');
                         $mesage_data = array('date_added' => $date_now, 'product_id' => $p_details['id'], 'user_id' => $logged_user_id, 'seller_id' => $p_details['product_user_id'], 'message' => Input::get('reply_message_' . $thread_id), 'last_updated' => $date_now, 'visibility' => $visibility, 'is_deleted' => 0);
                         $message_comments = new MpProductComments();
                         $thread_id = $message_comments->insertGetId($mesage_data);
                         $success_message = trans('webshoppack::viewProduct.comment_added_success');
                         $key = "NewComment";
                     }
                     // Send user notification mail details for admin and Thread owner / Purchased user
                     $this->ViewProductService->sendProductConversationMail($p_details, $thread_id, $key, $reply_id);
                 }
                 $url = $this->ViewProductService->getProductViewURL($p_details['id'], $p_details);
                 $url = $url . "/comments";
             } else {
                 $error_message = trans('webshoppack::viewProduct.invalid_url_slug');
             }
         } else {
             $error_message = trans('webshoppack::viewProduct.invalid_url_slug');
             $error_message = trans('webshoppack::viewProduct.invalid_url_slug');
         }
     }
     return Redirect::to($url)->with('success_message', $success_message)->with('error_message', $error_message);
 }